OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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/platform_canvas.h" |
| 6 |
| 7 #include "base/debug/trace_event.h" |
| 8 #include "skia/ext/bitmap_platform_device.h" |
| 9 |
| 10 namespace skia { |
| 11 |
| 12 PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque) { |
| 13 TRACE_EVENT2("skia", "PlatformCanvas::PlatformCanvas", |
| 14 "width", width, "height", height); |
| 15 if (!initialize(width, height, is_opaque)) |
| 16 SK_CRASH(); |
| 17 } |
| 18 |
| 19 #if defined(WIN32) |
| 20 PlatformCanvas::PlatformCanvas(int width, |
| 21 int height, |
| 22 bool is_opaque, |
| 23 HANDLE shared_section) { |
| 24 TRACE_EVENT2("skia", "PlatformCanvas::PlatformCanvas", |
| 25 "width", width, "height", height); |
| 26 if (!initialize(width, height, is_opaque, shared_section)) |
| 27 SK_CRASH(); |
| 28 } |
| 29 #else |
| 30 PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque, |
| 31 uint8_t* data) { |
| 32 TRACE_EVENT2("skia", "PlatformCanvas::PlatformCanvas", |
| 33 "width", width, "height", height); |
| 34 if (!initialize(width, height, is_opaque, data)) |
| 35 SK_CRASH(); |
| 36 } |
| 37 #endif |
| 38 |
| 39 PlatformCanvas::~PlatformCanvas() { |
| 40 } |
| 41 |
| 42 #if defined(WIN32) |
| 43 bool PlatformCanvas::initialize(int width, |
| 44 int height, |
| 45 bool is_opaque, |
| 46 HANDLE shared_section) { |
| 47 // Use platform specific device for shared_section. |
| 48 if (shared_section) { |
| 49 if (initializeWithDevice(BitmapPlatformDevice::Create(width, |
| 50 height, |
| 51 is_opaque, |
| 52 shared_section))) |
| 53 return true; |
| 54 // Investigate we failed. If we know the reason, crash in a specific place. |
| 55 unsigned int error = GetLastError(); |
| 56 if (shared_section) |
| 57 CrashIfInvalidSection(shared_section); |
| 58 CrashForBitmapAllocationFailure(width, height, error); |
| 59 return false; |
| 60 } |
| 61 |
| 62 return initializeWithDevice(new SkDevice( |
| 63 SkBitmap::kARGB_8888_Config, width, height, is_opaque)); |
| 64 } |
| 65 #else |
| 66 bool PlatformCanvas::initialize(int width, int height, bool is_opaque, |
| 67 uint8_t* data) { |
| 68 // Use platform specific device for data. |
| 69 if (data) |
| 70 return initializeWithDevice(BitmapPlatformDevice::Create( |
| 71 width, height, is_opaque, data)); |
| 72 |
| 73 return initializeWithDevice(new SkDevice( |
| 74 SkBitmap::kARGB_8888_Config, width, height, is_opaque)); |
| 75 } |
| 76 #endif |
| 77 |
| 78 } // namespace skia |
OLD | NEW |