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 void SkBitmapDevice::init(SkBitmap::Config config, int width, int height, bool i
sOpaque) { | 27 SkBitmapDevice::SkBitmapDevice(SkBitmap::Config config, int width, int height, b
ool isOpaque) { |
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 | 30 if (!fBitmap.allocPixels()) { |
31 if (SkBitmap::kNo_Config != config) { | 31 fBitmap.setConfig(config, 0, 0, 0, isOpaque ? |
32 if (!fBitmap.allocPixels()) { | 32 kOpaque_SkAlphaType : kPremul_SkAlphaType); |
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 } | |
39 } | 33 } |
40 } | 34 if (!isOpaque) { |
41 | 35 fBitmap.eraseColor(SK_ColorTRANSPARENT); |
42 SkBitmapDevice::SkBitmapDevice(SkBitmap::Config config, int width, int height, b
ool isOpaque) { | 36 } |
43 this->init(config, width, height, isOpaque); | |
44 } | 37 } |
45 | 38 |
46 SkBitmapDevice::SkBitmapDevice(SkBitmap::Config config, int width, int height, b
ool isOpaque, | 39 SkBitmapDevice::SkBitmapDevice(SkBitmap::Config config, int width, int height, b
ool isOpaque, |
47 const SkDeviceProperties& deviceProperties) | 40 const SkDeviceProperties& deviceProperties) |
48 : SkBaseDevice(deviceProperties) | 41 : SkBaseDevice(deviceProperties) { |
49 { | 42 |
50 this->init(config, width, height, isOpaque); | 43 fBitmap.setConfig(config, width, height, 0, 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 } |
51 } | 52 } |
52 | 53 |
53 SkBitmapDevice::~SkBitmapDevice() { | 54 SkBitmapDevice::~SkBitmapDevice() { |
54 } | 55 } |
55 | 56 |
56 void SkBitmapDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) { | 57 void SkBitmapDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) { |
57 SkASSERT(bm.width() == fBitmap.width()); | 58 SkASSERT(bm.width() == fBitmap.width()); |
58 SkASSERT(bm.height() == fBitmap.height()); | 59 SkASSERT(bm.height() == fBitmap.height()); |
59 fBitmap = bm; // intent is to use bm's pixelRef (and rowbytes/config) | 60 fBitmap = bm; // intent is to use bm's pixelRef (and rowbytes/config) |
60 fBitmap.lockPixels(); | 61 fBitmap.lockPixels(); |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 paint.getStyle() != SkPaint::kFill_Style || | 399 paint.getStyle() != SkPaint::kFill_Style || |
399 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) { | 400 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) { |
400 // turn off lcd | 401 // turn off lcd |
401 flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag; | 402 flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag; |
402 flags->fHinting = paint.getHinting(); | 403 flags->fHinting = paint.getHinting(); |
403 return true; | 404 return true; |
404 } | 405 } |
405 // we're cool with the paint as is | 406 // we're cool with the paint as is |
406 return false; | 407 return false; |
407 } | 408 } |
OLD | NEW |