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

Side by Side Diff: skia/ext/canvas_paint_linux.h

Issue 149409: Keep the cairo clipping region in sync with the Skia one. (Closed)
Patch Set: git try Created 11 years, 5 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 | « skia/ext/bitmap_platform_device_win.h ('k') | skia/ext/platform_canvas_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 2 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be 3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file. 4 // found in the LICENSE file.
5 5
6 #ifndef SKIA_EXT_CANVAS_PAINT_LINUX_H_ 6 #ifndef SKIA_EXT_CANVAS_PAINT_LINUX_H_
7 #define SKIA_EXT_CANVAS_PAINT_LINUX_H_ 7 #define SKIA_EXT_CANVAS_PAINT_LINUX_H_
8 8
9 #include "skia/ext/platform_canvas.h" 9 #include "skia/ext/platform_canvas.h"
10 10
11 #include <gdk/gdk.h> 11 #include <gdk/gdk.h>
12 12
13 namespace skia { 13 namespace skia {
14 14
15 // A class designed to translate skia painting into a region in a 15 // A class designed to translate skia painting into a region in a
16 // GdkWindow. This class has been adapted from the class with the same name in 16 // GdkWindow. This class has been adapted from the class with the same name in
17 // platform_canvas_win.h. On construction, it will set up a context for 17 // platform_canvas_win.h. On construction, it will set up a context for
18 // painting into, and on destruction, it will commit it to the GdkWindow. 18 // painting into, and on destruction, it will commit it to the GdkWindow.
19 template <class T> 19 template <class T>
20 class CanvasPaintT : public T { 20 class CanvasPaintT : public T {
21 public: 21 public:
22 // This constructor assumes the result is opaque. 22 // This constructor assumes the result is opaque.
23 explicit CanvasPaintT(GdkEventExpose* event) 23 explicit CanvasPaintT(GdkEventExpose* event)
24 : surface_(NULL), 24 : context_(NULL),
25 window_(event->window), 25 window_(event->window),
26 rectangle_(event->area), 26 rectangle_(event->area),
27 composite_alpha_(false) { 27 composite_alpha_(false) {
28 init(true); 28 init(true);
29 } 29 }
30 30
31 CanvasPaintT(GdkEventExpose* event, bool opaque) 31 CanvasPaintT(GdkEventExpose* event, bool opaque)
32 : surface_(NULL), 32 : context_(NULL),
33 window_(event->window), 33 window_(event->window),
34 rectangle_(event->area), 34 rectangle_(event->area),
35 composite_alpha_(false) { 35 composite_alpha_(false) {
36 init(opaque); 36 init(opaque);
37 } 37 }
38 38
39 virtual ~CanvasPaintT() { 39 virtual ~CanvasPaintT() {
40 if (!is_empty()) { 40 if (!is_empty()) {
41 T::restoreToCount(1); 41 T::restoreToCount(1);
42 42
43 // Blit the dirty rect to the window. 43 // Blit the dirty rect to the window.
44 cairo_t* cr = gdk_cairo_create(window_); 44 cairo_t* cr = gdk_cairo_create(window_);
45 if (composite_alpha_) 45 if (composite_alpha_)
46 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); 46 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
47 cairo_set_source_surface(cr, surface_, rectangle_.x, rectangle_.y); 47 cairo_surface_t* source_surface = cairo_get_target(context_);
48 cairo_set_source_surface(cr, source_surface, rectangle_.x, rectangle_.y);
48 cairo_rectangle(cr, rectangle_.x, rectangle_.y, 49 cairo_rectangle(cr, rectangle_.x, rectangle_.y,
49 rectangle_.width, rectangle_.height); 50 rectangle_.width, rectangle_.height);
50 cairo_fill(cr); 51 cairo_fill(cr);
51 cairo_destroy(cr); 52 cairo_destroy(cr);
52 } 53 }
53 } 54 }
54 55
55 // Sets whether the bitmap is composited in such a way that the alpha channel 56 // Sets whether the bitmap is composited in such a way that the alpha channel
56 // is honored. This is only useful if you've enabled an RGBA colormap on the 57 // is honored. This is only useful if you've enabled an RGBA colormap on the
57 // widget. The default is false. 58 // widget. The default is false.
(...skipping 15 matching lines...) Expand all
73 void init(bool opaque) { 74 void init(bool opaque) {
74 if (!T::initialize(rectangle_.width, rectangle_.height, opaque, NULL)) { 75 if (!T::initialize(rectangle_.width, rectangle_.height, opaque, NULL)) {
75 // Cause a deliberate crash; 76 // Cause a deliberate crash;
76 *(char*) 0 = 0; 77 *(char*) 0 = 0;
77 } 78 }
78 79
79 // Need to translate so that the dirty region appears at the origin of the 80 // Need to translate so that the dirty region appears at the origin of the
80 // surface. 81 // surface.
81 T::translate(-SkIntToScalar(rectangle_.x), -SkIntToScalar(rectangle_.y)); 82 T::translate(-SkIntToScalar(rectangle_.x), -SkIntToScalar(rectangle_.y));
82 83
83 surface_ = T::getTopPlatformDevice().beginPlatformPaint(); 84 context_ = T::getTopPlatformDevice().beginPlatformPaint();
84 } 85 }
85 86
86 cairo_surface_t* surface_; 87 cairo_t* context_;
87 GdkWindow* window_; 88 GdkWindow* window_;
88 GdkRectangle rectangle_; 89 GdkRectangle rectangle_;
89 // See description above setter. 90 // See description above setter.
90 bool composite_alpha_; 91 bool composite_alpha_;
91 92
92 // Disallow copy and assign. 93 // Disallow copy and assign.
93 CanvasPaintT(const CanvasPaintT&); 94 CanvasPaintT(const CanvasPaintT&);
94 CanvasPaintT& operator=(const CanvasPaintT&); 95 CanvasPaintT& operator=(const CanvasPaintT&);
95 }; 96 };
96 97
97 typedef CanvasPaintT<PlatformCanvas> PlatformCanvasPaint; 98 typedef CanvasPaintT<PlatformCanvas> PlatformCanvasPaint;
98 99
99 } // namespace skia 100 } // namespace skia
100 101
101 #endif // SKIA_EXT_CANVAS_PAINT_LINUX_H_ 102 #endif // SKIA_EXT_CANVAS_PAINT_LINUX_H_
OLDNEW
« no previous file with comments | « skia/ext/bitmap_platform_device_win.h ('k') | skia/ext/platform_canvas_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698