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" |
(...skipping 11 matching lines...) Expand all Loading... |
22 } | 22 } |
23 | 23 |
24 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkDeviceProperties&
deviceProperties) | 24 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkDeviceProperties&
deviceProperties) |
25 : SkBaseDevice(deviceProperties) | 25 : SkBaseDevice(deviceProperties) |
26 , fBitmap(bitmap) { | 26 , fBitmap(bitmap) { |
27 } | 27 } |
28 | 28 |
29 SkBitmapDevice::SkBitmapDevice(SkBitmap::Config config, int width, int height, b
ool isOpaque) { | 29 SkBitmapDevice::SkBitmapDevice(SkBitmap::Config config, int width, int height, b
ool isOpaque) { |
30 fBitmap.setConfig(config, width, height, 0, isOpaque ? | 30 fBitmap.setConfig(config, width, height, 0, isOpaque ? |
31 kOpaque_SkAlphaType : kPremul_SkAlphaType); | 31 kOpaque_SkAlphaType : kPremul_SkAlphaType); |
32 fBitmap.allocPixels(); | 32 if (!fBitmap.allocPixels()) { |
| 33 fBitmap.setConfig(config, 0, 0, 0, isOpaque ? |
| 34 kOpaque_SkAlphaType : kPremul_SkAlphaType); |
| 35 } |
33 if (!isOpaque) { | 36 if (!isOpaque) { |
34 fBitmap.eraseColor(SK_ColorTRANSPARENT); | 37 fBitmap.eraseColor(SK_ColorTRANSPARENT); |
35 } | 38 } |
36 } | 39 } |
37 | 40 |
38 SkBitmapDevice::SkBitmapDevice(SkBitmap::Config config, int width, int height, b
ool isOpaque, | 41 SkBitmapDevice::SkBitmapDevice(SkBitmap::Config config, int width, int height, b
ool isOpaque, |
39 const SkDeviceProperties& deviceProperties) | 42 const SkDeviceProperties& deviceProperties) |
40 : SkBaseDevice(deviceProperties) { | 43 : SkBaseDevice(deviceProperties) { |
41 | 44 |
42 fBitmap.setConfig(config, width, height, 0, isOpaque ? | 45 fBitmap.setConfig(config, width, height, 0, isOpaque ? |
43 kOpaque_SkAlphaType : kPremul_SkAlphaType); | 46 kOpaque_SkAlphaType : kPremul_SkAlphaType); |
44 fBitmap.allocPixels(); | 47 if (!fBitmap.allocPixels()) { |
| 48 fBitmap.setConfig(config, 0, 0, 0, isOpaque ? |
| 49 kOpaque_SkAlphaType : kPremul_SkAlphaType); |
| 50 } |
45 if (!isOpaque) { | 51 if (!isOpaque) { |
46 fBitmap.eraseColor(SK_ColorTRANSPARENT); | 52 fBitmap.eraseColor(SK_ColorTRANSPARENT); |
47 } | 53 } |
48 } | 54 } |
49 | 55 |
50 SkBitmapDevice::~SkBitmapDevice() { | 56 SkBitmapDevice::~SkBitmapDevice() { |
51 } | 57 } |
52 | 58 |
53 void SkBitmapDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) { | 59 void SkBitmapDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) { |
54 SkASSERT(bm.width() == fBitmap.width()); | 60 SkASSERT(bm.width() == fBitmap.width()); |
55 SkASSERT(bm.height() == fBitmap.height()); | 61 SkASSERT(bm.height() == fBitmap.height()); |
56 fBitmap = bm; // intent is to use bm's pixelRef (and rowbytes/config) | 62 fBitmap = bm; // intent is to use bm's pixelRef (and rowbytes/config) |
57 fBitmap.lockPixels(); | 63 fBitmap.lockPixels(); |
58 } | 64 } |
59 | 65 |
60 SkBaseDevice* SkBitmapDevice::onCreateCompatibleDevice(SkBitmap::Config config, | 66 SkBaseDevice* SkBitmapDevice::onCreateCompatibleDevice(SkBitmap::Config config, |
61 int width, int height, | 67 int width, int height, |
62 bool isOpaque, | 68 bool isOpaque, |
63 Usage usage) { | 69 Usage usage) { |
64 return SkNEW_ARGS(SkBitmapDevice,(config, width, height, isOpaque, | 70 SkBitmapDevice* device = SkNEW_ARGS(SkBitmapDevice,(config, width, height, |
65 this->getDeviceProperties())); | 71 isOpaque, this->getDeviceProperties())); |
| 72 // Check if allocation failed and delete device if it did fail |
| 73 if ((device->width() != width) || (device->height() != height)) { |
| 74 SkDELETE(device); |
| 75 device = NULL; |
| 76 } |
| 77 return device; |
66 } | 78 } |
67 | 79 |
68 void SkBitmapDevice::lockPixels() { | 80 void SkBitmapDevice::lockPixels() { |
69 if (fBitmap.lockPixelsAreWritable()) { | 81 if (fBitmap.lockPixelsAreWritable()) { |
70 fBitmap.lockPixels(); | 82 fBitmap.lockPixels(); |
71 } | 83 } |
72 } | 84 } |
73 | 85 |
74 void SkBitmapDevice::unlockPixels() { | 86 void SkBitmapDevice::unlockPixels() { |
75 if (fBitmap.lockPixelsAreWritable()) { | 87 if (fBitmap.lockPixelsAreWritable()) { |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 paint.getStyle() != SkPaint::kFill_Style || | 401 paint.getStyle() != SkPaint::kFill_Style || |
390 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) { | 402 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) { |
391 // turn off lcd | 403 // turn off lcd |
392 flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag; | 404 flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag; |
393 flags->fHinting = paint.getHinting(); | 405 flags->fHinting = paint.getHinting(); |
394 return true; | 406 return true; |
395 } | 407 } |
396 // we're cool with the paint as is | 408 // we're cool with the paint as is |
397 return false; | 409 return false; |
398 } | 410 } |
OLD | NEW |