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 | * Copyright 2012 Google Inc. |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 5 | * found in the LICENSE file. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | #include "SkBitmapDevice.h" |
michael@0 | 9 | #include "SkCanvas.h" |
michael@0 | 10 | #include "SkData.h" |
michael@0 | 11 | #include "SkNoSaveLayerCanvas.h" |
michael@0 | 12 | #include "SkPictureUtils.h" |
michael@0 | 13 | #include "SkPixelRef.h" |
michael@0 | 14 | #include "SkRRect.h" |
michael@0 | 15 | #include "SkShader.h" |
michael@0 | 16 | |
michael@0 | 17 | class PixelRefSet { |
michael@0 | 18 | public: |
michael@0 | 19 | PixelRefSet(SkTDArray<SkPixelRef*>* array) : fArray(array) {} |
michael@0 | 20 | |
michael@0 | 21 | // This does a linear search on existing pixelrefs, so if this list gets big |
michael@0 | 22 | // we should use a more complex sorted/hashy thing. |
michael@0 | 23 | // |
michael@0 | 24 | void add(SkPixelRef* pr) { |
michael@0 | 25 | uint32_t genID = pr->getGenerationID(); |
michael@0 | 26 | if (fGenID.find(genID) < 0) { |
michael@0 | 27 | *fArray->append() = pr; |
michael@0 | 28 | *fGenID.append() = genID; |
michael@0 | 29 | // SkDebugf("--- adding [%d] %x %d\n", fArray->count() - 1, pr, genID); |
michael@0 | 30 | } else { |
michael@0 | 31 | // SkDebugf("--- already have %x %d\n", pr, genID); |
michael@0 | 32 | } |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | private: |
michael@0 | 36 | SkTDArray<SkPixelRef*>* fArray; |
michael@0 | 37 | SkTDArray<uint32_t> fGenID; |
michael@0 | 38 | }; |
michael@0 | 39 | |
michael@0 | 40 | static void not_supported() { |
michael@0 | 41 | SkDEBUGFAIL("this method should never be called"); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | static void nothing_to_do() {} |
michael@0 | 45 | |
michael@0 | 46 | /** |
michael@0 | 47 | * This device will route all bitmaps (primitives and in shaders) to its PRSet. |
michael@0 | 48 | * It should never actually draw anything, so there need not be any pixels |
michael@0 | 49 | * behind its device. |
michael@0 | 50 | */ |
michael@0 | 51 | class GatherPixelRefDevice : public SkBaseDevice { |
michael@0 | 52 | public: |
michael@0 | 53 | SK_DECLARE_INST_COUNT(GatherPixelRefDevice) |
michael@0 | 54 | |
michael@0 | 55 | GatherPixelRefDevice(int width, int height, PixelRefSet* prset) { |
michael@0 | 56 | fSize.set(width, height); |
michael@0 | 57 | fEmptyBitmap.setConfig(SkImageInfo::MakeUnknown(width, height)); |
michael@0 | 58 | fPRSet = prset; |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | virtual int width() const SK_OVERRIDE { return fSize.width(); } |
michael@0 | 62 | virtual int height() const SK_OVERRIDE { return fSize.height(); } |
michael@0 | 63 | virtual bool isOpaque() const SK_OVERRIDE { return false; } |
michael@0 | 64 | virtual SkBitmap::Config config() const SK_OVERRIDE { |
michael@0 | 65 | return SkBitmap::kNo_Config; |
michael@0 | 66 | } |
michael@0 | 67 | virtual GrRenderTarget* accessRenderTarget() SK_OVERRIDE { return NULL; } |
michael@0 | 68 | virtual bool filterTextFlags(const SkPaint& paint, TextFlags*) SK_OVERRIDE { |
michael@0 | 69 | return false; |
michael@0 | 70 | } |
michael@0 | 71 | // TODO: allow this call to return failure, or move to SkBitmapDevice only. |
michael@0 | 72 | virtual const SkBitmap& onAccessBitmap() SK_OVERRIDE { |
michael@0 | 73 | return fEmptyBitmap; |
michael@0 | 74 | } |
michael@0 | 75 | virtual void lockPixels() SK_OVERRIDE { nothing_to_do(); } |
michael@0 | 76 | virtual void unlockPixels() SK_OVERRIDE { nothing_to_do(); } |
michael@0 | 77 | virtual bool allowImageFilter(const SkImageFilter*) SK_OVERRIDE { return false; } |
michael@0 | 78 | virtual bool canHandleImageFilter(const SkImageFilter*) SK_OVERRIDE { return false; } |
michael@0 | 79 | virtual bool filterImage(const SkImageFilter*, const SkBitmap&, const SkImageFilter::Context&, |
michael@0 | 80 | SkBitmap* result, SkIPoint* offset) SK_OVERRIDE { |
michael@0 | 81 | return false; |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | virtual void clear(SkColor color) SK_OVERRIDE { |
michael@0 | 85 | nothing_to_do(); |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | #ifdef SK_SUPPORT_LEGACY_WRITEPIXELSCONFIG |
michael@0 | 89 | virtual void writePixels(const SkBitmap& bitmap, int x, int y, |
michael@0 | 90 | SkCanvas::Config8888 config8888) SK_OVERRIDE { |
michael@0 | 91 | not_supported(); |
michael@0 | 92 | } |
michael@0 | 93 | #endif |
michael@0 | 94 | |
michael@0 | 95 | virtual void drawPaint(const SkDraw&, const SkPaint& paint) SK_OVERRIDE { |
michael@0 | 96 | this->addBitmapFromPaint(paint); |
michael@0 | 97 | } |
michael@0 | 98 | virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, size_t count, |
michael@0 | 99 | const SkPoint[], const SkPaint& paint) SK_OVERRIDE { |
michael@0 | 100 | this->addBitmapFromPaint(paint); |
michael@0 | 101 | } |
michael@0 | 102 | virtual void drawRect(const SkDraw&, const SkRect&, |
michael@0 | 103 | const SkPaint& paint) SK_OVERRIDE { |
michael@0 | 104 | this->addBitmapFromPaint(paint); |
michael@0 | 105 | } |
michael@0 | 106 | virtual void drawRRect(const SkDraw&, const SkRRect&, |
michael@0 | 107 | const SkPaint& paint) SK_OVERRIDE { |
michael@0 | 108 | this->addBitmapFromPaint(paint); |
michael@0 | 109 | } |
michael@0 | 110 | virtual void drawOval(const SkDraw&, const SkRect&, |
michael@0 | 111 | const SkPaint& paint) SK_OVERRIDE { |
michael@0 | 112 | this->addBitmapFromPaint(paint); |
michael@0 | 113 | } |
michael@0 | 114 | virtual void drawPath(const SkDraw&, const SkPath& path, |
michael@0 | 115 | const SkPaint& paint, const SkMatrix* prePathMatrix, |
michael@0 | 116 | bool pathIsMutable) SK_OVERRIDE { |
michael@0 | 117 | this->addBitmapFromPaint(paint); |
michael@0 | 118 | } |
michael@0 | 119 | virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap, |
michael@0 | 120 | const SkMatrix&, const SkPaint& paint) SK_OVERRIDE { |
michael@0 | 121 | this->addBitmap(bitmap); |
michael@0 | 122 | if (SkBitmap::kA8_Config == bitmap.config()) { |
michael@0 | 123 | this->addBitmapFromPaint(paint); |
michael@0 | 124 | } |
michael@0 | 125 | } |
michael@0 | 126 | virtual void drawBitmapRect(const SkDraw&, const SkBitmap& bitmap, |
michael@0 | 127 | const SkRect* srcOrNull, const SkRect& dst, |
michael@0 | 128 | const SkPaint& paint, |
michael@0 | 129 | SkCanvas::DrawBitmapRectFlags flags) SK_OVERRIDE { |
michael@0 | 130 | this->addBitmap(bitmap); |
michael@0 | 131 | if (SkBitmap::kA8_Config == bitmap.config()) { |
michael@0 | 132 | this->addBitmapFromPaint(paint); |
michael@0 | 133 | } |
michael@0 | 134 | } |
michael@0 | 135 | virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap, |
michael@0 | 136 | int x, int y, const SkPaint& paint) SK_OVERRIDE { |
michael@0 | 137 | this->addBitmap(bitmap); |
michael@0 | 138 | } |
michael@0 | 139 | virtual void drawText(const SkDraw&, const void* text, size_t len, |
michael@0 | 140 | SkScalar x, SkScalar y, |
michael@0 | 141 | const SkPaint& paint) SK_OVERRIDE { |
michael@0 | 142 | this->addBitmapFromPaint(paint); |
michael@0 | 143 | } |
michael@0 | 144 | virtual void drawPosText(const SkDraw&, const void* text, size_t len, |
michael@0 | 145 | const SkScalar pos[], SkScalar constY, |
michael@0 | 146 | int, const SkPaint& paint) SK_OVERRIDE { |
michael@0 | 147 | this->addBitmapFromPaint(paint); |
michael@0 | 148 | } |
michael@0 | 149 | virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len, |
michael@0 | 150 | const SkPath& path, const SkMatrix* matrix, |
michael@0 | 151 | const SkPaint& paint) SK_OVERRIDE { |
michael@0 | 152 | this->addBitmapFromPaint(paint); |
michael@0 | 153 | } |
michael@0 | 154 | virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, int vertexCount, |
michael@0 | 155 | const SkPoint verts[], const SkPoint texs[], |
michael@0 | 156 | const SkColor colors[], SkXfermode* xmode, |
michael@0 | 157 | const uint16_t indices[], int indexCount, |
michael@0 | 158 | const SkPaint& paint) SK_OVERRIDE { |
michael@0 | 159 | this->addBitmapFromPaint(paint); |
michael@0 | 160 | } |
michael@0 | 161 | virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y, |
michael@0 | 162 | const SkPaint&) SK_OVERRIDE { |
michael@0 | 163 | nothing_to_do(); |
michael@0 | 164 | } |
michael@0 | 165 | |
michael@0 | 166 | protected: |
michael@0 | 167 | virtual bool onReadPixels(const SkBitmap& bitmap, |
michael@0 | 168 | int x, int y, |
michael@0 | 169 | SkCanvas::Config8888 config8888) SK_OVERRIDE { |
michael@0 | 170 | not_supported(); |
michael@0 | 171 | return false; |
michael@0 | 172 | } |
michael@0 | 173 | |
michael@0 | 174 | virtual void replaceBitmapBackendForRasterSurface(const SkBitmap&) SK_OVERRIDE { |
michael@0 | 175 | not_supported(); |
michael@0 | 176 | } |
michael@0 | 177 | virtual SkBaseDevice* onCreateDevice(const SkImageInfo& info, Usage usage) SK_OVERRIDE { |
michael@0 | 178 | // we expect to only get called via savelayer, in which case it is fine. |
michael@0 | 179 | SkASSERT(kSaveLayer_Usage == usage); |
michael@0 | 180 | return SkNEW_ARGS(GatherPixelRefDevice, (info.width(), info.height(), fPRSet)); |
michael@0 | 181 | } |
michael@0 | 182 | virtual void flush() SK_OVERRIDE {} |
michael@0 | 183 | |
michael@0 | 184 | private: |
michael@0 | 185 | PixelRefSet* fPRSet; |
michael@0 | 186 | SkBitmap fEmptyBitmap; // legacy -- need to remove the need for this guy |
michael@0 | 187 | SkISize fSize; |
michael@0 | 188 | |
michael@0 | 189 | void addBitmap(const SkBitmap& bm) { |
michael@0 | 190 | fPRSet->add(bm.pixelRef()); |
michael@0 | 191 | } |
michael@0 | 192 | |
michael@0 | 193 | void addBitmapFromPaint(const SkPaint& paint) { |
michael@0 | 194 | SkShader* shader = paint.getShader(); |
michael@0 | 195 | if (shader) { |
michael@0 | 196 | SkBitmap bm; |
michael@0 | 197 | // Check whether the shader is a gradient in order to short-circuit |
michael@0 | 198 | // call to asABitmap to prevent generation of bitmaps from |
michael@0 | 199 | // gradient shaders, which implement asABitmap. |
michael@0 | 200 | if (SkShader::kNone_GradientType == shader->asAGradient(NULL) && |
michael@0 | 201 | shader->asABitmap(&bm, NULL, NULL)) { |
michael@0 | 202 | fPRSet->add(bm.pixelRef()); |
michael@0 | 203 | } |
michael@0 | 204 | } |
michael@0 | 205 | } |
michael@0 | 206 | |
michael@0 | 207 | typedef SkBaseDevice INHERITED; |
michael@0 | 208 | }; |
michael@0 | 209 | |
michael@0 | 210 | SkData* SkPictureUtils::GatherPixelRefs(SkPicture* pict, const SkRect& area) { |
michael@0 | 211 | if (NULL == pict) { |
michael@0 | 212 | return NULL; |
michael@0 | 213 | } |
michael@0 | 214 | |
michael@0 | 215 | // this test also handles if either area or pict's width/height are empty |
michael@0 | 216 | if (!SkRect::Intersects(area, |
michael@0 | 217 | SkRect::MakeWH(SkIntToScalar(pict->width()), |
michael@0 | 218 | SkIntToScalar(pict->height())))) { |
michael@0 | 219 | return NULL; |
michael@0 | 220 | } |
michael@0 | 221 | |
michael@0 | 222 | SkTDArray<SkPixelRef*> array; |
michael@0 | 223 | PixelRefSet prset(&array); |
michael@0 | 224 | |
michael@0 | 225 | GatherPixelRefDevice device(pict->width(), pict->height(), &prset); |
michael@0 | 226 | SkNoSaveLayerCanvas canvas(&device); |
michael@0 | 227 | |
michael@0 | 228 | canvas.clipRect(area, SkRegion::kIntersect_Op, false); |
michael@0 | 229 | canvas.drawPicture(*pict); |
michael@0 | 230 | |
michael@0 | 231 | SkData* data = NULL; |
michael@0 | 232 | int count = array.count(); |
michael@0 | 233 | if (count > 0) { |
michael@0 | 234 | data = SkData::NewFromMalloc(array.detach(), count * sizeof(SkPixelRef*)); |
michael@0 | 235 | } |
michael@0 | 236 | return data; |
michael@0 | 237 | } |