| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "skia/ext/bitmap_platform_device_android.h" | 5 #include "skia/ext/bitmap_platform_device_android.h" |
| 6 | 6 |
| 7 namespace skia { | 7 namespace skia { |
| 8 | 8 |
| 9 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, | 9 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, |
| 10 bool is_opaque) { | 10 bool is_opaque) { |
| 11 SkBitmap bitmap; | 11 SkBitmap bitmap; |
| 12 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); | 12 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
| 13 if (bitmap.allocPixels()) { | 13 if (bitmap.allocPixels()) { |
| 14 bitmap.setIsOpaque(is_opaque); | 14 bitmap.setIsOpaque(is_opaque); |
| 15 // Follow the logic in SkCanvas::createDevice(), initialize the bitmap if it | 15 // Follow the logic in SkCanvas::createDevice(), initialize the bitmap if it |
| 16 // is not opaque. | 16 // is not opaque. |
| 17 if (!is_opaque) | 17 if (!is_opaque) |
| 18 bitmap.eraseARGB(0, 0, 0, 0); | 18 bitmap.eraseARGB(0, 0, 0, 0); |
| 19 return new BitmapPlatformDevice(bitmap); | 19 return new BitmapPlatformDevice(bitmap); |
| 20 } | 20 } |
| 21 return NULL; | 21 return NULL; |
| 22 } | 22 } |
| 23 | 23 |
| 24 BitmapPlatformDevice* BitmapPlatformDevice::CreateAndClear(int width, |
| 25 int height, |
| 26 bool is_opaque) { |
| 27 BitmapPlatformDevice* device = Create(width, height, is_opaque); |
| 28 if (!is_opaque) |
| 29 device->accessBitmap(true).eraseARGB(0, 0, 0, 0); |
| 30 return device; |
| 31 } |
| 32 |
| 24 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, | 33 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, |
| 25 bool is_opaque, | 34 bool is_opaque, |
| 26 uint8_t* data) { | 35 uint8_t* data) { |
| 27 SkBitmap bitmap; | 36 SkBitmap bitmap; |
| 28 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); | 37 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
| 29 if (data) { | 38 if (data) |
| 30 bitmap.setPixels(data); | 39 bitmap.setPixels(data); |
| 31 } else { | 40 else if (!bitmap.allocPixels()) |
| 32 if (!bitmap.allocPixels()) | 41 return NULL; |
| 33 return NULL; | 42 |
| 34 // Follow the logic in SkCanvas::createDevice(), initialize the bitmap if it | |
| 35 // is not opaque. | |
| 36 if (!is_opaque) | |
| 37 bitmap.eraseARGB(0, 0, 0, 0); | |
| 38 } | |
| 39 bitmap.setIsOpaque(is_opaque); | 43 bitmap.setIsOpaque(is_opaque); |
| 40 return new BitmapPlatformDevice(bitmap); | 44 return new BitmapPlatformDevice(bitmap); |
| 41 } | 45 } |
| 42 | 46 |
| 43 BitmapPlatformDevice::BitmapPlatformDevice(const SkBitmap& bitmap) | 47 BitmapPlatformDevice::BitmapPlatformDevice(const SkBitmap& bitmap) |
| 44 : SkDevice(bitmap) { | 48 : SkDevice(bitmap) { |
| 45 SetPlatformDevice(this, this); | 49 SetPlatformDevice(this, this); |
| 46 } | 50 } |
| 47 | 51 |
| 48 BitmapPlatformDevice::~BitmapPlatformDevice() { | 52 BitmapPlatformDevice::~BitmapPlatformDevice() { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 61 return accessBitmap(true).getPixels(); | 65 return accessBitmap(true).getPixels(); |
| 62 } | 66 } |
| 63 | 67 |
| 64 void BitmapPlatformDevice::DrawToNativeContext( | 68 void BitmapPlatformDevice::DrawToNativeContext( |
| 65 PlatformSurface surface, int x, int y, const PlatformRect* src_rect) { | 69 PlatformSurface surface, int x, int y, const PlatformRect* src_rect) { |
| 66 // Should never be called on Android. | 70 // Should never be called on Android. |
| 67 SkASSERT(false); | 71 SkASSERT(false); |
| 68 } | 72 } |
| 69 | 73 |
| 70 } // namespace skia | 74 } // namespace skia |
| OLD | NEW |