OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2016 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #include "SkRasterCanvasLayerAllocator.h" |
| 9 |
| 10 #include "SkBitmap.h" |
| 11 #include "SkCanvas.h" |
| 12 #include "SkManagedBitmapDevice.h" |
| 13 |
| 14 SkRasterCanvasLayerAllocator::SkRasterCanvasLayerAllocator() { } |
| 15 |
| 16 SkRasterCanvasLayerAllocator::~SkRasterCanvasLayerAllocator() { } |
| 17 |
| 18 sk_sp<SkCanvas> SkRasterCanvasLayerAllocator::createCanvas(const SkImageInfo& in
fo, |
| 19 const SkSurfaceProps&
props, |
| 20 void* initialData) { |
| 21 SkBaseDevice* device = makeDevice(info, props, initialData); |
| 22 if (!device) { |
| 23 return nullptr; |
| 24 } |
| 25 return sk_make_sp<SkCanvas>(device, this); |
| 26 } |
| 27 |
| 28 |
| 29 SkBaseDevice* SkRasterCanvasLayerAllocator::makeDevice( |
| 30 const SkImageInfo& info, |
| 31 const SkSurfaceProps& props, |
| 32 void* initialData) { |
| 33 SkBitmap bitmap; |
| 34 size_t rowBytes; |
| 35 void (*deallocator)(void*) = nullptr; |
| 36 void* payload = nullptr; |
| 37 void* pixels = this->allocateLayer(info, &rowBytes, |
| 38 &deallocator, &payload, |
| 39 initialData); |
| 40 if (!pixels) { |
| 41 return nullptr; |
| 42 } |
| 43 if (!bitmap.installPixels(info, pixels, rowBytes)) { |
| 44 deallocator(payload); |
| 45 return nullptr; |
| 46 }; |
| 47 |
| 48 return new SkManagedBitmapDevice(bitmap, props, deallocator, payload); |
| 49 } |
| 50 |
OLD | NEW |