aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkBitmapDevice.cpp
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-02-16 00:59:25 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-02-16 00:59:25 +0000
commit15a140599942f70e47380e3f700a825c7cece3b4 (patch)
tree58bd83fb723b2766d078c93eb947bedf055f391a /src/core/SkBitmapDevice.cpp
parenta3b532743dbb1d54a4c17a2574083ef93c949d50 (diff)
Change device factories to take SkImageInfo instead of SkBitmap::Config
patch from issue 167033002 BUG=skia: R=reed@google.com Author: reed@chromium.org Review URL: https://codereview.chromium.org/168653002 git-svn-id: http://skia.googlecode.com/svn/trunk@13463 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core/SkBitmapDevice.cpp')
-rw-r--r--src/core/SkBitmapDevice.cpp94
1 files changed, 77 insertions, 17 deletions
diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp
index 374bef98c1..0eff33cf7e 100644
--- a/src/core/SkBitmapDevice.cpp
+++ b/src/core/SkBitmapDevice.cpp
@@ -15,16 +15,60 @@
#define CHECK_FOR_ANNOTATION(paint) \
do { if (paint.getAnnotation()) { return; } } while (0)
-SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap)
- : fBitmap(bitmap) {
- SkASSERT(SkBitmap::kARGB_4444_Config != bitmap.config());
+static bool valid_for_bitmap_device(const SkImageInfo& info,
+ SkAlphaType* newAlphaType) {
+ if (info.width() < 0 || info.height() < 0) {
+ return false;
+ }
+
+ // TODO: can we stop supporting kUnknown in SkBitmkapDevice?
+ if (kUnknown_SkColorType == info.colorType()) {
+ if (newAlphaType) {
+ *newAlphaType = kIgnore_SkAlphaType;
+ }
+ return true;
+ }
+
+ switch (info.alphaType()) {
+ case kPremul_SkAlphaType:
+ case kOpaque_SkAlphaType:
+ break;
+ default:
+ return false;
+ }
+
+ SkAlphaType canonicalAlphaType = info.alphaType();
+
+ switch (info.colorType()) {
+ case kAlpha_8_SkColorType:
+ break;
+ case kRGB_565_SkColorType:
+ canonicalAlphaType = kOpaque_SkAlphaType;
+ break;
+ case kPMColor_SkColorType:
+ break;
+ default:
+ return false;
+ }
+
+ if (newAlphaType) {
+ *newAlphaType = canonicalAlphaType;
+ }
+ return true;
+}
+
+SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap) : fBitmap(bitmap) {
+ SkASSERT(valid_for_bitmap_device(bitmap.info(), NULL));
}
SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkDeviceProperties& deviceProperties)
: SkBaseDevice(deviceProperties)
- , fBitmap(bitmap) {
+ , fBitmap(bitmap)
+{
+ SkASSERT(valid_for_bitmap_device(bitmap.info(), NULL));
}
+#ifdef SK_SUPPORT_LEGACY_COMPATIBLEDEVICE_CONFIG
void SkBitmapDevice::init(SkBitmap::Config config, int width, int height, bool isOpaque) {
fBitmap.setConfig(config, width, height, 0, isOpaque ?
kOpaque_SkAlphaType : kPremul_SkAlphaType);
@@ -50,8 +94,34 @@ SkBitmapDevice::SkBitmapDevice(SkBitmap::Config config, int width, int height, b
{
this->init(config, width, height, isOpaque);
}
+#endif
+SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& origInfo,
+ const SkDeviceProperties* props) {
+ SkImageInfo info = origInfo;
+ if (!valid_for_bitmap_device(info, &info.fAlphaType)) {
+ return NULL;
+ }
+
+ SkBitmap bitmap;
-SkBitmapDevice::~SkBitmapDevice() {
+ if (kUnknown_SkColorType == info.colorType()) {
+ if (!bitmap.setConfig(info)) {
+ return NULL;
+ }
+ } else {
+ if (!bitmap.allocPixels(info)) {
+ return NULL;
+ }
+ if (!bitmap.info().isOpaque()) {
+ bitmap.eraseColor(SK_ColorTRANSPARENT);
+ }
+ }
+
+ if (props) {
+ return SkNEW_ARGS(SkBitmapDevice, (bitmap, *props));
+ } else {
+ return SkNEW_ARGS(SkBitmapDevice, (bitmap));
+ }
}
SkImageInfo SkBitmapDevice::imageInfo() const {
@@ -65,18 +135,8 @@ void SkBitmapDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) {
fBitmap.lockPixels();
}
-SkBaseDevice* SkBitmapDevice::onCreateCompatibleDevice(SkBitmap::Config config,
- int width, int height,
- bool isOpaque,
- Usage usage) {
- SkBitmapDevice* device = SkNEW_ARGS(SkBitmapDevice,(config, width, height,
- isOpaque, this->getDeviceProperties()));
- // Check if allocation failed and delete device if it did fail
- if ((device->width() != width) || (device->height() != height)) {
- SkDELETE(device);
- device = NULL;
- }
- return device;
+SkBaseDevice* SkBitmapDevice::onCreateDevice(const SkImageInfo& info, Usage usage) {
+ return SkBitmapDevice::Create(info, &this->getDeviceProperties());
}
void SkBitmapDevice::lockPixels() {