gfx/skia/trunk/src/core/SkStrokeRec.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /*
     2  * Copyright 2012 Google Inc.
     3  *
     4  * Use of this source code is governed by a BSD-style license that can be
     5  * found in the LICENSE file.
     6  */
     8 #include "SkStrokeRec.h"
     9 #include "SkPaintDefaults.h"
    11 // must be < 0, since ==0 means hairline, and >0 means normal stroke
    12 #define kStrokeRec_FillStyleWidth     (-SK_Scalar1)
    14 SkStrokeRec::SkStrokeRec(InitStyle s) {
    15     fWidth          = (kFill_InitStyle == s) ? kStrokeRec_FillStyleWidth : 0;
    16     fMiterLimit     = SkPaintDefaults_MiterLimit;
    17     fCap            = SkPaint::kDefault_Cap;
    18     fJoin           = SkPaint::kDefault_Join;
    19     fStrokeAndFill  = false;
    20 }
    22 SkStrokeRec::SkStrokeRec(const SkStrokeRec& src) {
    23     memcpy(this, &src, sizeof(src));
    24 }
    26 SkStrokeRec::SkStrokeRec(const SkPaint& paint) {
    27     switch (paint.getStyle()) {
    28         case SkPaint::kFill_Style:
    29             fWidth = kStrokeRec_FillStyleWidth;
    30             fStrokeAndFill = false;
    31             break;
    32         case SkPaint::kStroke_Style:
    33             fWidth = paint.getStrokeWidth();
    34             fStrokeAndFill = false;
    35             break;
    36         case SkPaint::kStrokeAndFill_Style:
    37             if (0 == paint.getStrokeWidth()) {
    38                 // hairline+fill == fill
    39                 fWidth = kStrokeRec_FillStyleWidth;
    40                 fStrokeAndFill = false;
    41             } else {
    42                 fWidth = paint.getStrokeWidth();
    43                 fStrokeAndFill = true;
    44             }
    45             break;
    46         default:
    47             SkDEBUGFAIL("unknown paint style");
    48             // fall back on just fill
    49             fWidth = kStrokeRec_FillStyleWidth;
    50             fStrokeAndFill = false;
    51             break;
    52     }
    54     // copy these from the paint, regardless of our "style"
    55     fMiterLimit = paint.getStrokeMiter();
    56     fCap        = paint.getStrokeCap();
    57     fJoin       = paint.getStrokeJoin();
    58 }
    60 SkStrokeRec::Style SkStrokeRec::getStyle() const {
    61     if (fWidth < 0) {
    62         return kFill_Style;
    63     } else if (0 == fWidth) {
    64         return kHairline_Style;
    65     } else {
    66         return fStrokeAndFill ? kStrokeAndFill_Style : kStroke_Style;
    67     }
    68 }
    70 void SkStrokeRec::setFillStyle() {
    71     fWidth = kStrokeRec_FillStyleWidth;
    72     fStrokeAndFill = false;
    73 }
    75 void SkStrokeRec::setHairlineStyle() {
    76     fWidth = 0;
    77     fStrokeAndFill = false;
    78 }
    80 void SkStrokeRec::setStrokeStyle(SkScalar width, bool strokeAndFill) {
    81     if (strokeAndFill && (0 == width)) {
    82         // hairline+fill == fill
    83         this->setFillStyle();
    84     } else {
    85         fWidth = width;
    86         fStrokeAndFill = strokeAndFill;
    87     }
    88 }
    90 #include "SkStroke.h"
    92 bool SkStrokeRec::applyToPath(SkPath* dst, const SkPath& src) const {
    93     if (fWidth <= 0) {  // hairline or fill
    94         return false;
    95     }
    97     SkStroke stroker;
    98     stroker.setCap(fCap);
    99     stroker.setJoin(fJoin);
   100     stroker.setMiterLimit(fMiterLimit);
   101     stroker.setWidth(fWidth);
   102     stroker.setDoFill(fStrokeAndFill);
   103     stroker.strokePath(src, dst);
   104     return true;
   105 }

mercurial