| 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/bitmap_platform_device_linux.h" | 5 #include "skia/ext/bitmap_platform_device_linux.h" |
| 6 | 6 |
| 7 #include <cairo/cairo.h> | 7 #include <cairo/cairo.h> |
| 8 | 8 |
| 9 namespace skia { | 9 namespace skia { |
| 10 | 10 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 BitmapPlatformDeviceLinuxData(const BitmapPlatformDeviceLinuxData&); | 34 BitmapPlatformDeviceLinuxData(const BitmapPlatformDeviceLinuxData&); |
| 35 BitmapPlatformDeviceLinuxData& operator=( | 35 BitmapPlatformDeviceLinuxData& operator=( |
| 36 const BitmapPlatformDeviceLinuxData&); | 36 const BitmapPlatformDeviceLinuxData&); |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 // We use this static factory function instead of the regular constructor so | 39 // We use this static factory function instead of the regular constructor so |
| 40 // that we can create the pixel data before calling the constructor. This is | 40 // that we can create the pixel data before calling the constructor. This is |
| 41 // required so that we can call the base class' constructor with the pixel | 41 // required so that we can call the base class' constructor with the pixel |
| 42 // data. | 42 // data. |
| 43 BitmapPlatformDeviceLinux* BitmapPlatformDeviceLinux::Create( | 43 BitmapPlatformDeviceLinux* BitmapPlatformDeviceLinux::Create( |
| 44 int width, int height, bool is_opaque) { | 44 int width, int height, bool is_opaque, cairo_surface_t* surface) { |
| 45 cairo_surface_t* surface = | |
| 46 cairo_image_surface_create(CAIRO_FORMAT_ARGB32, | |
| 47 width, height); | |
| 48 | |
| 49 SkBitmap bitmap; | 45 SkBitmap bitmap; |
| 50 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height, | 46 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height, |
| 51 cairo_image_surface_get_stride(surface)); | 47 cairo_image_surface_get_stride(surface)); |
| 52 bitmap.setPixels(cairo_image_surface_get_data(surface)); | 48 bitmap.setPixels(cairo_image_surface_get_data(surface)); |
| 53 bitmap.setIsOpaque(is_opaque); | 49 bitmap.setIsOpaque(is_opaque); |
| 54 | 50 |
| 55 #ifndef NDEBUG | 51 #ifndef NDEBUG |
| 56 if (is_opaque) { | 52 if (is_opaque) { |
| 57 bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green | 53 bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green |
| 58 } | 54 } |
| 59 #endif | 55 #endif |
| 60 | 56 |
| 61 // The device object will take ownership of the graphics context. | 57 // The device object will take ownership of the graphics context. |
| 62 return new BitmapPlatformDeviceLinux | 58 return new BitmapPlatformDeviceLinux |
| 63 (bitmap, new BitmapPlatformDeviceLinuxData(surface)); | 59 (bitmap, new BitmapPlatformDeviceLinuxData(surface)); |
| 64 } | 60 } |
| 65 | 61 |
| 62 BitmapPlatformDeviceLinux* BitmapPlatformDeviceLinux::Create( |
| 63 int width, int height, bool is_opaque) { |
| 64 cairo_surface_t* surface = |
| 65 cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
| 66 width, height); |
| 67 |
| 68 return Create(width, height, is_opaque, surface); |
| 69 } |
| 70 |
| 71 BitmapPlatformDeviceLinux* BitmapPlatformDeviceLinux::Create( |
| 72 int width, int height, bool is_opaque, uint8_t* data) { |
| 73 cairo_surface_t* surface = cairo_image_surface_create_for_data( |
| 74 data, CAIRO_FORMAT_ARGB32, width, height, |
| 75 cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width)); |
| 76 |
| 77 return Create(width, height, is_opaque, surface); |
| 78 } |
| 79 |
| 66 // The device will own the bitmap, which corresponds to also owning the pixel | 80 // The device will own the bitmap, which corresponds to also owning the pixel |
| 67 // data. Therefore, we do not transfer ownership to the SkDevice's bitmap. | 81 // data. Therefore, we do not transfer ownership to the SkDevice's bitmap. |
| 68 BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinux( | 82 BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinux( |
| 69 const SkBitmap& bitmap, | 83 const SkBitmap& bitmap, |
| 70 BitmapPlatformDeviceLinuxData* data) | 84 BitmapPlatformDeviceLinuxData* data) |
| 71 : PlatformDeviceLinux(bitmap), | 85 : PlatformDeviceLinux(bitmap), |
| 72 data_(data) { | 86 data_(data) { |
| 73 } | 87 } |
| 74 | 88 |
| 75 BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinux( | 89 BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinux( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 86 return data_->surface(); | 100 return data_->surface(); |
| 87 } | 101 } |
| 88 | 102 |
| 89 BitmapPlatformDeviceLinux& BitmapPlatformDeviceLinux::operator=( | 103 BitmapPlatformDeviceLinux& BitmapPlatformDeviceLinux::operator=( |
| 90 const BitmapPlatformDeviceLinux& other) { | 104 const BitmapPlatformDeviceLinux& other) { |
| 91 data_ = other.data_; | 105 data_ = other.data_; |
| 92 return *this; | 106 return *this; |
| 93 } | 107 } |
| 94 | 108 |
| 95 } // namespace skia | 109 } // namespace skia |
| OLD | NEW |