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

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

Issue 7464027: Wayland support for views. views_desktop on Wayland. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Merged native_menu_wayland and native_menu_x and styling fixes Created 9 years, 4 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef SKIA_EXT_CANVAS_PAINT_WAYLAND_H_
6 #define SKIA_EXT_CANVAS_PAINT_WAYLAND_H_
7 #pragma once
8
9 #include "base/logging.h"
10 #include "skia/ext/platform_canvas.h"
11
12 namespace skia {
13
14 // 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 // destruction, it will commit it to the Wayland window surface.
17 template <class T>
18 class CanvasPaintT : public T {
19 public:
20 // This constructor assumes the result is opaque.
21 explicit CanvasPaintT(cairo_surface_t* cairo_window_surface,
sadrul 2011/08/22 18:44:11 Remove 'explicit'
22 cairo_rectangle_int_t* region)
23 : context_(NULL),
24 cairo_window_surface_(cairo_window_surface),
25 region_(region),
26 composite_alpha_(false) {
27 init(true);
28 }
29
30 CanvasPaintT(cairo_surface_t* cairo_window_surface,
31 cairo_rectangle_int_t* region,
32 bool opaque)
33 : context_(NULL),
34 cairo_window_surface_(cairo_window_surface),
35 region_(region),
36 composite_alpha_(false) {
37 init(opaque);
38 }
39
40 virtual ~CanvasPaintT() {
41 if (!is_empty()) {
42 T::restoreToCount(1);
43
44 // Blit the dirty rect to the window.
45 CHECK(cairo_window_surface_);
46 cairo_t* cr = cairo_create(cairo_window_surface_);
47 CHECK(cr);
48
49 if (composite_alpha_)
50 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
51
52 cairo_surface_t* source_surface = cairo_get_target(context_);
53 CHECK(source_surface);
54 // Flush cairo's cache of the surface.
55 cairo_surface_mark_dirty(source_surface);
56 cairo_set_source_surface(cr, source_surface, region_->x, region_->y);
57 cairo_rectangle(cr,
58 region_->x,
59 region_->y,
60 region_->width,
61 region_->height);
62 cairo_fill(cr);
63 cairo_destroy(cr);
64 }
65 }
66
67 // Sets whether the bitmap is composited in such a way that the alpha channel
68 // is honored. This is only useful if you've enabled an RGBA colormap on the
69 // widget. The default is false.
70 void set_composite_alpha(bool composite_alpha) {
71 composite_alpha_ = composite_alpha;
72 }
73
74 // Returns true if the invalid region is empty. The caller should call this
75 // function to determine if anything needs painting.
76 bool is_empty() const {
77 return region_->width == 0 && region_->height == 0;
78 }
79
80 private:
81 void init(bool opaque) {
82 if (!T::initialize(region_->width, region_->height, opaque, NULL)) {
83 // Cause a deliberate crash;
84 CHECK(false);
85 }
86
87 // Need to translate so that the dirty region appears at the origin of the
88 // surface.
89 T::translate(-SkIntToScalar(region_->x), -SkIntToScalar(region_->y));
90
91 context_ = BeginPlatformPaint(this);
92 }
93
94 cairo_t* context_;
95 cairo_surface_t* cairo_window_surface_;
96 cairo_rectangle_int_t* region_;
97 // See description above setter.
98 bool composite_alpha_;
99
100 // Disallow copy and assign.
101 CanvasPaintT(const CanvasPaintT&);
102 CanvasPaintT& operator=(const CanvasPaintT&);
103 };
104
105 typedef CanvasPaintT<PlatformCanvas> PlatformCanvasPaint;
106
107 } // namespace skia
108
109 #endif // SKIA_EXT_CANVAS_PAINT_WAYLAND_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698