| 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/canvas_paint_common.h" |
| 12 #include "skia/ext/platform_canvas.h" | 12 #include "skia/ext/platform_canvas.h" |
| 13 | 13 |
| 14 #include <gdk/gdk.h> | 14 #include <gdk/gdk.h> |
| 15 | 15 |
| 16 namespace skia { | 16 namespace skia { |
| 17 | 17 |
| 18 // 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. |
| 19 // 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 |
| 20 // destruction, it will commit it to the GdkWindow. | 20 // destruction, it will commit it to the GdkWindow. |
| 21 // Note: The created context is always inialized to (0, 0, 0, 0). |
| 21 template <class T> | 22 template <class T> |
| 22 class CanvasPaintT : public T { | 23 class CanvasPaintT : public T { |
| 23 public: | 24 public: |
| 24 // This constructor assumes the result is opaque. | 25 // This constructor assumes the result is opaque. |
| 25 explicit CanvasPaintT(GdkEventExpose* event) | 26 explicit CanvasPaintT(GdkEventExpose* event) |
| 26 : context_(NULL), | 27 : context_(NULL), |
| 27 window_(event->window), | 28 window_(event->window), |
| 28 region_(gdk_region_copy(event->region)), | 29 region_(gdk_region_copy(event->region)), |
| 29 composite_alpha_(false) { | 30 composite_alpha_(false) { |
| 30 init(true); | 31 init(true); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 } | 83 } |
| 83 | 84 |
| 84 private: | 85 private: |
| 85 void init(bool opaque) { | 86 void init(bool opaque) { |
| 86 GdkRectangle bounds = rectangle(); | 87 GdkRectangle bounds = rectangle(); |
| 87 PlatformCanvas* canvas = GetPlatformCanvas(this); | 88 PlatformCanvas* canvas = GetPlatformCanvas(this); |
| 88 if (!canvas->initialize(bounds.width, bounds.height, opaque, NULL)) { | 89 if (!canvas->initialize(bounds.width, bounds.height, opaque, NULL)) { |
| 89 // Cause a deliberate crash; | 90 // Cause a deliberate crash; |
| 90 CHECK(false); | 91 CHECK(false); |
| 91 } | 92 } |
| 93 // No need to clear the canvas, because cairo automatically performs the |
| 94 // clear. |
| 92 | 95 |
| 93 // Need to translate so that the dirty region appears at the origin of the | 96 // Need to translate so that the dirty region appears at the origin of the |
| 94 // surface. | 97 // surface. |
| 95 canvas->translate(-SkIntToScalar(bounds.x), -SkIntToScalar(bounds.y)); | 98 canvas->translate(-SkIntToScalar(bounds.x), -SkIntToScalar(bounds.y)); |
| 96 | 99 |
| 97 context_ = BeginPlatformPaint(canvas); | 100 context_ = BeginPlatformPaint(canvas); |
| 98 } | 101 } |
| 99 | 102 |
| 100 cairo_t* context_; | 103 cairo_t* context_; |
| 101 GdkWindow* window_; | 104 GdkWindow* window_; |
| 102 GdkRegion* region_; | 105 GdkRegion* 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_LINUX_H_ | 118 #endif // SKIA_EXT_CANVAS_PAINT_LINUX_H_ |
| OLD | NEW |