OLD | NEW |
1 | 1 |
2 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 #pragma once | 8 #pragma once |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "skia/ext/canvas_paint_common.h" |
11 #include "skia/ext/platform_canvas.h" | 12 #include "skia/ext/platform_canvas.h" |
12 | 13 |
13 #include <gdk/gdk.h> | 14 #include <gdk/gdk.h> |
14 | 15 |
15 namespace skia { | 16 namespace skia { |
16 | 17 |
17 // A class designed to translate skia painting into a region in a GdkWindow. | 18 // A class designed to translate skia painting into a region in a GdkWindow. |
18 // On construction, it will set up a context for painting into, and on | 19 // On construction, it will set up a context for painting into, and on |
19 // destruction, it will commit it to the GdkWindow. | 20 // destruction, it will commit it to the GdkWindow. |
20 template <class T> | 21 template <class T> |
(...skipping 11 matching lines...) Expand all Loading... |
32 CanvasPaintT(GdkEventExpose* event, bool opaque) | 33 CanvasPaintT(GdkEventExpose* event, bool opaque) |
33 : context_(NULL), | 34 : context_(NULL), |
34 window_(event->window), | 35 window_(event->window), |
35 region_(gdk_region_copy(event->region)), | 36 region_(gdk_region_copy(event->region)), |
36 composite_alpha_(false) { | 37 composite_alpha_(false) { |
37 init(opaque); | 38 init(opaque); |
38 } | 39 } |
39 | 40 |
40 virtual ~CanvasPaintT() { | 41 virtual ~CanvasPaintT() { |
41 if (!is_empty()) { | 42 if (!is_empty()) { |
42 T::restoreToCount(1); | 43 GetPlatformCanvas(this)->restoreToCount(1); |
43 | 44 |
44 // Blit the dirty rect to the window. | 45 // Blit the dirty rect to the window. |
45 CHECK(window_); | 46 CHECK(window_); |
46 cairo_t* cr = gdk_cairo_create(window_); | 47 cairo_t* cr = gdk_cairo_create(window_); |
47 CHECK(cr); | 48 CHECK(cr); |
48 if (composite_alpha_) | 49 if (composite_alpha_) |
49 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); | 50 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
50 cairo_surface_t* source_surface = cairo_get_target(context_); | 51 cairo_surface_t* source_surface = cairo_get_target(context_); |
51 CHECK(source_surface); | 52 CHECK(source_surface); |
52 // Flush cairo's cache of the surface. | 53 // Flush cairo's cache of the surface. |
(...skipping 23 matching lines...) Expand all Loading... |
76 | 77 |
77 GdkRectangle rectangle() const { | 78 GdkRectangle rectangle() const { |
78 GdkRectangle bounds; | 79 GdkRectangle bounds; |
79 gdk_region_get_clipbox(region_, &bounds); | 80 gdk_region_get_clipbox(region_, &bounds); |
80 return bounds; | 81 return bounds; |
81 } | 82 } |
82 | 83 |
83 private: | 84 private: |
84 void init(bool opaque) { | 85 void init(bool opaque) { |
85 GdkRectangle bounds = rectangle(); | 86 GdkRectangle bounds = rectangle(); |
86 if (!T::initialize(bounds.width, bounds.height, opaque, NULL)) { | 87 PlatformCanvas* canvas = GetPlatformCanvas(this); |
| 88 if (!canvas->initialize(bounds.width, bounds.height, opaque, NULL)) { |
87 // Cause a deliberate crash; | 89 // Cause a deliberate crash; |
88 CHECK(false); | 90 CHECK(false); |
89 } | 91 } |
90 | 92 |
91 // Need to translate so that the dirty region appears at the origin of the | 93 // Need to translate so that the dirty region appears at the origin of the |
92 // surface. | 94 // surface. |
93 T::translate(-SkIntToScalar(bounds.x), -SkIntToScalar(bounds.y)); | 95 canvas->translate(-SkIntToScalar(bounds.x), -SkIntToScalar(bounds.y)); |
94 | 96 |
95 context_ = BeginPlatformPaint(this); | 97 context_ = BeginPlatformPaint(canvas); |
96 } | 98 } |
97 | 99 |
98 cairo_t* context_; | 100 cairo_t* context_; |
99 GdkWindow* window_; | 101 GdkWindow* window_; |
100 GdkRegion* region_; | 102 GdkRegion* region_; |
101 // See description above setter. | 103 // See description above setter. |
102 bool composite_alpha_; | 104 bool composite_alpha_; |
103 | 105 |
104 // Disallow copy and assign. | 106 // Disallow copy and assign. |
105 CanvasPaintT(const CanvasPaintT&); | 107 CanvasPaintT(const CanvasPaintT&); |
106 CanvasPaintT& operator=(const CanvasPaintT&); | 108 CanvasPaintT& operator=(const CanvasPaintT&); |
107 }; | 109 }; |
108 | 110 |
109 typedef CanvasPaintT<PlatformCanvas> PlatformCanvasPaint; | 111 typedef CanvasPaintT<PlatformCanvas> PlatformCanvasPaint; |
110 | 112 |
111 } // namespace skia | 113 } // namespace skia |
112 | 114 |
113 #endif // SKIA_EXT_CANVAS_PAINT_LINUX_H_ | 115 #endif // SKIA_EXT_CANVAS_PAINT_LINUX_H_ |
OLD | NEW |