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 2011 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 "SkDevice.h" |
michael@0 | 9 | #include "SkMetaData.h" |
michael@0 | 10 | |
michael@0 | 11 | #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A) |
michael@0 | 12 | const SkCanvas::Config8888 SkBaseDevice::kPMColorAlias = SkCanvas::kBGRA_Premul_Config8888; |
michael@0 | 13 | #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A) |
michael@0 | 14 | const SkCanvas::Config8888 SkBaseDevice::kPMColorAlias = SkCanvas::kRGBA_Premul_Config8888; |
michael@0 | 15 | #else |
michael@0 | 16 | const SkCanvas::Config8888 SkBaseDevice::kPMColorAlias = (SkCanvas::Config8888) -1; |
michael@0 | 17 | #endif |
michael@0 | 18 | |
michael@0 | 19 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 20 | |
michael@0 | 21 | SkBaseDevice::SkBaseDevice() |
michael@0 | 22 | : fLeakyProperties(SkDeviceProperties::MakeDefault()) |
michael@0 | 23 | #ifdef SK_DEBUG |
michael@0 | 24 | , fAttachedToCanvas(false) |
michael@0 | 25 | #endif |
michael@0 | 26 | { |
michael@0 | 27 | fOrigin.setZero(); |
michael@0 | 28 | fMetaData = NULL; |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | SkBaseDevice::SkBaseDevice(const SkDeviceProperties& deviceProperties) |
michael@0 | 32 | : fLeakyProperties(deviceProperties) |
michael@0 | 33 | #ifdef SK_DEBUG |
michael@0 | 34 | , fAttachedToCanvas(false) |
michael@0 | 35 | #endif |
michael@0 | 36 | { |
michael@0 | 37 | fOrigin.setZero(); |
michael@0 | 38 | fMetaData = NULL; |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | SkBaseDevice::~SkBaseDevice() { |
michael@0 | 42 | delete fMetaData; |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | SkBaseDevice* SkBaseDevice::createCompatibleDevice(const SkImageInfo& info) { |
michael@0 | 46 | #ifdef SK_SUPPORT_LEGACY_COMPATIBLEDEVICE_CONFIG |
michael@0 | 47 | // We call the old method to support older subclasses. |
michael@0 | 48 | // If they have, we return their device, else we use the new impl. |
michael@0 | 49 | SkBitmap::Config config = SkColorTypeToBitmapConfig(info.colorType()); |
michael@0 | 50 | SkBaseDevice* dev = this->onCreateCompatibleDevice(config, |
michael@0 | 51 | info.width(), |
michael@0 | 52 | info.height(), |
michael@0 | 53 | info.isOpaque(), |
michael@0 | 54 | kGeneral_Usage); |
michael@0 | 55 | if (dev) { |
michael@0 | 56 | return dev; |
michael@0 | 57 | } |
michael@0 | 58 | // fall through to new impl |
michael@0 | 59 | #endif |
michael@0 | 60 | return this->onCreateDevice(info, kGeneral_Usage); |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | SkBaseDevice* SkBaseDevice::createCompatibleDeviceForSaveLayer(const SkImageInfo& info) { |
michael@0 | 64 | #ifdef SK_SUPPORT_LEGACY_COMPATIBLEDEVICE_CONFIG |
michael@0 | 65 | // We call the old method to support older subclasses. |
michael@0 | 66 | // If they have, we return their device, else we use the new impl. |
michael@0 | 67 | SkBitmap::Config config = SkColorTypeToBitmapConfig(info.colorType()); |
michael@0 | 68 | SkBaseDevice* dev = this->onCreateCompatibleDevice(config, |
michael@0 | 69 | info.width(), |
michael@0 | 70 | info.height(), |
michael@0 | 71 | info.isOpaque(), |
michael@0 | 72 | kSaveLayer_Usage); |
michael@0 | 73 | if (dev) { |
michael@0 | 74 | return dev; |
michael@0 | 75 | } |
michael@0 | 76 | // fall through to new impl |
michael@0 | 77 | #endif |
michael@0 | 78 | return this->onCreateDevice(info, kSaveLayer_Usage); |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | #ifdef SK_SUPPORT_LEGACY_COMPATIBLEDEVICE_CONFIG |
michael@0 | 82 | SkBaseDevice* SkBaseDevice::createCompatibleDevice(SkBitmap::Config config, |
michael@0 | 83 | int width, int height, |
michael@0 | 84 | bool isOpaque) { |
michael@0 | 85 | SkImageInfo info = SkImageInfo::Make(width, height, |
michael@0 | 86 | SkBitmapConfigToColorType(config), |
michael@0 | 87 | isOpaque ? kOpaque_SkAlphaType |
michael@0 | 88 | : kPremul_SkAlphaType); |
michael@0 | 89 | return this->createCompatibleDevice(info); |
michael@0 | 90 | } |
michael@0 | 91 | #endif |
michael@0 | 92 | |
michael@0 | 93 | SkMetaData& SkBaseDevice::getMetaData() { |
michael@0 | 94 | // metadata users are rare, so we lazily allocate it. If that changes we |
michael@0 | 95 | // can decide to just make it a field in the device (rather than a ptr) |
michael@0 | 96 | if (NULL == fMetaData) { |
michael@0 | 97 | fMetaData = new SkMetaData; |
michael@0 | 98 | } |
michael@0 | 99 | return *fMetaData; |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | // TODO: should make this guy pure-virtual. |
michael@0 | 103 | SkImageInfo SkBaseDevice::imageInfo() const { |
michael@0 | 104 | return SkImageInfo::MakeUnknown(this->width(), this->height()); |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | const SkBitmap& SkBaseDevice::accessBitmap(bool changePixels) { |
michael@0 | 108 | const SkBitmap& bitmap = this->onAccessBitmap(); |
michael@0 | 109 | if (changePixels) { |
michael@0 | 110 | bitmap.notifyPixelsChanged(); |
michael@0 | 111 | } |
michael@0 | 112 | return bitmap; |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | bool SkBaseDevice::readPixels(SkBitmap* bitmap, int x, int y, |
michael@0 | 116 | SkCanvas::Config8888 config8888) { |
michael@0 | 117 | if (SkBitmap::kARGB_8888_Config != bitmap->config() || |
michael@0 | 118 | NULL != bitmap->getTexture()) { |
michael@0 | 119 | return false; |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | const SkBitmap& src = this->accessBitmap(false); |
michael@0 | 123 | |
michael@0 | 124 | SkIRect srcRect = SkIRect::MakeXYWH(x, y, bitmap->width(), |
michael@0 | 125 | bitmap->height()); |
michael@0 | 126 | SkIRect devbounds = SkIRect::MakeWH(src.width(), src.height()); |
michael@0 | 127 | if (!srcRect.intersect(devbounds)) { |
michael@0 | 128 | return false; |
michael@0 | 129 | } |
michael@0 | 130 | |
michael@0 | 131 | SkBitmap tmp; |
michael@0 | 132 | SkBitmap* bmp; |
michael@0 | 133 | if (bitmap->isNull()) { |
michael@0 | 134 | if (!tmp.allocPixels(SkImageInfo::MakeN32Premul(bitmap->width(), |
michael@0 | 135 | bitmap->height()))) { |
michael@0 | 136 | return false; |
michael@0 | 137 | } |
michael@0 | 138 | bmp = &tmp; |
michael@0 | 139 | } else { |
michael@0 | 140 | bmp = bitmap; |
michael@0 | 141 | } |
michael@0 | 142 | |
michael@0 | 143 | SkIRect subrect = srcRect; |
michael@0 | 144 | subrect.offset(-x, -y); |
michael@0 | 145 | SkBitmap bmpSubset; |
michael@0 | 146 | bmp->extractSubset(&bmpSubset, subrect); |
michael@0 | 147 | |
michael@0 | 148 | bool result = this->onReadPixels(bmpSubset, |
michael@0 | 149 | srcRect.fLeft, |
michael@0 | 150 | srcRect.fTop, |
michael@0 | 151 | config8888); |
michael@0 | 152 | if (result && bmp == &tmp) { |
michael@0 | 153 | tmp.swap(*bitmap); |
michael@0 | 154 | } |
michael@0 | 155 | return result; |
michael@0 | 156 | } |
michael@0 | 157 | |
michael@0 | 158 | SkSurface* SkBaseDevice::newSurface(const SkImageInfo&) { return NULL; } |
michael@0 | 159 | |
michael@0 | 160 | const void* SkBaseDevice::peekPixels(SkImageInfo*, size_t*) { return NULL; } |
michael@0 | 161 | |
michael@0 | 162 | void SkBaseDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, |
michael@0 | 163 | const SkRRect& inner, const SkPaint& paint) { |
michael@0 | 164 | SkPath path; |
michael@0 | 165 | path.addRRect(outer); |
michael@0 | 166 | path.addRRect(inner); |
michael@0 | 167 | path.setFillType(SkPath::kEvenOdd_FillType); |
michael@0 | 168 | |
michael@0 | 169 | const SkMatrix* preMatrix = NULL; |
michael@0 | 170 | const bool pathIsMutable = true; |
michael@0 | 171 | this->drawPath(draw, path, paint, preMatrix, pathIsMutable); |
michael@0 | 172 | } |
michael@0 | 173 | |
michael@0 | 174 | bool SkBaseDevice::writePixelsDirect(const SkImageInfo& info, const void* pixels, size_t rowBytes, |
michael@0 | 175 | int x, int y) { |
michael@0 | 176 | #ifdef SK_DEBUG |
michael@0 | 177 | SkASSERT(info.width() > 0 && info.height() > 0); |
michael@0 | 178 | SkASSERT(pixels); |
michael@0 | 179 | SkASSERT(rowBytes >= info.minRowBytes()); |
michael@0 | 180 | SkASSERT(x >= 0 && y >= 0); |
michael@0 | 181 | |
michael@0 | 182 | const SkImageInfo& dstInfo = this->imageInfo(); |
michael@0 | 183 | SkASSERT(x + info.width() <= dstInfo.width()); |
michael@0 | 184 | SkASSERT(y + info.height() <= dstInfo.height()); |
michael@0 | 185 | #endif |
michael@0 | 186 | return this->onWritePixels(info, pixels, rowBytes, x, y); |
michael@0 | 187 | } |
michael@0 | 188 | |
michael@0 | 189 | bool SkBaseDevice::onWritePixels(const SkImageInfo&, const void*, size_t, int, int) { |
michael@0 | 190 | return false; |
michael@0 | 191 | } |
michael@0 | 192 | |
michael@0 | 193 | bool SkBaseDevice::onReadPixels(const SkBitmap&, int x, int y, SkCanvas::Config8888) { |
michael@0 | 194 | return false; |
michael@0 | 195 | } |
michael@0 | 196 | |
michael@0 | 197 | void* SkBaseDevice::accessPixels(SkImageInfo* info, size_t* rowBytes) { |
michael@0 | 198 | SkImageInfo tmpInfo; |
michael@0 | 199 | size_t tmpRowBytes; |
michael@0 | 200 | if (NULL == info) { |
michael@0 | 201 | info = &tmpInfo; |
michael@0 | 202 | } |
michael@0 | 203 | if (NULL == rowBytes) { |
michael@0 | 204 | rowBytes = &tmpRowBytes; |
michael@0 | 205 | } |
michael@0 | 206 | return this->onAccessPixels(info, rowBytes); |
michael@0 | 207 | } |
michael@0 | 208 | |
michael@0 | 209 | void* SkBaseDevice::onAccessPixels(SkImageInfo* info, size_t* rowBytes) { |
michael@0 | 210 | return NULL; |
michael@0 | 211 | } |
michael@0 | 212 | |
michael@0 | 213 | #ifdef SK_SUPPORT_LEGACY_WRITEPIXELSCONFIG |
michael@0 | 214 | void SkBaseDevice::writePixels(const SkBitmap&, int x, int y, SkCanvas::Config8888) {} |
michael@0 | 215 | #endif |
michael@0 | 216 | |
michael@0 | 217 | void SkBaseDevice::EXPERIMENTAL_optimize(SkPicture* picture) { |
michael@0 | 218 | // The base class doesn't perform any analysis but derived classes may |
michael@0 | 219 | } |
michael@0 | 220 | |
michael@0 | 221 | bool SkBaseDevice::EXPERIMENTAL_drawPicture(const SkPicture& picture) { |
michael@0 | 222 | // The base class doesn't perform any accelerated picture rendering |
michael@0 | 223 | return false; |
michael@0 | 224 | } |