| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/gfx/bitmap_platform_device_linux.h" | |
| 6 | |
| 7 #include <cairo/cairo.h> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 | |
| 11 namespace gfx { | |
| 12 | |
| 13 // ----------------------------------------------------------------------------- | |
| 14 // These objects are reference counted and own a Cairo surface. The surface is | |
| 15 // the backing store for a Skia bitmap and we reference count it so that we can | |
| 16 // copy BitmapPlatformDeviceLinux objects without having to copy all the image | |
| 17 // data. | |
| 18 // ----------------------------------------------------------------------------- | |
| 19 class BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinuxData | |
| 20 : public base::RefCounted<BitmapPlatformDeviceLinuxData> { | |
| 21 public: | |
| 22 explicit BitmapPlatformDeviceLinuxData(cairo_surface_t* surface) | |
| 23 : surface_(surface) { } | |
| 24 | |
| 25 cairo_surface_t* surface() const { return surface_; } | |
| 26 | |
| 27 protected: | |
| 28 cairo_surface_t *const surface_; | |
| 29 | |
| 30 friend class base::RefCounted<BitmapPlatformDeviceLinuxData>; | |
| 31 ~BitmapPlatformDeviceLinuxData() { | |
| 32 cairo_surface_destroy(surface_); | |
| 33 } | |
| 34 | |
| 35 DISALLOW_EVIL_CONSTRUCTORS(BitmapPlatformDeviceLinuxData); | |
| 36 }; | |
| 37 | |
| 38 // We use this static factory function instead of the regular constructor so | |
| 39 // that we can create the pixel data before calling the constructor. This is | |
| 40 // required so that we can call the base class' constructor with the pixel | |
| 41 // data. | |
| 42 BitmapPlatformDeviceLinux* BitmapPlatformDeviceLinux::Create( | |
| 43 int width, int height, bool is_opaque) { | |
| 44 cairo_surface_t* surface = | |
| 45 cairo_image_surface_create(CAIRO_FORMAT_ARGB32, | |
| 46 width, height); | |
| 47 | |
| 48 SkBitmap bitmap; | |
| 49 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height, | |
| 50 cairo_image_surface_get_stride(surface)); | |
| 51 bitmap.setPixels(cairo_image_surface_get_data(surface)); | |
| 52 bitmap.setIsOpaque(is_opaque); | |
| 53 | |
| 54 #ifndef NDEBUG | |
| 55 if (is_opaque) { | |
| 56 bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green | |
| 57 } | |
| 58 #endif | |
| 59 | |
| 60 // The device object will take ownership of the graphics context. | |
| 61 return new BitmapPlatformDeviceLinux | |
| 62 (bitmap, new BitmapPlatformDeviceLinuxData(surface)); | |
| 63 } | |
| 64 | |
| 65 // The device will own the bitmap, which corresponds to also owning the pixel | |
| 66 // data. Therefore, we do not transfer ownership to the SkDevice's bitmap. | |
| 67 BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinux( | |
| 68 const SkBitmap& bitmap, | |
| 69 BitmapPlatformDeviceLinuxData* data) | |
| 70 : PlatformDeviceLinux(bitmap), | |
| 71 data_(data) { | |
| 72 } | |
| 73 | |
| 74 BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinux( | |
| 75 const BitmapPlatformDeviceLinux& other) | |
| 76 : PlatformDeviceLinux(const_cast<BitmapPlatformDeviceLinux&>( | |
| 77 other).accessBitmap(true)), | |
| 78 data_(other.data_) { | |
| 79 } | |
| 80 | |
| 81 BitmapPlatformDeviceLinux::~BitmapPlatformDeviceLinux() { | |
| 82 } | |
| 83 | |
| 84 cairo_surface_t* BitmapPlatformDeviceLinux::surface() const { | |
| 85 return data_->surface(); | |
| 86 } | |
| 87 | |
| 88 BitmapPlatformDeviceLinux& BitmapPlatformDeviceLinux::operator=( | |
| 89 const BitmapPlatformDeviceLinux& other) { | |
| 90 data_ = other.data_; | |
| 91 return *this; | |
| 92 } | |
| 93 | |
| 94 } // namespace gfx | |
| OLD | NEW |