| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "skia/ext/bitmap_platform_device_skia.h" | |
| 6 #include "skia/ext/platform_canvas.h" | |
| 7 | |
| 8 namespace skia { | |
| 9 | |
| 10 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, | |
| 11 bool is_opaque) { | |
| 12 return Create(width, height, is_opaque, nullptr); | |
| 13 } | |
| 14 | |
| 15 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, | |
| 16 bool is_opaque, | |
| 17 uint8_t* data) { | |
| 18 SkBitmap bitmap; | |
| 19 bitmap.setInfo(SkImageInfo::MakeN32(width, height, | |
| 20 is_opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType)); | |
| 21 | |
| 22 if (data) { | |
| 23 bitmap.setPixels(data); | |
| 24 } else { | |
| 25 if (!bitmap.tryAllocPixels()) | |
| 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 return new BitmapPlatformDevice(bitmap); | |
| 34 } | |
| 35 | |
| 36 BitmapPlatformDevice::BitmapPlatformDevice(const SkBitmap& bitmap) | |
| 37 : SkBitmapDevice(bitmap) { | |
| 38 SetPlatformDevice(this, this); | |
| 39 } | |
| 40 | |
| 41 BitmapPlatformDevice::~BitmapPlatformDevice() { | |
| 42 } | |
| 43 | |
| 44 SkBaseDevice* BitmapPlatformDevice::onCreateDevice(const CreateInfo& info, | |
| 45 const SkPaint*) { | |
| 46 SkASSERT(info.fInfo.colorType() == kN32_SkColorType); | |
| 47 return BitmapPlatformDevice::Create(info.fInfo.width(), info.fInfo.height(), | |
| 48 info.fInfo.isOpaque()); | |
| 49 } | |
| 50 | |
| 51 // PlatformCanvas impl | |
| 52 | |
| 53 std::unique_ptr<SkCanvas> CreatePlatformCanvasWithPixels( | |
| 54 int width, | |
| 55 int height, | |
| 56 bool is_opaque, | |
| 57 uint8_t* data, | |
| 58 OnFailureType failureType) { | |
| 59 sk_sp<SkBaseDevice> dev( | |
| 60 BitmapPlatformDevice::Create(width, height, is_opaque, data)); | |
| 61 return CreateCanvas(dev, failureType); | |
| 62 } | |
| 63 | |
| 64 } // namespace skia | |
| OLD | NEW |