| 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 "SkDevice.h" | 8 #include "SkDevice.h" |
| 9 #include "SkDeviceProperties.h" | 9 #include "SkDeviceProperties.h" |
| 10 #include "SkDraw.h" | 10 #include "SkDraw.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 do { if (paint.isNoDrawAnnotation()) { return; } } while (0) | 23 do { if (paint.isNoDrawAnnotation()) { return; } } while (0) |
| 24 | 24 |
| 25 /////////////////////////////////////////////////////////////////////////////// | 25 /////////////////////////////////////////////////////////////////////////////// |
| 26 | 26 |
| 27 SkDevice::SkDevice(const SkBitmap& bitmap) | 27 SkDevice::SkDevice(const SkBitmap& bitmap) |
| 28 : fBitmap(bitmap), fLeakyProperties(SkDeviceProperties::MakeDefault()) | 28 : fBitmap(bitmap), fLeakyProperties(SkDeviceProperties::MakeDefault()) |
| 29 #ifdef SK_DEBUG | 29 #ifdef SK_DEBUG |
| 30 , fAttachedToCanvas(false) | 30 , fAttachedToCanvas(false) |
| 31 #endif | 31 #endif |
| 32 { | 32 { |
| 33 SkASSERT(bitmap.config() != SkBitmap::kIndex8_Config); |
| 34 SkASSERT(bitmap.premultiplied()); |
| 33 fOrigin.setZero(); | 35 fOrigin.setZero(); |
| 34 fMetaData = NULL; | 36 fMetaData = NULL; |
| 35 } | 37 } |
| 36 | 38 |
| 37 SkDevice::SkDevice(const SkBitmap& bitmap, const SkDeviceProperties& devicePrope
rties) | 39 SkDevice::SkDevice(const SkBitmap& bitmap, const SkDeviceProperties& devicePrope
rties) |
| 38 : fBitmap(bitmap), fLeakyProperties(deviceProperties) | 40 : fBitmap(bitmap), fLeakyProperties(deviceProperties) |
| 39 #ifdef SK_DEBUG | 41 #ifdef SK_DEBUG |
| 40 , fAttachedToCanvas(false) | 42 , fAttachedToCanvas(false) |
| 41 #endif | 43 #endif |
| 42 { | 44 { |
| 45 SkASSERT(bitmap.config() != SkBitmap::kIndex8_Config); |
| 46 SkASSERT(bitmap.premultiplied()); |
| 43 fOrigin.setZero(); | 47 fOrigin.setZero(); |
| 44 fMetaData = NULL; | 48 fMetaData = NULL; |
| 45 } | 49 } |
| 46 | 50 |
| 47 SkDevice::SkDevice(SkBitmap::Config config, int width, int height, bool isOpaque
) | 51 SkDevice::SkDevice(SkBitmap::Config config, int width, int height, bool isOpaque
) |
| 48 : fLeakyProperties(SkDeviceProperties::MakeDefault()) | 52 : fLeakyProperties(SkDeviceProperties::MakeDefault()) |
| 49 #ifdef SK_DEBUG | 53 #ifdef SK_DEBUG |
| 50 , fAttachedToCanvas(false) | 54 , fAttachedToCanvas(false) |
| 51 #endif | 55 #endif |
| 52 { | 56 { |
| 53 fOrigin.setZero(); | 57 fOrigin.setZero(); |
| 54 fMetaData = NULL; | 58 fMetaData = NULL; |
| 55 | 59 |
| 60 if (SkBitmap::kIndex8_Config == config) { |
| 61 config = SkBitmap::kARGB_8888_Config; |
| 62 } |
| 56 fBitmap.setConfig(config, width, height); | 63 fBitmap.setConfig(config, width, height); |
| 57 fBitmap.allocPixels(); | 64 fBitmap.allocPixels(); |
| 58 fBitmap.setIsOpaque(isOpaque); | 65 fBitmap.setIsOpaque(isOpaque); |
| 59 if (!isOpaque) { | 66 if (!isOpaque) { |
| 60 fBitmap.eraseColor(SK_ColorTRANSPARENT); | 67 fBitmap.eraseColor(SK_ColorTRANSPARENT); |
| 61 } | 68 } |
| 62 } | 69 } |
| 63 | 70 |
| 64 SkDevice::SkDevice(SkBitmap::Config config, int width, int height, bool isOpaque
, | 71 SkDevice::SkDevice(SkBitmap::Config config, int width, int height, bool isOpaque
, |
| 65 const SkDeviceProperties& deviceProperties) | 72 const SkDeviceProperties& deviceProperties) |
| 66 : fLeakyProperties(deviceProperties) | 73 : fLeakyProperties(deviceProperties) |
| 67 #ifdef SK_DEBUG | 74 #ifdef SK_DEBUG |
| 68 , fAttachedToCanvas(false) | 75 , fAttachedToCanvas(false) |
| 69 #endif | 76 #endif |
| 70 { | 77 { |
| 71 fOrigin.setZero(); | 78 fOrigin.setZero(); |
| 72 fMetaData = NULL; | 79 fMetaData = NULL; |
| 73 | 80 |
| 81 if (SkBitmap::kIndex8_Config == config) { |
| 82 config = SkBitmap::kARGB_8888_Config; |
| 83 } |
| 74 fBitmap.setConfig(config, width, height); | 84 fBitmap.setConfig(config, width, height); |
| 75 fBitmap.allocPixels(); | 85 fBitmap.allocPixels(); |
| 76 fBitmap.setIsOpaque(isOpaque); | 86 fBitmap.setIsOpaque(isOpaque); |
| 77 if (!isOpaque) { | 87 if (!isOpaque) { |
| 78 fBitmap.eraseColor(SK_ColorTRANSPARENT); | 88 fBitmap.eraseColor(SK_ColorTRANSPARENT); |
| 79 } | 89 } |
| 80 } | 90 } |
| 81 | 91 |
| 82 SkDevice::~SkDevice() { | 92 SkDevice::~SkDevice() { |
| 83 delete fMetaData; | 93 delete fMetaData; |
| 84 } | 94 } |
| 85 | 95 |
| 86 void SkDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) { | 96 void SkDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) { |
| 97 SkASSERT(bm.config() != SkBitmap::kIndex8_Config); |
| 98 SkASSERT(bm.premultiplied()); |
| 87 SkASSERT(bm.width() == fBitmap.width()); | 99 SkASSERT(bm.width() == fBitmap.width()); |
| 88 SkASSERT(bm.height() == fBitmap.height()); | 100 SkASSERT(bm.height() == fBitmap.height()); |
| 89 fBitmap = bm; // intent is to use bm's pixelRef (and rowbytes/config) | 101 fBitmap = bm; // intent is to use bm's pixelRef (and rowbytes/config) |
| 90 fBitmap.lockPixels(); | 102 fBitmap.lockPixels(); |
| 91 } | 103 } |
| 92 | 104 |
| 93 SkDevice* SkDevice::createCompatibleDevice(SkBitmap::Config config, | 105 SkDevice* SkDevice::createCompatibleDevice(SkBitmap::Config config, |
| 94 int width, int height, | 106 int width, int height, |
| 95 bool isOpaque) { | 107 bool isOpaque) { |
| 96 return this->onCreateCompatibleDevice(config, width, height, | 108 return this->onCreateCompatibleDevice(config, width, height, |
| 97 isOpaque, kGeneral_Usage); | 109 isOpaque, kGeneral_Usage); |
| 98 } | 110 } |
| 99 | 111 |
| 100 SkDevice* SkDevice::createCompatibleDeviceForSaveLayer(SkBitmap::Config config, | 112 SkDevice* SkDevice::createCompatibleDeviceForSaveLayer(SkBitmap::Config config, |
| 101 int width, int height, | 113 int width, int height, |
| 102 bool isOpaque) { | 114 bool isOpaque) { |
| 103 return this->onCreateCompatibleDevice(config, width, height, | 115 return this->onCreateCompatibleDevice(config, width, height, |
| 104 isOpaque, kSaveLayer_Usage); | 116 isOpaque, kSaveLayer_Usage); |
| 105 } | 117 } |
| 106 | 118 |
| 107 SkDevice* SkDevice::onCreateCompatibleDevice(SkBitmap::Config config, | 119 SkDevice* SkDevice::onCreateCompatibleDevice(SkBitmap::Config config, |
| 108 int width, int height, | 120 int width, int height, |
| 109 bool isOpaque, | 121 bool isOpaque, |
| 110 Usage usage) { | 122 Usage usage) { |
| 123 if (SkBitmap::kIndex8_Config == config) { |
| 124 config = SkBitmap::kARGB_8888_Config; |
| 125 } |
| 111 return SkNEW_ARGS(SkDevice,(config, width, height, isOpaque, fLeakyPropertie
s)); | 126 return SkNEW_ARGS(SkDevice,(config, width, height, isOpaque, fLeakyPropertie
s)); |
| 112 } | 127 } |
| 113 | 128 |
| 114 SkMetaData& SkDevice::getMetaData() { | 129 SkMetaData& SkDevice::getMetaData() { |
| 115 // metadata users are rare, so we lazily allocate it. If that changes we | 130 // metadata users are rare, so we lazily allocate it. If that changes we |
| 116 // can decide to just make it a field in the device (rather than a ptr) | 131 // can decide to just make it a field in the device (rather than a ptr) |
| 117 if (NULL == fMetaData) { | 132 if (NULL == fMetaData) { |
| 118 fMetaData = new SkMetaData; | 133 fMetaData = new SkMetaData; |
| 119 } | 134 } |
| 120 return *fMetaData; | 135 return *fMetaData; |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 paint.getStyle() != SkPaint::kFill_Style || | 563 paint.getStyle() != SkPaint::kFill_Style || |
| 549 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) { | 564 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) { |
| 550 // turn off lcd | 565 // turn off lcd |
| 551 flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag; | 566 flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag; |
| 552 flags->fHinting = paint.getHinting(); | 567 flags->fHinting = paint.getHinting(); |
| 553 return true; | 568 return true; |
| 554 } | 569 } |
| 555 // we're cool with the paint as is | 570 // we're cool with the paint as is |
| 556 return false; | 571 return false; |
| 557 } | 572 } |
| OLD | NEW |