OLD | NEW |
| (Empty) |
1 | |
2 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
3 // Use of this source code is governed by a BSD-style license that can be | |
4 // found in the LICENSE file. | |
5 | |
6 #ifndef UI_GFX_CANVAS_PAINT_LINUX_H_ | |
7 #define UI_GFX_CANVAS_PAINT_LINUX_H_ | |
8 | |
9 #include "base/logging.h" | |
10 #include "skia/ext/platform_canvas.h" | |
11 #include "ui/gfx/canvas.h" | |
12 #include <gdk/gdk.h> | |
13 | |
14 namespace gfx { | |
15 | |
16 // A class designed to translate skia painting into a region in a GdkWindow. | |
17 // On construction, it will set up a context for painting into, and on | |
18 // destruction, it will commit it to the GdkWindow. | |
19 // Note: The created context is always inialized to (0, 0, 0, 0). | |
20 class GFX_EXPORT CanvasSkiaPaint : public Canvas { | |
21 public: | |
22 // This constructor assumes the result is opaque. | |
23 explicit CanvasSkiaPaint(GdkEventExpose* event); | |
24 CanvasSkiaPaint(GdkEventExpose* event, bool opaque); | |
25 virtual ~CanvasSkiaPaint(); | |
26 | |
27 // Sets whether the bitmap is composited in such a way that the alpha channel | |
28 // is honored. This is only useful if you've enabled an RGBA colormap on the | |
29 // widget. The default is false. | |
30 void set_composite_alpha(bool composite_alpha) { | |
31 composite_alpha_ = composite_alpha; | |
32 } | |
33 | |
34 // Returns true if the invalid region is empty. The caller should call this | |
35 // function to determine if anything needs painting. | |
36 bool is_empty() const { | |
37 return gdk_region_empty(region_); | |
38 } | |
39 | |
40 GdkRectangle rectangle() const { | |
41 GdkRectangle bounds; | |
42 gdk_region_get_clipbox(region_, &bounds); | |
43 return bounds; | |
44 } | |
45 | |
46 private: | |
47 void Init(bool opaque); | |
48 | |
49 cairo_t* context_; | |
50 GdkWindow* window_; | |
51 GdkRegion* region_; | |
52 // See description above setter. | |
53 bool composite_alpha_; | |
54 | |
55 // Disallow copy and assign. | |
56 CanvasSkiaPaint(const CanvasSkiaPaint&); | |
57 CanvasSkiaPaint& operator=(const CanvasSkiaPaint&); | |
58 }; | |
59 | |
60 // A class designed to translate skia painting into a region in a Cairo context. | |
61 // On construction, it will set up a context for painting into, and on | |
62 // destruction, it will commit it to the Cairo context. If there are any | |
63 // transformations applied to the Cairo context, they will affect the drawing. | |
64 class GFX_EXPORT CanvasSkiaPaintCairo : public Canvas { | |
65 public: | |
66 CanvasSkiaPaintCairo(cairo_t* cairo, Size size, bool opaque); | |
67 virtual ~CanvasSkiaPaintCairo(); | |
68 | |
69 // Sets whether the bitmap is composited in such a way that the alpha channel | |
70 // is honored. This is only useful if you've enabled an RGBA colormap on the | |
71 // widget. The default is false. | |
72 void set_composite_alpha(bool composite_alpha) { | |
73 composite_alpha_ = composite_alpha; | |
74 } | |
75 | |
76 // Returns true if size of the drawing region is empty. The caller should call | |
77 // this function to determine if anything needs painting. | |
78 bool is_empty() const { | |
79 return size_.IsEmpty(); | |
80 } | |
81 | |
82 Size size() const { | |
83 return size_; | |
84 } | |
85 | |
86 private: | |
87 void Init(bool opaque); | |
88 | |
89 cairo_t* context_; | |
90 cairo_t* dest_; | |
91 Size size_; | |
92 // See description above setter. | |
93 bool composite_alpha_; | |
94 | |
95 // Disallow copy and assign. | |
96 CanvasSkiaPaintCairo(const CanvasSkiaPaintCairo&); | |
97 CanvasSkiaPaintCairo& operator=(const CanvasSkiaPaintCairo&); | |
98 }; | |
99 | |
100 } // namespace gfx | |
101 | |
102 #endif // UI_GFX_CANVAS_PAINT_LINUX_H_ | |
OLD | NEW |