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