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

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

Issue 199077: Reapplies the GdkPixbuf -> cairo surface patch. (Closed)
Patch Set: 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
« no previous file with comments | « chrome/browser/gtk/cairo_cached_surface.h ('k') | chrome/browser/gtk/custom_button.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 int CairoCachedSurface::Width() const {
22 return pixbuf_ ? gdk_pixbuf_get_width(pixbuf_) : -1;
23 }
24
25 int CairoCachedSurface::Height() const {
26 return pixbuf_ ? gdk_pixbuf_get_height(pixbuf_) : -1;
27 }
28
29 void CairoCachedSurface::UsePixbuf(GdkPixbuf* pixbuf) {
30 if (surface_) {
31 cairo_surface_destroy(surface_);
32 surface_ = NULL;
33 }
34
35 if (pixbuf)
36 g_object_ref(pixbuf);
37
38 if (pixbuf_)
39 g_object_unref(pixbuf_);
40
41 pixbuf_ = pixbuf;
42 }
43
44 void CairoCachedSurface::SetSource(cairo_t* cr, int x, int y) {
45 DCHECK(pixbuf_);
46 DCHECK(cr);
47
48 if (!surface_) {
49 // First time here since last UsePixbuf call. Generate the surface.
50 cairo_surface_t* target = cairo_get_target(cr);
51 surface_ = cairo_surface_create_similar(
52 target,
53 CAIRO_CONTENT_COLOR_ALPHA,
54 gdk_pixbuf_get_width(pixbuf_),
55 gdk_pixbuf_get_height(pixbuf_));
56
57 DCHECK(surface_);
58 DCHECK(cairo_surface_get_type(surface_) == CAIRO_SURFACE_TYPE_XLIB ||
59 cairo_surface_get_type(surface_) == CAIRO_SURFACE_TYPE_XCB);
60
61 cairo_t* copy_cr = cairo_create(surface_);
62 gdk_cairo_set_source_pixbuf(copy_cr, pixbuf_, 0, 0);
63 cairo_paint(copy_cr);
64 cairo_destroy(copy_cr);
65 }
66
67 cairo_set_source_surface(cr, surface_, x, y);
68 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/cairo_cached_surface.h ('k') | chrome/browser/gtk/custom_button.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698