LCOV - code coverage report
Current view: directory - gfx/skia/src/core - SkPathEffect.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 75 3 4.0 %
Date: 2012-06-02 Functions: 17 2 11.8 %

       1                 : 
       2                 : /*
       3                 :  * Copyright 2006 The Android Open Source Project
       4                 :  *
       5                 :  * Use of this source code is governed by a BSD-style license that can be
       6                 :  * found in the LICENSE file.
       7                 :  */
       8                 : 
       9                 : 
      10                 : #include "SkPathEffect.h"
      11                 : #include "SkPath.h"
      12                 : #include "SkBuffer.h"
      13                 : 
      14                 : ///////////////////////////////////////////////////////////////////////////////
      15                 : 
      16               0 : SkPairPathEffect::SkPairPathEffect(SkPathEffect* pe0, SkPathEffect* pe1)
      17               0 :         : fPE0(pe0), fPE1(pe1) {
      18               0 :     SkASSERT(pe0);
      19               0 :     SkASSERT(pe1);
      20               0 :     fPE0->ref();
      21               0 :     fPE1->ref();
      22               0 : }
      23                 : 
      24               0 : SkPairPathEffect::~SkPairPathEffect() {
      25               0 :     SkSafeUnref(fPE0);
      26               0 :     SkSafeUnref(fPE1);
      27               0 : }
      28                 : 
      29                 : /*
      30                 :     Format: [oe0-factory][pe1-factory][pe0-size][pe0-data][pe1-data]
      31                 : */
      32               0 : void SkPairPathEffect::flatten(SkFlattenableWriteBuffer& buffer) {
      33               0 :     buffer.writeFlattenable(fPE0);
      34               0 :     buffer.writeFlattenable(fPE1);
      35               0 : }
      36                 : 
      37               0 : SkPairPathEffect::SkPairPathEffect(SkFlattenableReadBuffer& buffer) {
      38               0 :     fPE0 = (SkPathEffect*)buffer.readFlattenable();
      39               0 :     fPE1 = (SkPathEffect*)buffer.readFlattenable();
      40                 :     // either of these may fail, so we have to check for nulls later on
      41               0 : }
      42                 : 
      43                 : ///////////////////////////////////////////////////////////////////////////////
      44                 : 
      45               0 : bool SkComposePathEffect::filterPath(SkPath* dst, const SkPath& src,
      46                 :                                      SkScalar* width) {
      47                 :     // we may have failed to unflatten these, so we have to check
      48               0 :     if (!fPE0 || !fPE1) {
      49               0 :         return false;
      50                 :     }
      51                 : 
      52               0 :     SkPath          tmp;
      53               0 :     const SkPath*   ptr = &src;
      54                 : 
      55               0 :     if (fPE1->filterPath(&tmp, src, width)) {
      56               0 :         ptr = &tmp;
      57                 :     }
      58               0 :     return fPE0->filterPath(dst, *ptr, width);
      59                 : }
      60                 : 
      61                 : ///////////////////////////////////////////////////////////////////////////////
      62                 : 
      63               0 : bool SkSumPathEffect::filterPath(SkPath* dst, const SkPath& src,
      64                 :                                  SkScalar* width) {
      65                 :     // use bit-or so that we always call both, even if the first one succeeds
      66               0 :     return  fPE0->filterPath(dst, src, width) | fPE1->filterPath(dst, src, width);
      67                 : }
      68                 : 
      69                 : ///////////////////////////////////////////////////////////////////////////////
      70                 : 
      71                 : #include "SkStroke.h"
      72                 : 
      73               0 : SkStrokePathEffect::SkStrokePathEffect(const SkPaint& paint)
      74               0 :     : fWidth(paint.getStrokeWidth()), fMiter(paint.getStrokeMiter()),
      75               0 :       fStyle(SkToU8(paint.getStyle())), fJoin(SkToU8(paint.getStrokeJoin())),
      76               0 :       fCap(SkToU8(paint.getStrokeCap())) {
      77               0 : }
      78                 : 
      79               0 : SkStrokePathEffect::SkStrokePathEffect(SkScalar width, SkPaint::Style style,
      80                 :                            SkPaint::Join join, SkPaint::Cap cap, SkScalar miter)
      81               0 :         : fWidth(width), fMiter(miter), fStyle(SkToU8(style)),
      82               0 :           fJoin(SkToU8(join)), fCap(SkToU8(cap)) {
      83               0 :     if (miter < 0) {  // signal they want the default
      84               0 :         fMiter = SK_DefaultMiterLimit;
      85                 :     }
      86               0 : }
      87                 : 
      88               0 : bool SkStrokePathEffect::filterPath(SkPath* dst, const SkPath& src,
      89                 :                                     SkScalar* width) {
      90               0 :     if (fWidth < 0 || fStyle == SkPaint::kFill_Style) {
      91               0 :         return false;
      92                 :     }
      93                 : 
      94               0 :     if (fStyle == SkPaint::kStroke_Style && fWidth == 0) {  // hairline
      95               0 :         *width = 0;
      96               0 :         return true;
      97                 :     }
      98                 : 
      99               0 :     SkStroke    stroke;
     100                 : 
     101               0 :     stroke.setWidth(fWidth);
     102               0 :     stroke.setMiterLimit(fMiter);
     103               0 :     stroke.setJoin((SkPaint::Join)fJoin);
     104               0 :     stroke.setCap((SkPaint::Cap)fCap);
     105               0 :     stroke.setDoFill(fStyle == SkPaint::kStrokeAndFill_Style);
     106                 : 
     107               0 :     stroke.strokePath(src, dst);
     108               0 :     return true;
     109                 : }
     110                 : 
     111               0 : SkFlattenable::Factory SkStrokePathEffect::getFactory() {
     112               0 :     return CreateProc;
     113                 : }
     114                 : 
     115               0 : SkFlattenable* SkStrokePathEffect::CreateProc(SkFlattenableReadBuffer& buffer) {
     116               0 :     return SkNEW_ARGS(SkStrokePathEffect, (buffer));
     117                 : }
     118                 : 
     119               0 : void SkStrokePathEffect::flatten(SkFlattenableWriteBuffer& buffer) {
     120               0 :     buffer.writeScalar(fWidth);
     121               0 :     buffer.writeScalar(fMiter);
     122               0 :     buffer.write8(fStyle);
     123               0 :     buffer.write8(fJoin);
     124               0 :     buffer.write8(fCap);
     125               0 : }
     126                 : 
     127               0 : SkStrokePathEffect::SkStrokePathEffect(SkFlattenableReadBuffer& buffer) {
     128               0 :     fWidth = buffer.readScalar();
     129               0 :     fMiter = buffer.readScalar();
     130               0 :     fStyle = buffer.readU8();
     131               0 :     fJoin = buffer.readU8();
     132               0 :     fCap = buffer.readU8();
     133               0 : }
     134                 : 
     135                 : ///////////////////////////////////////////////////////////////////////////////
     136                 : 
     137                 : SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkPathEffect)
     138            1464 :     SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkComposePathEffect)
     139            1464 :     SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkStrokePathEffect)
     140            4392 :     SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSumPathEffect)
     141                 : SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
     142                 : 

Generated by: LCOV version 1.7