Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: base/gfx/bitmap_platform_device_linux.cc

Issue 8227: Switch from using GdkPixbuf to cairo for painting on Drawables. (Closed)
Patch Set: Address comments Created 12 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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> 7 #include <cairo/cairo.h>
8 #include <gdk-pixbuf/gdk-pixbuf.h>
9 8
10 #include "base/logging.h" 9 #include "base/logging.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) ; 19 cairo_surface_t* surface =
21 if (!pixbuf) 20 cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
22 return NULL; 21 width, height);
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 22
31 SkBitmap bitmap; 23 SkBitmap bitmap;
32 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height, 24 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height,
33 gdk_pixbuf_get_rowstride(pixbuf)); 25 cairo_image_surface_get_stride(surface));
34 bitmap.setPixels(gdk_pixbuf_get_pixels(pixbuf)); 26 bitmap.setPixels(cairo_image_surface_get_data(surface));
35 bitmap.setIsOpaque(is_opaque); 27 bitmap.setIsOpaque(is_opaque);
36 28
37 #ifndef NDEBUG 29 #ifndef NDEBUG
38 if (is_opaque) { 30 if (is_opaque) {
39 bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green 31 bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green
40 } 32 }
41 #endif 33 #endif
42 34
43 // The device object will take ownership of the graphics context. 35 // The device object will take ownership of the graphics context.
44 return new BitmapPlatformDeviceLinux(bitmap, pixbuf); 36 return new BitmapPlatformDeviceLinux(bitmap, surface);
45 } 37 }
46 38
47 // The device will own the bitmap, which corresponds to also owning the pixel 39 // 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. 40 // data. Therefore, we do not transfer ownership to the SkDevice's bitmap.
49 BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinux(const SkBitmap& bitmap, 41 BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinux(const SkBitmap& bitmap,
50 GdkPixbuf* pixbuf) 42 cairo_surface_t* surface)
51 : PlatformDeviceLinux(bitmap), 43 : PlatformDeviceLinux(bitmap),
52 pixbuf_(pixbuf) { 44 surface_(surface) {
53 } 45 }
54 46
55 BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinux( 47 BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinux(
56 const BitmapPlatformDeviceLinux& other) 48 const BitmapPlatformDeviceLinux& other)
57 : PlatformDeviceLinux(const_cast<BitmapPlatformDeviceLinux&>( 49 : PlatformDeviceLinux(const_cast<BitmapPlatformDeviceLinux&>(
58 other).accessBitmap(true)) { 50 other).accessBitmap(true)) {
59 } 51 }
60 52
61 BitmapPlatformDeviceLinux::~BitmapPlatformDeviceLinux() { 53 BitmapPlatformDeviceLinux::~BitmapPlatformDeviceLinux() {
62 if (pixbuf_) { 54 if (surface_) {
63 g_object_unref(pixbuf_); 55 cairo_surface_destroy(surface_);
64 pixbuf_ = NULL; 56 surface_ = NULL;
65 } 57 }
66 } 58 }
67 59
68 } // namespace gfx 60 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698