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 "SkSurface_Base.h" |
michael@0 | 9 | #include "SkImagePriv.h" |
michael@0 | 10 | #include "SkCanvas.h" |
michael@0 | 11 | #include "SkDevice.h" |
michael@0 | 12 | #include "SkMallocPixelRef.h" |
michael@0 | 13 | |
michael@0 | 14 | static const size_t kIgnoreRowBytesValue = (size_t)~0; |
michael@0 | 15 | |
michael@0 | 16 | class SkSurface_Raster : public SkSurface_Base { |
michael@0 | 17 | public: |
michael@0 | 18 | static bool Valid(const SkImageInfo&, size_t rb = kIgnoreRowBytesValue); |
michael@0 | 19 | |
michael@0 | 20 | SkSurface_Raster(const SkImageInfo&, void*, size_t rb); |
michael@0 | 21 | SkSurface_Raster(SkPixelRef*); |
michael@0 | 22 | |
michael@0 | 23 | virtual SkCanvas* onNewCanvas() SK_OVERRIDE; |
michael@0 | 24 | virtual SkSurface* onNewSurface(const SkImageInfo&) SK_OVERRIDE; |
michael@0 | 25 | virtual SkImage* onNewImageSnapshot() SK_OVERRIDE; |
michael@0 | 26 | virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, |
michael@0 | 27 | const SkPaint*) SK_OVERRIDE; |
michael@0 | 28 | virtual void onCopyOnWrite(ContentChangeMode) SK_OVERRIDE; |
michael@0 | 29 | |
michael@0 | 30 | private: |
michael@0 | 31 | SkBitmap fBitmap; |
michael@0 | 32 | bool fWeOwnThePixels; |
michael@0 | 33 | |
michael@0 | 34 | typedef SkSurface_Base INHERITED; |
michael@0 | 35 | }; |
michael@0 | 36 | |
michael@0 | 37 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 38 | |
michael@0 | 39 | bool SkSurface_Raster::Valid(const SkImageInfo& info, size_t rowBytes) { |
michael@0 | 40 | static const size_t kMaxTotalSize = SK_MaxS32; |
michael@0 | 41 | |
michael@0 | 42 | int shift = 0; |
michael@0 | 43 | switch (info.fColorType) { |
michael@0 | 44 | case kAlpha_8_SkColorType: |
michael@0 | 45 | shift = 0; |
michael@0 | 46 | break; |
michael@0 | 47 | case kRGB_565_SkColorType: |
michael@0 | 48 | shift = 1; |
michael@0 | 49 | break; |
michael@0 | 50 | case kPMColor_SkColorType: |
michael@0 | 51 | shift = 2; |
michael@0 | 52 | break; |
michael@0 | 53 | default: |
michael@0 | 54 | return false; |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | if (kIgnoreRowBytesValue == rowBytes) { |
michael@0 | 58 | return true; |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | uint64_t minRB = (uint64_t)info.fWidth << shift; |
michael@0 | 62 | if (minRB > rowBytes) { |
michael@0 | 63 | return false; |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | size_t alignedRowBytes = rowBytes >> shift << shift; |
michael@0 | 67 | if (alignedRowBytes != rowBytes) { |
michael@0 | 68 | return false; |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | uint64_t size = sk_64_mul(info.fHeight, rowBytes); |
michael@0 | 72 | if (size > kMaxTotalSize) { |
michael@0 | 73 | return false; |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | return true; |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | SkSurface_Raster::SkSurface_Raster(const SkImageInfo& info, void* pixels, size_t rb) |
michael@0 | 80 | : INHERITED(info) |
michael@0 | 81 | { |
michael@0 | 82 | fBitmap.setConfig(info, rb); |
michael@0 | 83 | fBitmap.setPixels(pixels); |
michael@0 | 84 | fWeOwnThePixels = false; // We are "Direct" |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | SkSurface_Raster::SkSurface_Raster(SkPixelRef* pr) |
michael@0 | 88 | : INHERITED(pr->info().fWidth, pr->info().fHeight) |
michael@0 | 89 | { |
michael@0 | 90 | const SkImageInfo& info = pr->info(); |
michael@0 | 91 | |
michael@0 | 92 | fBitmap.setConfig(info, info.minRowBytes()); |
michael@0 | 93 | fBitmap.setPixelRef(pr); |
michael@0 | 94 | fWeOwnThePixels = true; |
michael@0 | 95 | |
michael@0 | 96 | if (!info.isOpaque()) { |
michael@0 | 97 | fBitmap.eraseColor(SK_ColorTRANSPARENT); |
michael@0 | 98 | } |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | SkCanvas* SkSurface_Raster::onNewCanvas() { |
michael@0 | 102 | return SkNEW_ARGS(SkCanvas, (fBitmap)); |
michael@0 | 103 | } |
michael@0 | 104 | |
michael@0 | 105 | SkSurface* SkSurface_Raster::onNewSurface(const SkImageInfo& info) { |
michael@0 | 106 | return SkSurface::NewRaster(info); |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | void SkSurface_Raster::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, |
michael@0 | 110 | const SkPaint* paint) { |
michael@0 | 111 | canvas->drawBitmap(fBitmap, x, y, paint); |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | SkImage* SkSurface_Raster::onNewImageSnapshot() { |
michael@0 | 115 | return SkNewImageFromBitmap(fBitmap, fWeOwnThePixels); |
michael@0 | 116 | } |
michael@0 | 117 | |
michael@0 | 118 | void SkSurface_Raster::onCopyOnWrite(ContentChangeMode mode) { |
michael@0 | 119 | // are we sharing pixelrefs with the image? |
michael@0 | 120 | SkASSERT(NULL != this->getCachedImage()); |
michael@0 | 121 | if (SkBitmapImageGetPixelRef(this->getCachedImage()) == fBitmap.pixelRef()) { |
michael@0 | 122 | SkASSERT(fWeOwnThePixels); |
michael@0 | 123 | if (kDiscard_ContentChangeMode == mode) { |
michael@0 | 124 | fBitmap.setPixelRef(NULL); |
michael@0 | 125 | fBitmap.allocPixels(); |
michael@0 | 126 | } else { |
michael@0 | 127 | SkBitmap prev(fBitmap); |
michael@0 | 128 | prev.deepCopyTo(&fBitmap); |
michael@0 | 129 | } |
michael@0 | 130 | // Now fBitmap is a deep copy of itself (and therefore different from |
michael@0 | 131 | // what is being used by the image. Next we update the canvas to use |
michael@0 | 132 | // this as its backend, so we can't modify the image's pixels anymore. |
michael@0 | 133 | SkASSERT(NULL != this->getCachedCanvas()); |
michael@0 | 134 | this->getCachedCanvas()->getDevice()->replaceBitmapBackendForRasterSurface(fBitmap); |
michael@0 | 135 | } |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 139 | |
michael@0 | 140 | SkSurface* SkSurface::NewRasterDirect(const SkImageInfo& info, void* pixels, size_t rowBytes) { |
michael@0 | 141 | if (!SkSurface_Raster::Valid(info, rowBytes)) { |
michael@0 | 142 | return NULL; |
michael@0 | 143 | } |
michael@0 | 144 | if (NULL == pixels) { |
michael@0 | 145 | return NULL; |
michael@0 | 146 | } |
michael@0 | 147 | |
michael@0 | 148 | return SkNEW_ARGS(SkSurface_Raster, (info, pixels, rowBytes)); |
michael@0 | 149 | } |
michael@0 | 150 | |
michael@0 | 151 | SkSurface* SkSurface::NewRaster(const SkImageInfo& info) { |
michael@0 | 152 | if (!SkSurface_Raster::Valid(info)) { |
michael@0 | 153 | return NULL; |
michael@0 | 154 | } |
michael@0 | 155 | |
michael@0 | 156 | SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewAllocate(info, 0, NULL)); |
michael@0 | 157 | if (NULL == pr.get()) { |
michael@0 | 158 | return NULL; |
michael@0 | 159 | } |
michael@0 | 160 | return SkNEW_ARGS(SkSurface_Raster, (pr)); |
michael@0 | 161 | } |