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

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

Issue 545513002: tryAllocPixels returns bool, allocPixels requires success (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « skia/ext/bitmap_platform_device_mac.cc ('k') | skia/ext/skia_utils_ios.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_skia.h" 5 #include "skia/ext/bitmap_platform_device_skia.h"
6 #include "skia/ext/platform_canvas.h" 6 #include "skia/ext/platform_canvas.h"
7 7
8 namespace skia { 8 namespace skia {
9 9
10 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, 10 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height,
11 bool is_opaque) { 11 bool is_opaque) {
12 SkBitmap bitmap; 12 SkBitmap bitmap;
13 if (bitmap.allocN32Pixels(width, height, is_opaque)) { 13 if (bitmap.tryAllocN32Pixels(width, height, is_opaque)) {
14 // Follow the logic in SkCanvas::createDevice(), initialize the bitmap if it 14 // Follow the logic in SkCanvas::createDevice(), initialize the bitmap if it
15 // is not opaque. 15 // is not opaque.
16 if (!is_opaque) 16 if (!is_opaque)
17 bitmap.eraseARGB(0, 0, 0, 0); 17 bitmap.eraseARGB(0, 0, 0, 0);
18 return new BitmapPlatformDevice(bitmap); 18 return new BitmapPlatformDevice(bitmap);
19 } 19 }
20 return NULL; 20 return NULL;
21 } 21 }
22 22
23 BitmapPlatformDevice* BitmapPlatformDevice::CreateAndClear(int width, 23 BitmapPlatformDevice* BitmapPlatformDevice::CreateAndClear(int width,
24 int height, 24 int height,
25 bool is_opaque) { 25 bool is_opaque) {
26 BitmapPlatformDevice* device = Create(width, height, is_opaque); 26 BitmapPlatformDevice* device = Create(width, height, is_opaque);
27 if (!is_opaque) 27 if (!is_opaque)
28 device->clear(0); 28 device->clear(0);
29 return device; 29 return device;
30 } 30 }
31 31
32 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, 32 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height,
33 bool is_opaque, 33 bool is_opaque,
34 uint8_t* data) { 34 uint8_t* data) {
35 SkBitmap bitmap; 35 SkBitmap bitmap;
36 bitmap.setInfo(SkImageInfo::MakeN32(width, height, 36 bitmap.setInfo(SkImageInfo::MakeN32(width, height,
37 is_opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType)); 37 is_opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType));
38 if (data) 38 if (data)
39 bitmap.setPixels(data); 39 bitmap.setPixels(data);
40 else if (!bitmap.allocPixels()) 40 else if (!bitmap.tryAllocPixels())
41 return NULL; 41 return NULL;
42 42
43 return new BitmapPlatformDevice(bitmap); 43 return new BitmapPlatformDevice(bitmap);
44 } 44 }
45 45
46 BitmapPlatformDevice::BitmapPlatformDevice(const SkBitmap& bitmap) 46 BitmapPlatformDevice::BitmapPlatformDevice(const SkBitmap& bitmap)
47 : SkBitmapDevice(bitmap) { 47 : SkBitmapDevice(bitmap) {
48 SetPlatformDevice(this, this); 48 SetPlatformDevice(this, this);
49 } 49 }
50 50
(...skipping 27 matching lines...) Expand all
78 BitmapPlatformDevice::Create(width, height, is_opaque, data)); 78 BitmapPlatformDevice::Create(width, height, is_opaque, data));
79 return CreateCanvas(dev, failureType); 79 return CreateCanvas(dev, failureType);
80 } 80 }
81 81
82 // Port of PlatformBitmap to android 82 // Port of PlatformBitmap to android
83 PlatformBitmap::~PlatformBitmap() { 83 PlatformBitmap::~PlatformBitmap() {
84 // Nothing to do. 84 // Nothing to do.
85 } 85 }
86 86
87 bool PlatformBitmap::Allocate(int width, int height, bool is_opaque) { 87 bool PlatformBitmap::Allocate(int width, int height, bool is_opaque) {
88 if (!bitmap_.allocN32Pixels(width, height, is_opaque)) 88 if (!bitmap_.tryAllocN32Pixels(width, height, is_opaque))
89 return false; 89 return false;
90 90
91 surface_ = bitmap_.getPixels(); 91 surface_ = bitmap_.getPixels();
92 return true; 92 return true;
93 } 93 }
94 94
95 } // namespace skia 95 } // namespace skia
OLDNEW
« no previous file with comments | « skia/ext/bitmap_platform_device_mac.cc ('k') | skia/ext/skia_utils_ios.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698