gfx/skia/trunk/src/gpu/GrTextContext.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 2010 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 "GrTextContext.h"
     9 #include "GrContext.h"
    11 #include "SkAutoKern.h"
    12 #include "SkGlyphCache.h"
    13 #include "SkGr.h"
    15 GrTextContext::GrTextContext(GrContext* context, const SkDeviceProperties& properties) :
    16                             fContext(context), fDeviceProperties(properties), fDrawTarget(NULL) {
    17 }
    19 void GrTextContext::init(const GrPaint& grPaint, const SkPaint& skPaint) {
    20     const GrClipData* clipData = fContext->getClip();
    22     SkRect devConservativeBound;
    23     clipData->fClipStack->getConservativeBounds(
    24                                      -clipData->fOrigin.fX,
    25                                      -clipData->fOrigin.fY,
    26                                      fContext->getRenderTarget()->width(),
    27                                      fContext->getRenderTarget()->height(),
    28                                      &devConservativeBound);
    30     devConservativeBound.roundOut(&fClipRect);
    32     fDrawTarget = fContext->getTextTarget();
    34     fPaint = grPaint;
    35     fSkPaint = skPaint;
    36 }
    38 //*** change to output positions?
    39 void GrTextContext::MeasureText(SkGlyphCache* cache, SkDrawCacheProc glyphCacheProc,
    40                                 const char text[], size_t byteLength, SkVector* stopVector) {
    41     SkFixed     x = 0, y = 0;
    42     const char* stop = text + byteLength;
    44     SkAutoKern  autokern;
    46     while (text < stop) {
    47         // don't need x, y here, since all subpixel variants will have the
    48         // same advance
    49         const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0);
    51         x += autokern.adjust(glyph) + glyph.fAdvanceX;
    52         y += glyph.fAdvanceY;
    53     }
    54     stopVector->set(SkFixedToScalar(x), SkFixedToScalar(y));
    56     SkASSERT(text == stop);
    57 }
    59 static void GlyphCacheAuxProc(void* data) {
    60     GrFontScaler* scaler = (GrFontScaler*)data;
    61     SkSafeUnref(scaler);
    62 }
    64 GrFontScaler* GrTextContext::GetGrFontScaler(SkGlyphCache* cache) {
    65     void* auxData;
    66     GrFontScaler* scaler = NULL;
    68     if (cache->getAuxProcData(GlyphCacheAuxProc, &auxData)) {
    69         scaler = (GrFontScaler*)auxData;
    70     }
    71     if (NULL == scaler) {
    72         scaler = SkNEW_ARGS(SkGrFontScaler, (cache));
    73         cache->setAuxProc(GlyphCacheAuxProc, scaler);
    74     }
    76     return scaler;
    77 }

mercurial