| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/platform_canvas_linux.h" | 5 #include "skia/ext/platform_canvas_linux.h" |
| 6 | 6 |
| 7 #include "skia/ext/platform_device_linux.h" | 7 #include "skia/ext/platform_device_linux.h" |
| 8 #include "skia/ext/bitmap_platform_device_linux.h" | 8 #include "skia/ext/bitmap_platform_device_linux.h" |
| 9 #include "SkTypes.h" | 9 #include "SkTypes.h" |
| 10 | 10 |
| 11 #include <cairo/cairo.h> | 11 #include <cairo/cairo.h> |
| 12 | 12 |
| 13 namespace skia { | 13 namespace skia { |
| 14 | 14 |
| 15 PlatformCanvasLinux::PlatformCanvasLinux() : SkCanvas() { | 15 PlatformCanvasLinux::PlatformCanvasLinux() : SkCanvas() { |
| 16 } | 16 } |
| 17 | 17 |
| 18 PlatformCanvasLinux::PlatformCanvasLinux(int width, int height, bool is_opaque) | 18 PlatformCanvasLinux::PlatformCanvasLinux(int width, int height, bool is_opaque) |
| 19 : SkCanvas() { | 19 : SkCanvas() { |
| 20 if (!initialize(width, height, is_opaque)) | 20 if (!initialize(width, height, is_opaque)) |
| 21 SK_CRASH(); | 21 SK_CRASH(); |
| 22 } | 22 } |
| 23 | 23 |
| 24 PlatformCanvasLinux::PlatformCanvasLinux(int width, int height, bool is_opaque, |
| 25 uint8_t* data) |
| 26 : SkCanvas() { |
| 27 if (!initialize(width, height, is_opaque, data)) |
| 28 SK_CRASH(); |
| 29 } |
| 30 |
| 24 PlatformCanvasLinux::~PlatformCanvasLinux() { | 31 PlatformCanvasLinux::~PlatformCanvasLinux() { |
| 25 } | 32 } |
| 26 | 33 |
| 27 bool PlatformCanvasLinux::initialize(int width, int height, bool is_opaque) { | 34 bool PlatformCanvasLinux::initialize(int width, int height, bool is_opaque) { |
| 28 SkDevice* device = createPlatformDevice(width, height, is_opaque); | 35 SkDevice* device = createPlatformDevice(width, height, is_opaque); |
| 29 if (!device) | 36 if (!device) |
| 30 return false; | 37 return false; |
| 31 | 38 |
| 32 setDevice(device); | 39 setDevice(device); |
| 33 device->unref(); // was created with refcount 1, and setDevice also refs | 40 device->unref(); // was created with refcount 1, and setDevice also refs |
| 34 return true; | 41 return true; |
| 35 } | 42 } |
| 36 | 43 |
| 44 bool PlatformCanvasLinux::initialize(int width, int height, bool is_opaque, |
| 45 uint8_t* data) { |
| 46 SkDevice* device = |
| 47 BitmapPlatformDeviceLinux::Create(width, height, is_opaque, data); |
| 48 if (!device) |
| 49 return false; |
| 50 |
| 51 setDevice(device); |
| 52 device->unref(); // was created with refcount 1, and setDevice also refs |
| 53 return true; |
| 54 } |
| 55 |
| 37 PlatformDeviceLinux& PlatformCanvasLinux::getTopPlatformDevice() const { | 56 PlatformDeviceLinux& PlatformCanvasLinux::getTopPlatformDevice() const { |
| 38 // All of our devices should be our special PlatformDevice. | 57 // All of our devices should be our special PlatformDevice. |
| 39 SkCanvas::LayerIter iter(const_cast<PlatformCanvasLinux*>(this), false); | 58 SkCanvas::LayerIter iter(const_cast<PlatformCanvasLinux*>(this), false); |
| 40 return *static_cast<PlatformDeviceLinux*>(iter.device()); | 59 return *static_cast<PlatformDeviceLinux*>(iter.device()); |
| 41 } | 60 } |
| 42 | 61 |
| 43 SkDevice* PlatformCanvasLinux::createDevice(SkBitmap::Config config, | 62 SkDevice* PlatformCanvasLinux::createDevice(SkBitmap::Config config, |
| 44 int width, | 63 int width, |
| 45 int height, | 64 int height, |
| 46 bool is_opaque, bool isForLayer) { | 65 bool is_opaque, bool isForLayer) { |
| 47 SkASSERT(config == SkBitmap::kARGB_8888_Config); | 66 SkASSERT(config == SkBitmap::kARGB_8888_Config); |
| 48 return createPlatformDevice(width, height, is_opaque); | 67 return createPlatformDevice(width, height, is_opaque); |
| 49 } | 68 } |
| 50 | 69 |
| 51 SkDevice* PlatformCanvasLinux::createPlatformDevice(int width, | 70 SkDevice* PlatformCanvasLinux::createPlatformDevice(int width, |
| 52 int height, | 71 int height, |
| 53 bool is_opaque) { | 72 bool is_opaque) { |
| 54 return BitmapPlatformDeviceLinux::Create(width, height, is_opaque); | 73 return BitmapPlatformDeviceLinux::Create(width, height, is_opaque); |
| 55 } | 74 } |
| 56 | 75 |
| 57 // static | 76 // static |
| 58 size_t PlatformCanvasLinux::StrideForWidth(unsigned width) { | 77 size_t PlatformCanvasLinux::StrideForWidth(unsigned width) { |
| 59 return cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width); | 78 return cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width); |
| 60 } | 79 } |
| 61 | 80 |
| 62 } // namespace skia | 81 } // namespace skia |
| OLD | NEW |