Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(563)

Side by Side Diff: skia/ext/canvas_paint_wayland.h

Issue 8122013: Allow CanvasSkia to bind to an existing SkCanvas. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: 1 more fix Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 namespace skia { 13 namespace skia {
13 14
14 // 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
15 // 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
16 // destruction, it will commit it to the Wayland window surface. 17 // destruction, it will commit it to the Wayland window surface.
17 template <class T> 18 template <class T>
18 class CanvasPaintT : public T { 19 class CanvasPaintT : public T {
19 public: 20 public:
(...skipping 12 matching lines...) Expand all
32 bool opaque) 33 bool opaque)
33 : context_(NULL), 34 : context_(NULL),
34 cairo_window_surface_(cairo_window_surface), 35 cairo_window_surface_(cairo_window_surface),
35 region_(region), 36 region_(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 PlatformCanvas* canvas = GetPlatformCanvas(this);
44 canvas->restoreToCount(1);
43 45
44 // Blit the dirty rect to the window. 46 // Blit the dirty rect to the window.
45 CHECK(cairo_window_surface_); 47 CHECK(cairo_window_surface_);
46 cairo_t* cr = cairo_create(cairo_window_surface_); 48 cairo_t* cr = cairo_create(cairo_window_surface_);
47 CHECK(cr); 49 CHECK(cr);
48 50
49 if (composite_alpha_) 51 if (composite_alpha_)
50 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); 52 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
51 53
52 cairo_surface_t* source_surface = cairo_get_target(context_); 54 cairo_surface_t* source_surface = cairo_get_target(context_);
(...skipping 19 matching lines...) Expand all
72 } 74 }
73 75
74 // Returns true if the invalid region is empty. The caller should call this 76 // Returns true if the invalid region is empty. The caller should call this
75 // function to determine if anything needs painting. 77 // function to determine if anything needs painting.
76 bool is_empty() const { 78 bool is_empty() const {
77 return region_->width == 0 && region_->height == 0; 79 return region_->width == 0 && region_->height == 0;
78 } 80 }
79 81
80 private: 82 private:
81 void init(bool opaque) { 83 void init(bool opaque) {
82 if (!T::initialize(region_->width, region_->height, opaque, NULL)) { 84 PlatformCanvas* canvas = GetPlatformCanvas(this);
85 if (!canvas->initialize(region_->width, region_->height, opaque, NULL)) {
83 // Cause a deliberate crash; 86 // Cause a deliberate crash;
84 CHECK(false); 87 CHECK(false);
85 } 88 }
86 89
87 // Need to translate so that the dirty region appears at the origin of the 90 // Need to translate so that the dirty region appears at the origin of the
88 // surface. 91 // surface.
89 T::translate(-SkIntToScalar(region_->x), -SkIntToScalar(region_->y)); 92 canvas->translate(-SkIntToScalar(region_->x), -SkIntToScalar(region_->y));
90 93
91 context_ = BeginPlatformPaint(this); 94 context_ = BeginPlatformPaint(canvas);
92 } 95 }
93 96
94 cairo_t* context_; 97 cairo_t* context_;
95 cairo_surface_t* cairo_window_surface_; 98 cairo_surface_t* cairo_window_surface_;
96 cairo_rectangle_int_t* region_; 99 cairo_rectangle_int_t* region_;
97 // See description above setter. 100 // See description above setter.
98 bool composite_alpha_; 101 bool composite_alpha_;
99 102
100 // Disallow copy and assign. 103 // Disallow copy and assign.
101 CanvasPaintT(const CanvasPaintT&); 104 CanvasPaintT(const CanvasPaintT&);
102 CanvasPaintT& operator=(const CanvasPaintT&); 105 CanvasPaintT& operator=(const CanvasPaintT&);
103 }; 106 };
104 107
105 typedef CanvasPaintT<PlatformCanvas> PlatformCanvasPaint; 108 typedef CanvasPaintT<PlatformCanvas> PlatformCanvasPaint;
106 109
107 } // namespace skia 110 } // namespace skia
108 111
109 #endif // SKIA_EXT_CANVAS_PAINT_WAYLAND_H_ 112 #endif // SKIA_EXT_CANVAS_PAINT_WAYLAND_H_
OLDNEW
« no previous file with comments | « skia/ext/canvas_paint_mac.h ('k') | skia/ext/canvas_paint_win.h » ('j') | ui/gfx/canvas.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698