| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkBitmapDevice.h" | 8 #include "SkBitmapDevice.h" |
| 9 #include "SkConfig8888.h" | 9 #include "SkConfig8888.h" |
| 10 #include "SkDraw.h" | 10 #include "SkDraw.h" |
| 11 #include "SkRasterClip.h" | 11 #include "SkRasterClip.h" |
| 12 #include "SkShader.h" | 12 #include "SkShader.h" |
| 13 | 13 |
| 14 #define CHECK_FOR_ANNOTATION(paint) \ | 14 #define CHECK_FOR_ANNOTATION(paint) \ |
| 15 do { if (paint.getAnnotation()) { return; } } while (0) | 15 do { if (paint.getAnnotation()) { return; } } while (0) |
| 16 | 16 |
| 17 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap) | 17 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap) |
| 18 : fBitmap(bitmap) { | 18 : fBitmap(bitmap) { |
| 19 SkASSERT(SkBitmap::kARGB_4444_Config != bitmap.config()); | 19 SkASSERT(SkBitmap::kARGB_4444_Config != bitmap.config()); |
| 20 } | 20 } |
| 21 | 21 |
| 22 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkDeviceProperties&
deviceProperties) | 22 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkDeviceProperties&
deviceProperties) |
| 23 : SkBaseDevice(deviceProperties) | 23 : SkBaseDevice(deviceProperties) |
| 24 , fBitmap(bitmap) { | 24 , fBitmap(bitmap) { |
| 25 } | 25 } |
| 26 | 26 |
| 27 SkBitmapDevice::SkBitmapDevice(SkBitmap::Config config, int width, int height, b
ool isOpaque) { | 27 void SkBitmapDevice::init(SkBitmap::Config config, int width, int height, bool i
sOpaque) { |
| 28 fBitmap.setConfig(config, width, height, 0, isOpaque ? | 28 fBitmap.setConfig(config, width, height, 0, isOpaque ? |
| 29 kOpaque_SkAlphaType : kPremul_SkAlphaType); | 29 kOpaque_SkAlphaType : kPremul_SkAlphaType); |
| 30 if (!fBitmap.allocPixels()) { | 30 |
| 31 fBitmap.setConfig(config, 0, 0, 0, isOpaque ? | 31 if (SkBitmap::kNo_Config != config) { |
| 32 kOpaque_SkAlphaType : kPremul_SkAlphaType); | 32 if (!fBitmap.allocPixels()) { |
| 33 // indicate failure by zeroing our bitmap |
| 34 fBitmap.setConfig(config, 0, 0, 0, isOpaque ? |
| 35 kOpaque_SkAlphaType : kPremul_SkAlphaType); |
| 36 } else if (!isOpaque) { |
| 37 fBitmap.eraseColor(SK_ColorTRANSPARENT); |
| 38 } |
| 33 } | 39 } |
| 34 if (!isOpaque) { | 40 } |
| 35 fBitmap.eraseColor(SK_ColorTRANSPARENT); | 41 |
| 36 } | 42 SkBitmapDevice::SkBitmapDevice(SkBitmap::Config config, int width, int height, b
ool isOpaque) { |
| 43 this->init(config, width, height, isOpaque); |
| 37 } | 44 } |
| 38 | 45 |
| 39 SkBitmapDevice::SkBitmapDevice(SkBitmap::Config config, int width, int height, b
ool isOpaque, | 46 SkBitmapDevice::SkBitmapDevice(SkBitmap::Config config, int width, int height, b
ool isOpaque, |
| 40 const SkDeviceProperties& deviceProperties) | 47 const SkDeviceProperties& deviceProperties) |
| 41 : SkBaseDevice(deviceProperties) { | 48 : SkBaseDevice(deviceProperties) |
| 42 | 49 { |
| 43 fBitmap.setConfig(config, width, height, 0, isOpaque ? | 50 this->init(config, width, height, isOpaque); |
| 44 kOpaque_SkAlphaType : kPremul_SkAlphaType); | |
| 45 if (!fBitmap.allocPixels()) { | |
| 46 fBitmap.setConfig(config, 0, 0, 0, isOpaque ? | |
| 47 kOpaque_SkAlphaType : kPremul_SkAlphaType); | |
| 48 } | |
| 49 if (!isOpaque) { | |
| 50 fBitmap.eraseColor(SK_ColorTRANSPARENT); | |
| 51 } | |
| 52 } | 51 } |
| 53 | 52 |
| 54 SkBitmapDevice::~SkBitmapDevice() { | 53 SkBitmapDevice::~SkBitmapDevice() { |
| 55 } | 54 } |
| 56 | 55 |
| 57 void SkBitmapDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) { | 56 void SkBitmapDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) { |
| 58 SkASSERT(bm.width() == fBitmap.width()); | 57 SkASSERT(bm.width() == fBitmap.width()); |
| 59 SkASSERT(bm.height() == fBitmap.height()); | 58 SkASSERT(bm.height() == fBitmap.height()); |
| 60 fBitmap = bm; // intent is to use bm's pixelRef (and rowbytes/config) | 59 fBitmap = bm; // intent is to use bm's pixelRef (and rowbytes/config) |
| 61 fBitmap.lockPixels(); | 60 fBitmap.lockPixels(); |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 paint.getStyle() != SkPaint::kFill_Style || | 398 paint.getStyle() != SkPaint::kFill_Style || |
| 400 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) { | 399 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) { |
| 401 // turn off lcd | 400 // turn off lcd |
| 402 flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag; | 401 flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag; |
| 403 flags->fHinting = paint.getHinting(); | 402 flags->fHinting = paint.getHinting(); |
| 404 return true; | 403 return true; |
| 405 } | 404 } |
| 406 // we're cool with the paint as is | 405 // we're cool with the paint as is |
| 407 return false; | 406 return false; |
| 408 } | 407 } |
| OLD | NEW |