| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 #include "SkBitmapDevice.h" |
| 8 #include "SkDevice.h" | 9 #include "SkDevice.h" |
| 9 #include "SkDeviceProperties.h" | 10 #include "SkDeviceProperties.h" |
| 10 #include "SkDraw.h" | 11 #include "SkDraw.h" |
| 11 #include "SkImageFilter.h" | 12 #include "SkImageFilter.h" |
| 12 #include "SkMetaData.h" | 13 #include "SkMetaData.h" |
| 13 #include "SkRasterClip.h" | 14 #include "SkRasterClip.h" |
| 14 #include "SkRect.h" | 15 #include "SkRect.h" |
| 15 #include "SkRRect.h" | 16 #include "SkRRect.h" |
| 16 #include "SkShader.h" | 17 #include "SkShader.h" |
| 17 | 18 |
| 18 SK_DEFINE_INST_COUNT(SkDevice) | 19 SK_DEFINE_INST_COUNT(SkBaseDevice) |
| 20 SK_DEFINE_INST_COUNT(SkBitmapDevice) |
| 19 | 21 |
| 20 /////////////////////////////////////////////////////////////////////////////// | 22 /////////////////////////////////////////////////////////////////////////////// |
| 21 | 23 |
| 22 #define CHECK_FOR_NODRAW_ANNOTATION(paint) \ | 24 #define CHECK_FOR_NODRAW_ANNOTATION(paint) \ |
| 23 do { if (paint.isNoDrawAnnotation()) { return; } } while (0) | 25 do { if (paint.isNoDrawAnnotation()) { return; } } while (0) |
| 24 | 26 |
| 25 /////////////////////////////////////////////////////////////////////////////// | 27 /////////////////////////////////////////////////////////////////////////////// |
| 26 | 28 |
| 27 SkDevice::SkDevice(const SkBitmap& bitmap) | 29 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap) |
| 28 : fBitmap(bitmap), fLeakyProperties(SkDeviceProperties::MakeDefault()) | 30 : fBitmap(bitmap) { |
| 31 SkASSERT(SkBitmap::kARGB_4444_Config != bitmap.config()); |
| 32 } |
| 33 |
| 34 SkBaseDevice::SkBaseDevice() |
| 35 : fLeakyProperties(SkDeviceProperties::MakeDefault()) |
| 29 #ifdef SK_DEBUG | 36 #ifdef SK_DEBUG |
| 30 , fAttachedToCanvas(false) | 37 , fAttachedToCanvas(false) |
| 31 #endif | 38 #endif |
| 32 { | |
| 33 fOrigin.setZero(); | |
| 34 fMetaData = NULL; | |
| 35 | |
| 36 SkASSERT(SkBitmap::kARGB_4444_Config != bitmap.config()); | |
| 37 } | |
| 38 | |
| 39 SkDevice::SkDevice(const SkBitmap& bitmap, const SkDeviceProperties& devicePrope
rties) | |
| 40 : fBitmap(bitmap), fLeakyProperties(deviceProperties) | |
| 41 #ifdef SK_DEBUG | |
| 42 , fAttachedToCanvas(false) | |
| 43 #endif | |
| 44 { | 39 { |
| 45 fOrigin.setZero(); | 40 fOrigin.setZero(); |
| 46 fMetaData = NULL; | 41 fMetaData = NULL; |
| 47 } | 42 } |
| 48 | 43 |
| 49 SkDevice::SkDevice(SkBitmap::Config config, int width, int height, bool isOpaque
) | 44 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkDeviceProperties&
deviceProperties) |
| 50 : fLeakyProperties(SkDeviceProperties::MakeDefault()) | 45 : SkBaseDevice(deviceProperties) |
| 46 , fBitmap(bitmap) { |
| 47 } |
| 48 |
| 49 SkBaseDevice::SkBaseDevice(const SkDeviceProperties& deviceProperties) |
| 50 : fLeakyProperties(deviceProperties) |
| 51 #ifdef SK_DEBUG | 51 #ifdef SK_DEBUG |
| 52 , fAttachedToCanvas(false) | 52 , fAttachedToCanvas(false) |
| 53 #endif | 53 #endif |
| 54 { | 54 { |
| 55 fOrigin.setZero(); | 55 fOrigin.setZero(); |
| 56 fMetaData = NULL; | 56 fMetaData = NULL; |
| 57 } |
| 57 | 58 |
| 59 SkBitmapDevice::SkBitmapDevice(SkBitmap::Config config, int width, int height, b
ool isOpaque) { |
| 58 fBitmap.setConfig(config, width, height); | 60 fBitmap.setConfig(config, width, height); |
| 59 fBitmap.allocPixels(); | 61 fBitmap.allocPixels(); |
| 60 fBitmap.setIsOpaque(isOpaque); | 62 fBitmap.setIsOpaque(isOpaque); |
| 61 if (!isOpaque) { | 63 if (!isOpaque) { |
| 62 fBitmap.eraseColor(SK_ColorTRANSPARENT); | 64 fBitmap.eraseColor(SK_ColorTRANSPARENT); |
| 63 } | 65 } |
| 64 } | 66 } |
| 65 | 67 |
| 66 SkDevice::SkDevice(SkBitmap::Config config, int width, int height, bool isOpaque
, | 68 SkBitmapDevice::SkBitmapDevice(SkBitmap::Config config, int width, int height, b
ool isOpaque, |
| 67 const SkDeviceProperties& deviceProperties) | 69 const SkDeviceProperties& deviceProperties) |
| 68 : fLeakyProperties(deviceProperties) | 70 : SkBaseDevice(deviceProperties) { |
| 69 #ifdef SK_DEBUG | |
| 70 , fAttachedToCanvas(false) | |
| 71 #endif | |
| 72 { | |
| 73 fOrigin.setZero(); | |
| 74 fMetaData = NULL; | |
| 75 | 71 |
| 76 fBitmap.setConfig(config, width, height); | 72 fBitmap.setConfig(config, width, height); |
| 77 fBitmap.allocPixels(); | 73 fBitmap.allocPixels(); |
| 78 fBitmap.setIsOpaque(isOpaque); | 74 fBitmap.setIsOpaque(isOpaque); |
| 79 if (!isOpaque) { | 75 if (!isOpaque) { |
| 80 fBitmap.eraseColor(SK_ColorTRANSPARENT); | 76 fBitmap.eraseColor(SK_ColorTRANSPARENT); |
| 81 } | 77 } |
| 82 } | 78 } |
| 83 | 79 |
| 84 SkDevice::~SkDevice() { | 80 SkBaseDevice::~SkBaseDevice() { |
| 85 delete fMetaData; | 81 delete fMetaData; |
| 86 } | 82 } |
| 87 | 83 |
| 88 void SkDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) { | 84 SkBitmapDevice::~SkBitmapDevice() { |
| 85 } |
| 86 |
| 87 void SkBitmapDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) { |
| 89 SkASSERT(bm.width() == fBitmap.width()); | 88 SkASSERT(bm.width() == fBitmap.width()); |
| 90 SkASSERT(bm.height() == fBitmap.height()); | 89 SkASSERT(bm.height() == fBitmap.height()); |
| 91 fBitmap = bm; // intent is to use bm's pixelRef (and rowbytes/config) | 90 fBitmap = bm; // intent is to use bm's pixelRef (and rowbytes/config) |
| 92 fBitmap.lockPixels(); | 91 fBitmap.lockPixels(); |
| 93 } | 92 } |
| 94 | 93 |
| 95 SkDevice* SkDevice::createCompatibleDevice(SkBitmap::Config config, | 94 SkBaseDevice* SkBaseDevice::createCompatibleDevice(SkBitmap::Config config, |
| 96 int width, int height, | 95 int width, int height, |
| 97 bool isOpaque) { | 96 bool isOpaque) { |
| 98 return this->onCreateCompatibleDevice(config, width, height, | 97 return this->onCreateCompatibleDevice(config, width, height, |
| 99 isOpaque, kGeneral_Usage); | 98 isOpaque, kGeneral_Usage); |
| 100 } | 99 } |
| 101 | 100 |
| 102 SkDevice* SkDevice::createCompatibleDeviceForSaveLayer(SkBitmap::Config config, | 101 SkBaseDevice* SkBaseDevice::createCompatibleDeviceForSaveLayer(SkBitmap::Config
config, |
| 103 int width, int height, | 102 int width, int he
ight, |
| 104 bool isOpaque) { | 103 bool isOpaque) { |
| 105 return this->onCreateCompatibleDevice(config, width, height, | 104 return this->onCreateCompatibleDevice(config, width, height, |
| 106 isOpaque, kSaveLayer_Usage); | 105 isOpaque, kSaveLayer_Usage); |
| 107 } | 106 } |
| 108 | 107 |
| 109 SkDevice* SkDevice::onCreateCompatibleDevice(SkBitmap::Config config, | 108 SkBaseDevice* SkBitmapDevice::onCreateCompatibleDevice(SkBitmap::Config config, |
| 110 int width, int height, | 109 int width, int height, |
| 111 bool isOpaque, | 110 bool isOpaque, |
| 112 Usage usage) { | 111 Usage usage) { |
| 113 return SkNEW_ARGS(SkDevice,(config, width, height, isOpaque, fLeakyPropertie
s)); | 112 return SkNEW_ARGS(SkBitmapDevice,(config, width, height, isOpaque, |
| 113 this->getDeviceProperties())); |
| 114 } | 114 } |
| 115 | 115 |
| 116 SkMetaData& SkDevice::getMetaData() { | 116 SkMetaData& SkBaseDevice::getMetaData() { |
| 117 // metadata users are rare, so we lazily allocate it. If that changes we | 117 // metadata users are rare, so we lazily allocate it. If that changes we |
| 118 // can decide to just make it a field in the device (rather than a ptr) | 118 // can decide to just make it a field in the device (rather than a ptr) |
| 119 if (NULL == fMetaData) { | 119 if (NULL == fMetaData) { |
| 120 fMetaData = new SkMetaData; | 120 fMetaData = new SkMetaData; |
| 121 } | 121 } |
| 122 return *fMetaData; | 122 return *fMetaData; |
| 123 } | 123 } |
| 124 | 124 |
| 125 void SkDevice::lockPixels() { | 125 void SkBitmapDevice::lockPixels() { |
| 126 if (fBitmap.lockPixelsAreWritable()) { | 126 if (fBitmap.lockPixelsAreWritable()) { |
| 127 fBitmap.lockPixels(); | 127 fBitmap.lockPixels(); |
| 128 } | 128 } |
| 129 } | 129 } |
| 130 | 130 |
| 131 void SkDevice::unlockPixels() { | 131 void SkBitmapDevice::unlockPixels() { |
| 132 if (fBitmap.lockPixelsAreWritable()) { | 132 if (fBitmap.lockPixelsAreWritable()) { |
| 133 fBitmap.unlockPixels(); | 133 fBitmap.unlockPixels(); |
| 134 } | 134 } |
| 135 } | 135 } |
| 136 | 136 |
| 137 const SkBitmap& SkDevice::accessBitmap(bool changePixels) { | 137 const SkBitmap& SkBaseDevice::accessBitmap(bool changePixels) { |
| 138 const SkBitmap& bitmap = this->onAccessBitmap(&fBitmap); | 138 const SkBitmap& bitmap = this->onAccessBitmap(); |
| 139 if (changePixels) { | 139 if (changePixels) { |
| 140 bitmap.notifyPixelsChanged(); | 140 bitmap.notifyPixelsChanged(); |
| 141 } | 141 } |
| 142 return bitmap; | 142 return bitmap; |
| 143 } | 143 } |
| 144 | 144 |
| 145 void SkDevice::getGlobalBounds(SkIRect* bounds) const { | 145 void SkBitmapDevice::getGlobalBounds(SkIRect* bounds) const { |
| 146 if (bounds) { | 146 if (bounds) { |
| 147 bounds->setXYWH(fOrigin.x(), fOrigin.y(), | 147 const SkIPoint& origin = this->getOrigin(); |
| 148 bounds->setXYWH(origin.x(), origin.y(), |
| 148 fBitmap.width(), fBitmap.height()); | 149 fBitmap.width(), fBitmap.height()); |
| 149 } | 150 } |
| 150 } | 151 } |
| 151 | 152 |
| 152 void SkDevice::clear(SkColor color) { | 153 void SkBitmapDevice::clear(SkColor color) { |
| 153 fBitmap.eraseColor(color); | 154 fBitmap.eraseColor(color); |
| 154 } | 155 } |
| 155 | 156 |
| 156 const SkBitmap& SkDevice::onAccessBitmap(SkBitmap* bitmap) {return *bitmap;} | 157 const SkBitmap& SkBitmapDevice::onAccessBitmap() { |
| 157 | 158 return fBitmap; |
| 158 void SkDevice::setMatrixClip(const SkMatrix& matrix, const SkRegion& region, | |
| 159 const SkClipStack& clipStack) { | |
| 160 } | 159 } |
| 161 | 160 |
| 162 bool SkDevice::canHandleImageFilter(SkImageFilter*) { | 161 bool SkBitmapDevice::canHandleImageFilter(SkImageFilter*) { |
| 163 return false; | 162 return false; |
| 164 } | 163 } |
| 165 | 164 |
| 166 bool SkDevice::filterImage(SkImageFilter* filter, const SkBitmap& src, | 165 bool SkBitmapDevice::filterImage(SkImageFilter* filter, const SkBitmap& src, |
| 167 const SkMatrix& ctm, SkBitmap* result, | 166 const SkMatrix& ctm, SkBitmap* result, |
| 168 SkIPoint* offset) { | 167 SkIPoint* offset) { |
| 169 return false; | 168 return false; |
| 170 } | 169 } |
| 171 | 170 |
| 172 bool SkDevice::allowImageFilter(SkImageFilter*) { | 171 bool SkBitmapDevice::allowImageFilter(SkImageFilter*) { |
| 173 return true; | 172 return true; |
| 174 } | 173 } |
| 175 | 174 |
| 176 /////////////////////////////////////////////////////////////////////////////// | 175 /////////////////////////////////////////////////////////////////////////////// |
| 177 | 176 |
| 178 bool SkDevice::readPixels(SkBitmap* bitmap, int x, int y, | 177 bool SkBaseDevice::readPixels(SkBitmap* bitmap, int x, int y, |
| 179 SkCanvas::Config8888 config8888) { | 178 SkCanvas::Config8888 config8888) { |
| 180 if (SkBitmap::kARGB_8888_Config != bitmap->config() || | 179 if (SkBitmap::kARGB_8888_Config != bitmap->config() || |
| 181 NULL != bitmap->getTexture()) { | 180 NULL != bitmap->getTexture()) { |
| 182 return false; | 181 return false; |
| 183 } | 182 } |
| 184 | 183 |
| 185 const SkBitmap& src = this->accessBitmap(false); | 184 const SkBitmap& src = this->accessBitmap(false); |
| 186 | 185 |
| 187 SkIRect srcRect = SkIRect::MakeXYWH(x, y, bitmap->width(), | 186 SkIRect srcRect = SkIRect::MakeXYWH(x, y, bitmap->width(), |
| 188 bitmap->height()); | 187 bitmap->height()); |
| 189 SkIRect devbounds = SkIRect::MakeWH(src.width(), src.height()); | 188 SkIRect devbounds = SkIRect::MakeWH(src.width(), src.height()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 213 srcRect.fLeft, | 212 srcRect.fLeft, |
| 214 srcRect.fTop, | 213 srcRect.fTop, |
| 215 config8888); | 214 config8888); |
| 216 if (result && bmp == &tmp) { | 215 if (result && bmp == &tmp) { |
| 217 tmp.swap(*bitmap); | 216 tmp.swap(*bitmap); |
| 218 } | 217 } |
| 219 return result; | 218 return result; |
| 220 } | 219 } |
| 221 | 220 |
| 222 #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A) | 221 #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A) |
| 223 const SkCanvas::Config8888 SkDevice::kPMColorAlias = | 222 const SkCanvas::Config8888 SkBaseDevice::kPMColorAlias = |
| 224 SkCanvas::kBGRA_Premul_Config8888; | 223 SkCanvas::kBGRA_Premul_Config8888; |
| 225 #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A) | 224 #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A) |
| 226 const SkCanvas::Config8888 SkDevice::kPMColorAlias = | 225 const SkCanvas::Config8888 SkBaseDevice::kPMColorAlias = |
| 227 SkCanvas::kRGBA_Premul_Config8888; | 226 SkCanvas::kRGBA_Premul_Config8888; |
| 228 #else | 227 #else |
| 229 const SkCanvas::Config8888 SkDevice::kPMColorAlias = | 228 const SkCanvas::Config8888 SkBaseDevice::kPMColorAlias = |
| 230 (SkCanvas::Config8888) -1; | 229 (SkCanvas::Config8888) -1; |
| 231 #endif | 230 #endif |
| 232 | 231 |
| 233 #include <SkConfig8888.h> | 232 #include <SkConfig8888.h> |
| 234 | 233 |
| 235 bool SkDevice::onReadPixels(const SkBitmap& bitmap, | 234 bool SkBitmapDevice::onReadPixels(const SkBitmap& bitmap, |
| 236 int x, int y, | 235 int x, int y, |
| 237 SkCanvas::Config8888 config8888) { | 236 SkCanvas::Config8888 config8888) { |
| 238 SkASSERT(SkBitmap::kARGB_8888_Config == bitmap.config()); | 237 SkASSERT(SkBitmap::kARGB_8888_Config == bitmap.config()); |
| 239 SkASSERT(!bitmap.isNull()); | 238 SkASSERT(!bitmap.isNull()); |
| 240 SkASSERT(SkIRect::MakeWH(this->width(), this->height()).contains(SkIRect::Ma
keXYWH(x, y, bitmap.width(), bitmap.height()))); | 239 SkASSERT(SkIRect::MakeWH(this->width(), this->height()).contains(SkIRect::Ma
keXYWH(x, y, bitmap.width(), bitmap.height()))); |
| 241 | 240 |
| 242 SkIRect srcRect = SkIRect::MakeXYWH(x, y, bitmap.width(), | 241 SkIRect srcRect = SkIRect::MakeXYWH(x, y, bitmap.width(), |
| 243 bitmap.height()); | 242 bitmap.height()); |
| 244 const SkBitmap& src = this->accessBitmap(false); | 243 const SkBitmap& src = this->accessBitmap(false); |
| 245 | 244 |
| 246 SkBitmap subset; | 245 SkBitmap subset; |
| 247 if (!src.extractSubset(&subset, srcRect)) { | 246 if (!src.extractSubset(&subset, srcRect)) { |
| 248 return false; | 247 return false; |
| 249 } | 248 } |
| 250 if (SkBitmap::kARGB_8888_Config != subset.config()) { | 249 if (SkBitmap::kARGB_8888_Config != subset.config()) { |
| 251 // It'd be preferable to do this directly to bitmap. | 250 // It'd be preferable to do this directly to bitmap. |
| 252 subset.copyTo(&subset, SkBitmap::kARGB_8888_Config); | 251 subset.copyTo(&subset, SkBitmap::kARGB_8888_Config); |
| 253 } | 252 } |
| 254 SkAutoLockPixels alp(bitmap); | 253 SkAutoLockPixels alp(bitmap); |
| 255 uint32_t* bmpPixels = reinterpret_cast<uint32_t*>(bitmap.getPixels()); | 254 uint32_t* bmpPixels = reinterpret_cast<uint32_t*>(bitmap.getPixels()); |
| 256 SkCopyBitmapToConfig8888(bmpPixels, bitmap.rowBytes(), config8888, subset); | 255 SkCopyBitmapToConfig8888(bmpPixels, bitmap.rowBytes(), config8888, subset); |
| 257 return true; | 256 return true; |
| 258 } | 257 } |
| 259 | 258 |
| 260 void SkDevice::writePixels(const SkBitmap& bitmap, | 259 void SkBitmapDevice::writePixels(const SkBitmap& bitmap, |
| 261 int x, int y, | 260 int x, int y, |
| 262 SkCanvas::Config8888 config8888) { | 261 SkCanvas::Config8888 config8888) { |
| 263 if (bitmap.isNull() || bitmap.getTexture()) { | 262 if (bitmap.isNull() || bitmap.getTexture()) { |
| 264 return; | 263 return; |
| 265 } | 264 } |
| 266 const SkBitmap* sprite = &bitmap; | 265 const SkBitmap* sprite = &bitmap; |
| 267 // check whether we have to handle a config8888 that doesn't match SkPMColor | 266 // check whether we have to handle a config8888 that doesn't match SkPMColor |
| 268 if (SkBitmap::kARGB_8888_Config == bitmap.config() && | 267 if (SkBitmap::kARGB_8888_Config == bitmap.config() && |
| 269 SkCanvas::kNative_Premul_Config8888 != config8888 && | 268 SkCanvas::kNative_Premul_Config8888 != config8888 && |
| 270 kPMColorAlias != config8888) { | 269 kPMColorAlias != config8888) { |
| 271 | 270 |
| 272 // We're going to have to convert from a config8888 to the native config | 271 // We're going to have to convert from a config8888 to the native config |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 SkDraw draw; | 320 SkDraw draw; |
| 322 draw.fRC = &clip; | 321 draw.fRC = &clip; |
| 323 draw.fClip = &clip.bwRgn(); | 322 draw.fClip = &clip.bwRgn(); |
| 324 draw.fBitmap = &fBitmap; // canvas should have already called accessBitmap | 323 draw.fBitmap = &fBitmap; // canvas should have already called accessBitmap |
| 325 draw.fMatrix = &SkMatrix::I(); | 324 draw.fMatrix = &SkMatrix::I(); |
| 326 this->drawSprite(draw, *sprite, x, y, paint); | 325 this->drawSprite(draw, *sprite, x, y, paint); |
| 327 } | 326 } |
| 328 | 327 |
| 329 /////////////////////////////////////////////////////////////////////////////// | 328 /////////////////////////////////////////////////////////////////////////////// |
| 330 | 329 |
| 331 void SkDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { | 330 void SkBitmapDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { |
| 332 draw.drawPaint(paint); | 331 draw.drawPaint(paint); |
| 333 } | 332 } |
| 334 | 333 |
| 335 void SkDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, size_t c
ount, | 334 void SkBitmapDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, si
ze_t count, |
| 336 const SkPoint pts[], const SkPaint& paint) { | 335 const SkPoint pts[], const SkPaint& paint) { |
| 337 CHECK_FOR_NODRAW_ANNOTATION(paint); | 336 CHECK_FOR_NODRAW_ANNOTATION(paint); |
| 338 draw.drawPoints(mode, count, pts, paint); | 337 draw.drawPoints(mode, count, pts, paint); |
| 339 } | 338 } |
| 340 | 339 |
| 341 void SkDevice::drawRect(const SkDraw& draw, const SkRect& r, const SkPaint& pain
t) { | 340 void SkBitmapDevice::drawRect(const SkDraw& draw, const SkRect& r, const SkPaint
& paint) { |
| 342 CHECK_FOR_NODRAW_ANNOTATION(paint); | 341 CHECK_FOR_NODRAW_ANNOTATION(paint); |
| 343 draw.drawRect(r, paint); | 342 draw.drawRect(r, paint); |
| 344 } | 343 } |
| 345 | 344 |
| 346 void SkDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPaint& p
aint) { | 345 void SkBitmapDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPa
int& paint) { |
| 347 CHECK_FOR_NODRAW_ANNOTATION(paint); | 346 CHECK_FOR_NODRAW_ANNOTATION(paint); |
| 348 | 347 |
| 349 SkPath path; | 348 SkPath path; |
| 350 path.addOval(oval); | 349 path.addOval(oval); |
| 351 // call the VIRTUAL version, so any subclasses who do handle drawPath aren't | 350 // call the VIRTUAL version, so any subclasses who do handle drawPath aren't |
| 352 // required to override drawOval. | 351 // required to override drawOval. |
| 353 this->drawPath(draw, path, paint, NULL, true); | 352 this->drawPath(draw, path, paint, NULL, true); |
| 354 } | 353 } |
| 355 | 354 |
| 356 void SkDevice::drawRRect(const SkDraw& draw, const SkRRect& rrect, const SkPaint
& paint) { | 355 void SkBitmapDevice::drawRRect(const SkDraw& draw, const SkRRect& rrect, const S
kPaint& paint) { |
| 357 CHECK_FOR_NODRAW_ANNOTATION(paint); | 356 CHECK_FOR_NODRAW_ANNOTATION(paint); |
| 358 | 357 |
| 359 SkPath path; | 358 SkPath path; |
| 360 path.addRRect(rrect); | 359 path.addRRect(rrect); |
| 361 // call the VIRTUAL version, so any subclasses who do handle drawPath aren't | 360 // call the VIRTUAL version, so any subclasses who do handle drawPath aren't |
| 362 // required to override drawRRect. | 361 // required to override drawRRect. |
| 363 this->drawPath(draw, path, paint, NULL, true); | 362 this->drawPath(draw, path, paint, NULL, true); |
| 364 } | 363 } |
| 365 | 364 |
| 366 void SkDevice::drawPath(const SkDraw& draw, const SkPath& path, | 365 void SkBitmapDevice::drawPath(const SkDraw& draw, const SkPath& path, |
| 367 const SkPaint& paint, const SkMatrix* prePathMatrix, | 366 const SkPaint& paint, const SkMatrix* prePathMatri
x, |
| 368 bool pathIsMutable) { | 367 bool pathIsMutable) { |
| 369 CHECK_FOR_NODRAW_ANNOTATION(paint); | 368 CHECK_FOR_NODRAW_ANNOTATION(paint); |
| 370 draw.drawPath(path, paint, prePathMatrix, pathIsMutable); | 369 draw.drawPath(path, paint, prePathMatrix, pathIsMutable); |
| 371 } | 370 } |
| 372 | 371 |
| 373 void SkDevice::drawBitmap(const SkDraw& draw, const SkBitmap& bitmap, | 372 void SkBitmapDevice::drawBitmap(const SkDraw& draw, const SkBitmap& bitmap, |
| 374 const SkMatrix& matrix, const SkPaint& paint) { | 373 const SkMatrix& matrix, const SkPaint& paint) { |
| 375 draw.drawBitmap(bitmap, matrix, paint); | 374 draw.drawBitmap(bitmap, matrix, paint); |
| 376 } | 375 } |
| 377 | 376 |
| 378 void SkDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap, | 377 void SkBitmapDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap, |
| 379 const SkRect* src, const SkRect& dst, | 378 const SkRect* src, const SkRect& dst, |
| 380 const SkPaint& paint, | 379 const SkPaint& paint, |
| 381 SkCanvas::DrawBitmapRectFlags flags) { | 380 SkCanvas::DrawBitmapRectFlags flags) { |
| 382 SkMatrix matrix; | 381 SkMatrix matrix; |
| 383 SkRect bitmapBounds, tmpSrc, tmpDst; | 382 SkRect bitmapBounds, tmpSrc, tmpDst; |
| 384 SkBitmap tmpBitmap; | 383 SkBitmap tmpBitmap; |
| 385 | 384 |
| 386 bitmapBounds.isetWH(bitmap.width(), bitmap.height()); | 385 bitmapBounds.isetWH(bitmap.width(), bitmap.height()); |
| 387 | 386 |
| 388 // Compute matrix from the two rectangles | 387 // Compute matrix from the two rectangles |
| 389 if (src) { | 388 if (src) { |
| 390 tmpSrc = *src; | 389 tmpSrc = *src; |
| 391 } else { | 390 } else { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 | 454 |
| 456 SkPaint paintWithShader(paint); | 455 SkPaint paintWithShader(paint); |
| 457 paintWithShader.setStyle(SkPaint::kFill_Style); | 456 paintWithShader.setStyle(SkPaint::kFill_Style); |
| 458 paintWithShader.setShader(s)->unref(); | 457 paintWithShader.setShader(s)->unref(); |
| 459 | 458 |
| 460 // Call ourself, in case the subclass wanted to share this setup code | 459 // Call ourself, in case the subclass wanted to share this setup code |
| 461 // but handle the drawRect code themselves. | 460 // but handle the drawRect code themselves. |
| 462 this->drawRect(draw, *dstPtr, paintWithShader); | 461 this->drawRect(draw, *dstPtr, paintWithShader); |
| 463 } | 462 } |
| 464 | 463 |
| 465 void SkDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, | 464 void SkBitmapDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, |
| 466 int x, int y, const SkPaint& paint) { | 465 int x, int y, const SkPaint& paint) { |
| 467 draw.drawSprite(bitmap, x, y, paint); | 466 draw.drawSprite(bitmap, x, y, paint); |
| 468 } | 467 } |
| 469 | 468 |
| 470 void SkDevice::drawText(const SkDraw& draw, const void* text, size_t len, | 469 void SkBitmapDevice::drawText(const SkDraw& draw, const void* text, size_t len, |
| 471 SkScalar x, SkScalar y, const SkPaint& paint) { | 470 SkScalar x, SkScalar y, const SkPaint& paint) { |
| 472 draw.drawText((const char*)text, len, x, y, paint); | 471 draw.drawText((const char*)text, len, x, y, paint); |
| 473 } | 472 } |
| 474 | 473 |
| 475 void SkDevice::drawPosText(const SkDraw& draw, const void* text, size_t len, | 474 void SkBitmapDevice::drawPosText(const SkDraw& draw, const void* text, size_t le
n, |
| 476 const SkScalar xpos[], SkScalar y, | 475 const SkScalar xpos[], SkScalar y, |
| 477 int scalarsPerPos, const SkPaint& paint) { | 476 int scalarsPerPos, const SkPaint& paint) { |
| 478 draw.drawPosText((const char*)text, len, xpos, y, scalarsPerPos, paint); | 477 draw.drawPosText((const char*)text, len, xpos, y, scalarsPerPos, paint); |
| 479 } | 478 } |
| 480 | 479 |
| 481 void SkDevice::drawTextOnPath(const SkDraw& draw, const void* text, | 480 void SkBitmapDevice::drawTextOnPath(const SkDraw& draw, const void* text, |
| 482 size_t len, const SkPath& path, | 481 size_t len, const SkPath& path, |
| 483 const SkMatrix* matrix, | 482 const SkMatrix* matrix, |
| 484 const SkPaint& paint) { | 483 const SkPaint& paint) { |
| 485 draw.drawTextOnPath((const char*)text, len, path, matrix, paint); | 484 draw.drawTextOnPath((const char*)text, len, path, matrix, paint); |
| 486 } | 485 } |
| 487 | 486 |
| 488 #ifdef SK_BUILD_FOR_ANDROID | 487 #ifdef SK_BUILD_FOR_ANDROID |
| 489 void SkDevice::drawPosTextOnPath(const SkDraw& draw, const void* text, size_t le
n, | 488 void SkBitmapDevice::drawPosTextOnPath(const SkDraw& draw, const void* text, siz
e_t len, |
| 490 const SkPoint pos[], const SkPaint& paint, | 489 const SkPoint pos[], const SkPaint& paint
, |
| 491 const SkPath& path, const SkMatrix* matrix)
{ | 490 const SkPath& path, const SkMatrix* matri
x) { |
| 492 draw.drawPosTextOnPath((const char*)text, len, pos, paint, path, matrix); | 491 draw.drawPosTextOnPath((const char*)text, len, pos, paint, path, matrix); |
| 493 } | 492 } |
| 494 #endif | 493 #endif |
| 495 | 494 |
| 496 void SkDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, | 495 void SkBitmapDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode
, |
| 497 int vertexCount, | 496 int vertexCount, |
| 498 const SkPoint verts[], const SkPoint textures[], | 497 const SkPoint verts[], const SkPoint textures[
], |
| 499 const SkColor colors[], SkXfermode* xmode, | 498 const SkColor colors[], SkXfermode* xmode, |
| 500 const uint16_t indices[], int indexCount, | 499 const uint16_t indices[], int indexCount, |
| 501 const SkPaint& paint) { | 500 const SkPaint& paint) { |
| 502 draw.drawVertices(vmode, vertexCount, verts, textures, colors, xmode, | 501 draw.drawVertices(vmode, vertexCount, verts, textures, colors, xmode, |
| 503 indices, indexCount, paint); | 502 indices, indexCount, paint); |
| 504 } | 503 } |
| 505 | 504 |
| 506 void SkDevice::drawDevice(const SkDraw& draw, SkDevice* device, | 505 void SkBitmapDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device, |
| 507 int x, int y, const SkPaint& paint) { | 506 int x, int y, const SkPaint& paint) { |
| 508 const SkBitmap& src = device->accessBitmap(false); | 507 const SkBitmap& src = device->accessBitmap(false); |
| 509 draw.drawSprite(src, x, y, paint); | 508 draw.drawSprite(src, x, y, paint); |
| 510 } | 509 } |
| 511 | 510 |
| 512 /////////////////////////////////////////////////////////////////////////////// | 511 /////////////////////////////////////////////////////////////////////////////// |
| 513 | 512 |
| 514 bool SkDevice::filterTextFlags(const SkPaint& paint, TextFlags* flags) { | 513 bool SkBitmapDevice::filterTextFlags(const SkPaint& paint, TextFlags* flags) { |
| 515 if (!paint.isLCDRenderText() || !paint.isAntiAlias()) { | 514 if (!paint.isLCDRenderText() || !paint.isAntiAlias()) { |
| 516 // we're cool with the paint as is | 515 // we're cool with the paint as is |
| 517 return false; | 516 return false; |
| 518 } | 517 } |
| 519 | 518 |
| 520 if (SkBitmap::kARGB_8888_Config != fBitmap.config() || | 519 if (SkBitmap::kARGB_8888_Config != fBitmap.config() || |
| 521 paint.getRasterizer() || | 520 paint.getRasterizer() || |
| 522 paint.getPathEffect() || | 521 paint.getPathEffect() || |
| 523 paint.isFakeBoldText() || | 522 paint.isFakeBoldText() || |
| 524 paint.getStyle() != SkPaint::kFill_Style || | 523 paint.getStyle() != SkPaint::kFill_Style || |
| 525 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) { | 524 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) { |
| 526 // turn off lcd | 525 // turn off lcd |
| 527 flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag; | 526 flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag; |
| 528 flags->fHinting = paint.getHinting(); | 527 flags->fHinting = paint.getHinting(); |
| 529 return true; | 528 return true; |
| 530 } | 529 } |
| 531 // we're cool with the paint as is | 530 // we're cool with the paint as is |
| 532 return false; | 531 return false; |
| 533 } | 532 } |
| OLD | NEW |