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

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

Issue 2616003003: Revert of Delete Mac & Cairo skia::BitmapPlatformDevice impls (Closed)
Patch Set: Created 3 years, 11 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_skia.h ('k') | skia/ext/bitmap_platform_device_win.h » ('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 return Create(width, height, is_opaque, nullptr); 12 SkBitmap bitmap;
13 if (bitmap.tryAllocN32Pixels(width, height, is_opaque)) {
14 // Follow the logic in SkCanvas::createDevice(), initialize the bitmap if it
15 // is not opaque.
16 if (!is_opaque)
17 bitmap.eraseARGB(0, 0, 0, 0);
18 return new BitmapPlatformDevice(bitmap);
19 }
20 return NULL;
13 } 21 }
14 22
15 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, 23 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height,
16 bool is_opaque, 24 bool is_opaque,
17 uint8_t* data) { 25 uint8_t* data) {
18 SkBitmap bitmap; 26 SkBitmap bitmap;
19 bitmap.setInfo(SkImageInfo::MakeN32(width, height, 27 bitmap.setInfo(SkImageInfo::MakeN32(width, height,
20 is_opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType)); 28 is_opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType));
21 29 if (data)
22 if (data) {
23 bitmap.setPixels(data); 30 bitmap.setPixels(data);
24 } else { 31 else if (!bitmap.tryAllocPixels())
25 if (!bitmap.tryAllocPixels()) 32 return NULL;
26 return nullptr;
27 // Follow the logic in SkCanvas::createDevice(), initialize the bitmap if
28 // it is not opaque.
29 if (!is_opaque)
30 bitmap.eraseARGB(0, 0, 0, 0);
31 }
32 33
33 return new BitmapPlatformDevice(bitmap); 34 return new BitmapPlatformDevice(bitmap);
34 } 35 }
35 36
36 BitmapPlatformDevice::BitmapPlatformDevice(const SkBitmap& bitmap) 37 BitmapPlatformDevice::BitmapPlatformDevice(const SkBitmap& bitmap)
37 : SkBitmapDevice(bitmap) { 38 : SkBitmapDevice(bitmap) {
38 SetPlatformDevice(this, this); 39 SetPlatformDevice(this, this);
39 } 40 }
40 41
41 BitmapPlatformDevice::~BitmapPlatformDevice() { 42 BitmapPlatformDevice::~BitmapPlatformDevice() {
42 } 43 }
43 44
44 SkBaseDevice* BitmapPlatformDevice::onCreateDevice(const CreateInfo& info, 45 SkBaseDevice* BitmapPlatformDevice::onCreateDevice(const CreateInfo& info,
45 const SkPaint*) { 46 const SkPaint*) {
46 SkASSERT(info.fInfo.colorType() == kN32_SkColorType); 47 SkASSERT(info.fInfo.colorType() == kN32_SkColorType);
47 return BitmapPlatformDevice::Create(info.fInfo.width(), info.fInfo.height(), 48 return BitmapPlatformDevice::Create(info.fInfo.width(), info.fInfo.height(),
48 info.fInfo.isOpaque()); 49 info.fInfo.isOpaque());
49 } 50 }
50 51
52 NativeDrawingContext BitmapPlatformDevice::BeginPlatformPaint(
53 const SkMatrix& transform,
54 const SkIRect& clip_bounds) {
55 // TODO(zhenghao): What should we return? The ptr to the address of the
56 // pixels? Maybe this won't be called at all.
57 SkPixmap pixmap;
58 return accessPixels(&pixmap) ? pixmap.writable_addr() : nullptr;
59 }
60
51 // PlatformCanvas impl 61 // PlatformCanvas impl
52 62
53 std::unique_ptr<SkCanvas> CreatePlatformCanvasWithPixels( 63 std::unique_ptr<SkCanvas> CreatePlatformCanvasWithPixels(
54 int width, 64 int width,
55 int height, 65 int height,
56 bool is_opaque, 66 bool is_opaque,
57 uint8_t* data, 67 uint8_t* data,
58 OnFailureType failureType) { 68 OnFailureType failureType) {
59 sk_sp<SkBaseDevice> dev( 69 sk_sp<SkBaseDevice> dev(
60 BitmapPlatformDevice::Create(width, height, is_opaque, data)); 70 BitmapPlatformDevice::Create(width, height, is_opaque, data));
61 return CreateCanvas(dev, failureType); 71 return CreateCanvas(dev, failureType);
62 } 72 }
63 73
64 } // namespace skia 74 } // namespace skia
OLDNEW
« no previous file with comments | « skia/ext/bitmap_platform_device_skia.h ('k') | skia/ext/bitmap_platform_device_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698