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/canvas_paint_common.h" |
11 #include "skia/ext/platform_canvas.h" | 11 #include "skia/ext/platform_canvas.h" |
12 | 12 |
13 #include <cairo/cairo.h> | 13 #include <cairo/cairo.h> |
14 | 14 |
15 namespace skia { | 15 namespace skia { |
16 | 16 |
17 // 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 |
18 // 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 |
19 // destruction, it will commit it to the Wayland window surface. | 19 // destruction, it will commit it to the Wayland window surface. |
| 20 // Note: The created context is always inialized to (0, 0, 0, 0). |
20 template <class T> | 21 template <class T> |
21 class CanvasPaintT : public T { | 22 class CanvasPaintT : public T { |
22 public: | 23 public: |
23 // This constructor assumes the result is opaque. | 24 // This constructor assumes the result is opaque. |
24 CanvasPaintT(cairo_surface_t* cairo_window_surface, | 25 CanvasPaintT(cairo_surface_t* cairo_window_surface, |
25 cairo_rectangle_t* region) | 26 cairo_rectangle_t* region) |
26 : context_(NULL), | 27 : context_(NULL), |
27 cairo_window_surface_(cairo_window_surface), | 28 cairo_window_surface_(cairo_window_surface), |
28 region_(region), | 29 region_(region), |
29 composite_alpha_(false) { | 30 composite_alpha_(false) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 return region_->width == 0 && region_->height == 0; | 82 return region_->width == 0 && region_->height == 0; |
82 } | 83 } |
83 | 84 |
84 private: | 85 private: |
85 void init(bool opaque) { | 86 void init(bool opaque) { |
86 PlatformCanvas* canvas = GetPlatformCanvas(this); | 87 PlatformCanvas* canvas = GetPlatformCanvas(this); |
87 if (!canvas->initialize(region_->width, region_->height, opaque, NULL)) { | 88 if (!canvas->initialize(region_->width, region_->height, opaque, NULL)) { |
88 // Cause a deliberate crash; | 89 // Cause a deliberate crash; |
89 CHECK(false); | 90 CHECK(false); |
90 } | 91 } |
| 92 // No need to clear the canvas, because cairo automatically performs the |
| 93 // clear. |
91 | 94 |
92 // Need to translate so that the dirty region appears at the origin of the | 95 // Need to translate so that the dirty region appears at the origin of the |
93 // surface. | 96 // surface. |
94 canvas->translate(-SkDoubleToScalar(region_->x), | 97 canvas->translate(-SkDoubleToScalar(region_->x), |
95 -SkDoubleToScalar(region_->y)); | 98 -SkDoubleToScalar(region_->y)); |
96 | 99 |
97 context_ = BeginPlatformPaint(canvas); | 100 context_ = BeginPlatformPaint(canvas); |
98 } | 101 } |
99 | 102 |
100 cairo_t* context_; | 103 cairo_t* context_; |
101 cairo_surface_t* cairo_window_surface_; | 104 cairo_surface_t* cairo_window_surface_; |
102 cairo_rectangle_t* region_; | 105 cairo_rectangle_t* region_; |
103 // See description above setter. | 106 // See description above setter. |
104 bool composite_alpha_; | 107 bool composite_alpha_; |
105 | 108 |
106 // Disallow copy and assign. | 109 // Disallow copy and assign. |
107 CanvasPaintT(const CanvasPaintT&); | 110 CanvasPaintT(const CanvasPaintT&); |
108 CanvasPaintT& operator=(const CanvasPaintT&); | 111 CanvasPaintT& operator=(const CanvasPaintT&); |
109 }; | 112 }; |
110 | 113 |
111 typedef CanvasPaintT<PlatformCanvas> PlatformCanvasPaint; | 114 typedef CanvasPaintT<PlatformCanvas> PlatformCanvasPaint; |
112 | 115 |
113 } // namespace skia | 116 } // namespace skia |
114 | 117 |
115 #endif // SKIA_EXT_CANVAS_PAINT_WAYLAND_H_ | 118 #endif // SKIA_EXT_CANVAS_PAINT_WAYLAND_H_ |
OLD | NEW |