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

Side by Side Diff: chrome/browser/gtk/cairo_cached_surface.cc

Issue 197046: Upload GdkPixbufs into cairo surfaces so they (hopefully) live on X (Closed)
Patch Set: Fix crash Created 11 years, 3 months 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
(Empty)
1 // Copyright (c) 2009 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 "chrome/browser/gtk/cairo_cached_surface.h"
6
7 #include "base/basictypes.h"
8 #include "base/logging.h"
9
10 CairoCachedSurface::CairoCachedSurface() : pixbuf_(NULL), surface_(NULL) {
11 }
12
13 CairoCachedSurface::~CairoCachedSurface() {
14 if (surface_)
15 cairo_surface_destroy(surface_);
16
17 if (pixbuf_)
18 g_object_unref(pixbuf_);
19 }
20
21 bool CairoCachedSurface::valid() const {
22 return pixbuf_;
23 }
24
25 int CairoCachedSurface::Width() const {
26 return pixbuf_ ? gdk_pixbuf_get_width(pixbuf_) : -1;
27 }
28
29 int CairoCachedSurface::Height() const {
30 return pixbuf_ ? gdk_pixbuf_get_height(pixbuf_) : -1;
31 }
32
33 void CairoCachedSurface::UsePixbuf(GdkPixbuf* pixbuf) {
34 if (surface_) {
35 cairo_surface_destroy(surface_);
36 surface_ = NULL;
37 }
38
39 if (pixbuf)
40 g_object_ref(pixbuf);
41
42 if (pixbuf_)
43 g_object_unref(pixbuf_);
44
45 pixbuf_ = pixbuf;
46 }
47
48 void CairoCachedSurface::SetSource(cairo_t* cr, int x, int y) {
49 DCHECK(pixbuf_);
50 DCHECK(cr);
51
52 if (!surface_) {
53 // First time here since last UsePixbuf call. Generate the surface.
54 cairo_surface_t* target = cairo_get_target(cr);
55 surface_ = cairo_surface_create_similar(
56 target,
57 CAIRO_CONTENT_COLOR_ALPHA,
58 gdk_pixbuf_get_width(pixbuf_),
59 gdk_pixbuf_get_height(pixbuf_));
60
61 DCHECK(surface_);
62 DCHECK(cairo_surface_get_type(surface_) == CAIRO_SURFACE_TYPE_XLIB ||
63 cairo_surface_get_type(surface_) == CAIRO_SURFACE_TYPE_XCB);
64
65 cairo_t* copy_cr = cairo_create(surface_);
66 gdk_cairo_set_source_pixbuf(copy_cr, pixbuf_, 0, 0);
67 cairo_paint(copy_cr);
68 cairo_destroy(copy_cr);
69 }
70
71 cairo_set_source_surface(cr, surface_, x, y);
72 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698