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