Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: skia/ext/bitmap_platform_device_android.cc

Issue 9416017: Optionally clear PlatformCanvas instances. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Address comments & add BitmapPlatformDevice::CreateAndClear. Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 {
msw 2012/03/16 07:13:22 nit: this could now be "else if (!bitmap...)" and
Jeff Timanus 2012/03/16 15:52:42 Done.
32 if (!bitmap.allocPixels()) 41 if (!bitmap.allocPixels())
33 return NULL; 42 return NULL;
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 } 43 }
39 bitmap.setIsOpaque(is_opaque); 44 bitmap.setIsOpaque(is_opaque);
40 return new BitmapPlatformDevice(bitmap); 45 return new BitmapPlatformDevice(bitmap);
41 } 46 }
42 47
43 BitmapPlatformDevice::BitmapPlatformDevice(const SkBitmap& bitmap) 48 BitmapPlatformDevice::BitmapPlatformDevice(const SkBitmap& bitmap)
44 : SkDevice(bitmap) { 49 : SkDevice(bitmap) {
45 SetPlatformDevice(this, this); 50 SetPlatformDevice(this, this);
46 } 51 }
47 52
(...skipping 13 matching lines...) Expand all
61 return accessBitmap(true).getPixels(); 66 return accessBitmap(true).getPixels();
62 } 67 }
63 68
64 void BitmapPlatformDevice::DrawToNativeContext( 69 void BitmapPlatformDevice::DrawToNativeContext(
65 PlatformSurface surface, int x, int y, const PlatformRect* src_rect) { 70 PlatformSurface surface, int x, int y, const PlatformRect* src_rect) {
66 // Should never be called on Android. 71 // Should never be called on Android.
67 SkASSERT(false); 72 SkASSERT(false);
68 } 73 }
69 74
70 } // namespace skia 75 } // namespace skia
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698