Sat, 03 Jan 2015 20:18:00 +0100
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.
michael@0 | 1 | |
michael@0 | 2 | /* |
michael@0 | 3 | * Copyright 2010 Google Inc. |
michael@0 | 4 | * |
michael@0 | 5 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 6 | * found in the LICENSE file. |
michael@0 | 7 | */ |
michael@0 | 8 | |
michael@0 | 9 | |
michael@0 | 10 | #include "GrTemplates.h" |
michael@0 | 11 | #include "SkGr.h" |
michael@0 | 12 | #include "SkDescriptor.h" |
michael@0 | 13 | #include "SkGlyphCache.h" |
michael@0 | 14 | |
michael@0 | 15 | class SkGrDescKey : public GrKey { |
michael@0 | 16 | public: |
michael@0 | 17 | explicit SkGrDescKey(const SkDescriptor& desc); |
michael@0 | 18 | virtual ~SkGrDescKey(); |
michael@0 | 19 | |
michael@0 | 20 | protected: |
michael@0 | 21 | // overrides |
michael@0 | 22 | virtual bool lt(const GrKey& rh) const; |
michael@0 | 23 | virtual bool eq(const GrKey& rh) const; |
michael@0 | 24 | |
michael@0 | 25 | private: |
michael@0 | 26 | SkDescriptor* fDesc; |
michael@0 | 27 | enum { |
michael@0 | 28 | kMaxStorageInts = 16 |
michael@0 | 29 | }; |
michael@0 | 30 | uint32_t fStorage[kMaxStorageInts]; |
michael@0 | 31 | }; |
michael@0 | 32 | |
michael@0 | 33 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 34 | |
michael@0 | 35 | SkGrDescKey::SkGrDescKey(const SkDescriptor& desc) : GrKey(desc.getChecksum()) { |
michael@0 | 36 | size_t size = desc.getLength(); |
michael@0 | 37 | if (size <= sizeof(fStorage)) { |
michael@0 | 38 | fDesc = GrTCast<SkDescriptor*>(fStorage); |
michael@0 | 39 | } else { |
michael@0 | 40 | fDesc = SkDescriptor::Alloc(size); |
michael@0 | 41 | } |
michael@0 | 42 | memcpy(fDesc, &desc, size); |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | SkGrDescKey::~SkGrDescKey() { |
michael@0 | 46 | if (fDesc != GrTCast<SkDescriptor*>(fStorage)) { |
michael@0 | 47 | SkDescriptor::Free(fDesc); |
michael@0 | 48 | } |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | bool SkGrDescKey::lt(const GrKey& rh) const { |
michael@0 | 52 | const SkDescriptor* srcDesc = ((const SkGrDescKey*)&rh)->fDesc; |
michael@0 | 53 | size_t lenLH = fDesc->getLength(); |
michael@0 | 54 | size_t lenRH = srcDesc->getLength(); |
michael@0 | 55 | int cmp = memcmp(fDesc, srcDesc, SkTMin<size_t>(lenLH, lenRH)); |
michael@0 | 56 | if (0 == cmp) { |
michael@0 | 57 | return lenLH < lenRH; |
michael@0 | 58 | } else { |
michael@0 | 59 | return cmp < 0; |
michael@0 | 60 | } |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | bool SkGrDescKey::eq(const GrKey& rh) const { |
michael@0 | 64 | const SkDescriptor* srcDesc = ((const SkGrDescKey*)&rh)->fDesc; |
michael@0 | 65 | return fDesc->equals(*srcDesc); |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 69 | |
michael@0 | 70 | SkGrFontScaler::SkGrFontScaler(SkGlyphCache* strike) { |
michael@0 | 71 | fStrike = strike; |
michael@0 | 72 | fKey = NULL; |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | SkGrFontScaler::~SkGrFontScaler() { |
michael@0 | 76 | SkSafeUnref(fKey); |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | GrMaskFormat SkGrFontScaler::getMaskFormat() { |
michael@0 | 80 | SkMask::Format format = fStrike->getMaskFormat(); |
michael@0 | 81 | switch (format) { |
michael@0 | 82 | case SkMask::kBW_Format: |
michael@0 | 83 | // fall through to kA8 -- we store BW glyphs in our 8-bit cache |
michael@0 | 84 | case SkMask::kA8_Format: |
michael@0 | 85 | return kA8_GrMaskFormat; |
michael@0 | 86 | case SkMask::kLCD16_Format: |
michael@0 | 87 | return kA565_GrMaskFormat; |
michael@0 | 88 | case SkMask::kLCD32_Format: |
michael@0 | 89 | return kA888_GrMaskFormat; |
michael@0 | 90 | case SkMask::kARGB32_Format: |
michael@0 | 91 | return kARGB_GrMaskFormat; |
michael@0 | 92 | default: |
michael@0 | 93 | SkDEBUGFAIL("unsupported SkMask::Format"); |
michael@0 | 94 | return kA8_GrMaskFormat; |
michael@0 | 95 | } |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | const GrKey* SkGrFontScaler::getKey() { |
michael@0 | 99 | if (NULL == fKey) { |
michael@0 | 100 | fKey = SkNEW_ARGS(SkGrDescKey, (fStrike->getDescriptor())); |
michael@0 | 101 | } |
michael@0 | 102 | return fKey; |
michael@0 | 103 | } |
michael@0 | 104 | |
michael@0 | 105 | bool SkGrFontScaler::getPackedGlyphBounds(GrGlyph::PackedID packed, |
michael@0 | 106 | SkIRect* bounds) { |
michael@0 | 107 | const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed), |
michael@0 | 108 | GrGlyph::UnpackFixedX(packed), |
michael@0 | 109 | GrGlyph::UnpackFixedY(packed)); |
michael@0 | 110 | bounds->setXYWH(glyph.fLeft, glyph.fTop, glyph.fWidth, glyph.fHeight); |
michael@0 | 111 | return true; |
michael@0 | 112 | |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | namespace { |
michael@0 | 116 | // expands each bit in a bitmask to 0 or ~0 of type INT_TYPE. Used to expand a BW glyph mask to |
michael@0 | 117 | // A8, RGB565, or RGBA8888. |
michael@0 | 118 | template <typename INT_TYPE> |
michael@0 | 119 | void expand_bits(INT_TYPE* dst, |
michael@0 | 120 | const uint8_t* src, |
michael@0 | 121 | int width, |
michael@0 | 122 | int height, |
michael@0 | 123 | int dstRowBytes, |
michael@0 | 124 | int srcRowBytes) { |
michael@0 | 125 | for (int i = 0; i < height; ++i) { |
michael@0 | 126 | int rowWritesLeft = width; |
michael@0 | 127 | const uint8_t* s = src; |
michael@0 | 128 | INT_TYPE* d = dst; |
michael@0 | 129 | while (rowWritesLeft > 0) { |
michael@0 | 130 | unsigned mask = *s++; |
michael@0 | 131 | for (int i = 7; i >= 0 && rowWritesLeft; --i, --rowWritesLeft) { |
michael@0 | 132 | *d++ = (mask & (1 << i)) ? (INT_TYPE)(~0UL) : 0; |
michael@0 | 133 | } |
michael@0 | 134 | } |
michael@0 | 135 | dst = reinterpret_cast<INT_TYPE*>(reinterpret_cast<intptr_t>(dst) + dstRowBytes); |
michael@0 | 136 | src += srcRowBytes; |
michael@0 | 137 | } |
michael@0 | 138 | } |
michael@0 | 139 | } |
michael@0 | 140 | |
michael@0 | 141 | bool SkGrFontScaler::getPackedGlyphImage(GrGlyph::PackedID packed, |
michael@0 | 142 | int width, int height, |
michael@0 | 143 | int dstRB, void* dst) { |
michael@0 | 144 | const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed), |
michael@0 | 145 | GrGlyph::UnpackFixedX(packed), |
michael@0 | 146 | GrGlyph::UnpackFixedY(packed)); |
michael@0 | 147 | SkASSERT(glyph.fWidth == width); |
michael@0 | 148 | SkASSERT(glyph.fHeight == height); |
michael@0 | 149 | const void* src = fStrike->findImage(glyph); |
michael@0 | 150 | if (NULL == src) { |
michael@0 | 151 | return false; |
michael@0 | 152 | } |
michael@0 | 153 | |
michael@0 | 154 | int srcRB = glyph.rowBytes(); |
michael@0 | 155 | // The windows font host sometimes has BW glyphs in a non-BW strike. So it is important here to |
michael@0 | 156 | // check the glyph's format, not the strike's format, and to be able to convert to any of the |
michael@0 | 157 | // GrMaskFormats. |
michael@0 | 158 | if (SkMask::kBW_Format == glyph.fMaskFormat) { |
michael@0 | 159 | // expand bits to our mask type |
michael@0 | 160 | const uint8_t* bits = reinterpret_cast<const uint8_t*>(src); |
michael@0 | 161 | switch (this->getMaskFormat()) { |
michael@0 | 162 | case kA8_GrMaskFormat:{ |
michael@0 | 163 | uint8_t* bytes = reinterpret_cast<uint8_t*>(dst); |
michael@0 | 164 | expand_bits(bytes, bits, width, height, dstRB, srcRB); |
michael@0 | 165 | break; |
michael@0 | 166 | } |
michael@0 | 167 | case kA565_GrMaskFormat: { |
michael@0 | 168 | uint16_t* rgb565 = reinterpret_cast<uint16_t*>(dst); |
michael@0 | 169 | expand_bits(rgb565, bits, width, height, dstRB, srcRB); |
michael@0 | 170 | break; |
michael@0 | 171 | } |
michael@0 | 172 | case kA888_GrMaskFormat: { |
michael@0 | 173 | uint32_t* rgba8888 = reinterpret_cast<uint32_t*>(dst); |
michael@0 | 174 | expand_bits(rgba8888, bits, width, height, dstRB, srcRB); |
michael@0 | 175 | break; |
michael@0 | 176 | } |
michael@0 | 177 | default: |
michael@0 | 178 | GrCrash("Invalid GrMaskFormat"); |
michael@0 | 179 | } |
michael@0 | 180 | } else if (srcRB == dstRB) { |
michael@0 | 181 | memcpy(dst, src, dstRB * height); |
michael@0 | 182 | } else { |
michael@0 | 183 | const int bbp = GrMaskFormatBytesPerPixel(this->getMaskFormat()); |
michael@0 | 184 | for (int y = 0; y < height; y++) { |
michael@0 | 185 | memcpy(dst, src, width * bbp); |
michael@0 | 186 | src = (const char*)src + srcRB; |
michael@0 | 187 | dst = (char*)dst + dstRB; |
michael@0 | 188 | } |
michael@0 | 189 | } |
michael@0 | 190 | return true; |
michael@0 | 191 | } |
michael@0 | 192 | |
michael@0 | 193 | // we should just return const SkPath* (NULL means false) |
michael@0 | 194 | bool SkGrFontScaler::getGlyphPath(uint16_t glyphID, SkPath* path) { |
michael@0 | 195 | |
michael@0 | 196 | const SkGlyph& glyph = fStrike->getGlyphIDMetrics(glyphID); |
michael@0 | 197 | const SkPath* skPath = fStrike->findPath(glyph); |
michael@0 | 198 | if (skPath) { |
michael@0 | 199 | *path = *skPath; |
michael@0 | 200 | return true; |
michael@0 | 201 | } |
michael@0 | 202 | return false; |
michael@0 | 203 | } |