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 "base/gfx/bitmap_platform_device_linux.h" | 5 #include "base/gfx/bitmap_platform_device_linux.h" |
6 | 6 |
| 7 #include <gdk/gdk.h> |
| 8 #include <gdk-pixbuf/gdk-pixbuf.h> |
| 9 |
7 #include "base/logging.h" | 10 #include "base/logging.h" |
8 | 11 |
9 #include <time.h> | |
10 | |
11 namespace gfx { | 12 namespace gfx { |
12 | 13 |
13 // We use this static factory function instead of the regular constructor so | 14 // We use this static factory function instead of the regular constructor so |
14 // that we can create the pixel data before calling the constructor. This is | 15 // that we can create the pixel data before calling the constructor. This is |
15 // required so that we can call the base class' constructor with the pixel | 16 // required so that we can call the base class' constructor with the pixel |
16 // data. | 17 // data. |
17 BitmapPlatformDeviceLinux* BitmapPlatformDeviceLinux::Create( | 18 BitmapPlatformDeviceLinux* BitmapPlatformDeviceLinux::Create( |
18 int width, int height, bool is_opaque) { | 19 int width, int height, bool is_opaque) { |
| 20 GdkPixbuf* pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, true, 8, width, height)
; |
| 21 if (!pixbuf) |
| 22 return NULL; |
| 23 |
| 24 DCHECK_EQ(gdk_pixbuf_get_colorspace(pixbuf), GDK_COLORSPACE_RGB); |
| 25 DCHECK_EQ(gdk_pixbuf_get_bits_per_sample(pixbuf), 8); |
| 26 DCHECK(gdk_pixbuf_get_has_alpha(pixbuf)); |
| 27 DCHECK_EQ(gdk_pixbuf_get_n_channels(pixbuf), 4); |
| 28 DCHECK_EQ(gdk_pixbuf_get_width(pixbuf), width); |
| 29 DCHECK_EQ(gdk_pixbuf_get_height(pixbuf), height); |
| 30 |
19 SkBitmap bitmap; | 31 SkBitmap bitmap; |
20 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); | 32 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height, |
| 33 gdk_pixbuf_get_rowstride(pixbuf)); |
| 34 bitmap.setPixels(gdk_pixbuf_get_pixels(pixbuf)); |
21 bitmap.setIsOpaque(is_opaque); | 35 bitmap.setIsOpaque(is_opaque); |
22 | 36 |
| 37 #ifndef NDEBUG |
23 if (is_opaque) { | 38 if (is_opaque) { |
24 #ifndef NDEBUG | |
25 // To aid in finding bugs, we set the background color to something | |
26 // obviously wrong so it will be noticable when it is not cleared | |
27 bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green | 39 bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green |
| 40 } |
28 #endif | 41 #endif |
29 } | |
30 | 42 |
31 // The device object will take ownership of the graphics context. | 43 // The device object will take ownership of the graphics context. |
32 return new BitmapPlatformDeviceLinux(bitmap); | 44 return new BitmapPlatformDeviceLinux(bitmap, pixbuf); |
33 } | 45 } |
34 | 46 |
35 // The device will own the bitmap, which corresponds to also owning the pixel | 47 // The device will own the bitmap, which corresponds to also owning the pixel |
36 // data. Therefore, we do not transfer ownership to the SkDevice's bitmap. | 48 // data. Therefore, we do not transfer ownership to the SkDevice's bitmap. |
37 BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinux(const SkBitmap& bitmap) | 49 BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinux(const SkBitmap& bitmap, |
38 : PlatformDeviceLinux(bitmap) { | 50 GdkPixbuf* pixbuf) |
| 51 : PlatformDeviceLinux(bitmap), |
| 52 pixbuf_(pixbuf) { |
39 } | 53 } |
40 | 54 |
41 BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinux( | 55 BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinux( |
42 const BitmapPlatformDeviceLinux& other) | 56 const BitmapPlatformDeviceLinux& other) |
43 : PlatformDeviceLinux(const_cast<BitmapPlatformDeviceLinux&>( | 57 : PlatformDeviceLinux(const_cast<BitmapPlatformDeviceLinux&>( |
44 other).accessBitmap(true)) { | 58 other).accessBitmap(true)) { |
45 } | 59 } |
46 | 60 |
47 BitmapPlatformDeviceLinux::~BitmapPlatformDeviceLinux() { | 61 BitmapPlatformDeviceLinux::~BitmapPlatformDeviceLinux() { |
| 62 if (pixbuf_) { |
| 63 g_object_unref(pixbuf_); |
| 64 pixbuf_ = NULL; |
| 65 } |
48 } | 66 } |
49 | 67 |
50 } // namespace gfx | 68 } // namespace gfx |
OLD | NEW |