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

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

Issue 119226: Adds ability to change compositing operator used by CanvasPaint.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef SKIA_EXT_PLATFORM_CANVAS_LINUX_H_ 5 #ifndef SKIA_EXT_PLATFORM_CANVAS_LINUX_H_
6 #define SKIA_EXT_PLATFORM_CANVAS_LINUX_H_ 6 #define SKIA_EXT_PLATFORM_CANVAS_LINUX_H_
7 7
8 #include <unistd.h> 8 #include <unistd.h>
9 9
10 #include "skia/ext/platform_device_linux.h" 10 #include "skia/ext/platform_device_linux.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 // A class designed to translate skia painting into a region in a 71 // A class designed to translate skia painting into a region in a
72 // GdkWindow. This class has been adapted from the class with the same name in 72 // GdkWindow. This class has been adapted from the class with the same name in
73 // platform_canvas_win.h. On construction, it will set up a context for 73 // platform_canvas_win.h. On construction, it will set up a context for
74 // painting into, and on destruction, it will commit it to the GdkWindow. 74 // painting into, and on destruction, it will commit it to the GdkWindow.
75 template <class T> 75 template <class T>
76 class CanvasPaintT : public T { 76 class CanvasPaintT : public T {
77 public: 77 public:
78 explicit CanvasPaintT(GdkEventExpose* event) 78 explicit CanvasPaintT(GdkEventExpose* event)
79 : surface_(NULL), 79 : surface_(NULL),
80 window_(event->window), 80 window_(event->window),
81 rectangle_(event->area) { 81 rectangle_(event->area),
82 composite_alpha_(false) {
82 init(true); 83 init(true);
83 } 84 }
84 85
85 CanvasPaintT(GdkEventExpose* event, bool opaque) 86 CanvasPaintT(GdkEventExpose* event, bool opaque)
86 : surface_(NULL), 87 : surface_(NULL),
87 window_(event->window), 88 window_(event->window),
88 rectangle_(event->area) { 89 rectangle_(event->area),
90 composite_alpha_(false) {
89 init(opaque); 91 init(opaque);
90 } 92 }
91 93
92 virtual ~CanvasPaintT() { 94 virtual ~CanvasPaintT() {
93 if (!isEmpty()) { 95 if (!isEmpty()) {
94 T::restoreToCount(1); 96 T::restoreToCount(1);
95 97
96 // Blit the dirty rect to the window. 98 // Blit the dirty rect to the window.
97 cairo_t* cr = gdk_cairo_create(window_); 99 cairo_t* cr = gdk_cairo_create(window_);
100 if (composite_alpha_)
101 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
98 cairo_set_source_surface(cr, surface_, rectangle_.x, rectangle_.y); 102 cairo_set_source_surface(cr, surface_, rectangle_.x, rectangle_.y);
99 cairo_rectangle(cr, rectangle_.x, rectangle_.y, 103 cairo_rectangle(cr, rectangle_.x, rectangle_.y,
100 rectangle_.width, rectangle_.height); 104 rectangle_.width, rectangle_.height);
101 cairo_fill(cr); 105 cairo_fill(cr);
102 cairo_destroy(cr); 106 cairo_destroy(cr);
103 } 107 }
104 } 108 }
105 109
110 // Sets whether the bitmap is composited in such a way that the alpha channel
111 // is honored. This is only useful if you've enabled an RGBA colormap on the
112 // widget. The default is false.
113 void set_composite_alpha(bool composite_alpha) {
114 composite_alpha_ = composite_alpha;
115 }
116
106 // Returns true if the invalid region is empty. The caller should call this 117 // Returns true if the invalid region is empty. The caller should call this
107 // function to determine if anything needs painting. 118 // function to determine if anything needs painting.
108 bool isEmpty() const { 119 bool isEmpty() const {
109 return rectangle_.width == 0 || rectangle_.height == 0; 120 return rectangle_.width == 0 || rectangle_.height == 0;
110 } 121 }
111 122
112 const GdkRectangle& rectangle() const { 123 const GdkRectangle& rectangle() const {
113 return rectangle_; 124 return rectangle_;
114 } 125 }
115 126
116 private: 127 private:
117 void init(bool opaque) { 128 void init(bool opaque) {
118 if (!T::initialize(rectangle_.width, rectangle_.height, opaque, NULL)) { 129 if (!T::initialize(rectangle_.width, rectangle_.height, opaque, NULL)) {
119 // Cause a deliberate crash; 130 // Cause a deliberate crash;
120 *(char*) 0 = 0; 131 *(char*) 0 = 0;
121 } 132 }
122 133
123 // Need to translate so that the dirty region appears at the origin of the 134 // Need to translate so that the dirty region appears at the origin of the
124 // surface. 135 // surface.
125 T::translate(-SkIntToScalar(rectangle_.x), -SkIntToScalar(rectangle_.y)); 136 T::translate(-SkIntToScalar(rectangle_.x), -SkIntToScalar(rectangle_.y));
126 137
127 surface_ = T::getTopPlatformDevice().beginPlatformPaint(); 138 surface_ = T::getTopPlatformDevice().beginPlatformPaint();
128 } 139 }
129 140
130 cairo_surface_t* surface_; 141 cairo_surface_t* surface_;
131 GdkWindow* window_; 142 GdkWindow* window_;
132 GdkRectangle rectangle_; 143 GdkRectangle rectangle_;
144 // See description above setter.
145 bool composite_alpha_;
133 146
134 // Disallow copy and assign. 147 // Disallow copy and assign.
135 CanvasPaintT(const CanvasPaintT&); 148 CanvasPaintT(const CanvasPaintT&);
136 CanvasPaintT& operator=(const CanvasPaintT&); 149 CanvasPaintT& operator=(const CanvasPaintT&);
137 }; 150 };
138 151
139 } // namespace skia 152 } // namespace skia
140 153
141 #endif // SKIA_EXT_PLATFORM_CANVAS_LINUX_H_ 154 #endif // SKIA_EXT_PLATFORM_CANVAS_LINUX_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698