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