Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / skia / ext / bitmap_platform_device_skia.cc
blob04fc950f56028a98850e11f81a0414e1a44b7b40
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
3 // found in the LICENSE file.
5 #include "skia/ext/bitmap_platform_device_skia.h"
6 #include "skia/ext/platform_canvas.h"
8 namespace skia {
10 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height,
11 bool is_opaque) {
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);
20 return NULL;
23 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height,
24 bool is_opaque,
25 uint8_t* data) {
26 SkBitmap bitmap;
27 bitmap.setInfo(SkImageInfo::MakeN32(width, height,
28 is_opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType));
29 if (data)
30 bitmap.setPixels(data);
31 else if (!bitmap.tryAllocPixels())
32 return NULL;
34 return new BitmapPlatformDevice(bitmap);
37 BitmapPlatformDevice::BitmapPlatformDevice(const SkBitmap& bitmap)
38 : SkBitmapDevice(bitmap) {
39 SetPlatformDevice(this, this);
42 BitmapPlatformDevice::~BitmapPlatformDevice() {
45 SkBaseDevice* BitmapPlatformDevice::onCreateDevice(const CreateInfo& info,
46 const SkPaint*) {
47 SkASSERT(info.fInfo.colorType() == kN32_SkColorType);
48 return BitmapPlatformDevice::Create(info.fInfo.width(), info.fInfo.height(),
49 info.fInfo.isOpaque());
52 PlatformSurface BitmapPlatformDevice::BeginPlatformPaint() {
53 // TODO(zhenghao): What should we return? The ptr to the address of the
54 // pixels? Maybe this won't be called at all.
55 return accessBitmap(true).getPixels();
58 // PlatformCanvas impl
60 SkCanvas* CreatePlatformCanvas(int width, int height, bool is_opaque,
61 uint8_t* data, OnFailureType failureType) {
62 skia::RefPtr<SkBaseDevice> dev = skia::AdoptRef(
63 BitmapPlatformDevice::Create(width, height, is_opaque, data));
64 return CreateCanvas(dev, failureType);
67 // Port of PlatformBitmap to android
68 PlatformBitmap::~PlatformBitmap() {
69 // Nothing to do.
72 bool PlatformBitmap::Allocate(int width, int height, bool is_opaque) {
73 if (!bitmap_.tryAllocN32Pixels(width, height, is_opaque))
74 return false;
76 surface_ = bitmap_.getPixels();
77 return true;
80 } // namespace skia