1 // Copyright (c) 2012 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.
5 #include "base/basictypes.h"
6 #include "base/compiler_specific.h"
7 #include "ui/gfx/canvas.h"
8 #include "ui/gfx/canvas_skia_paint.h"
9 #include "ui/gfx/rect.h"
13 CanvasSkiaPaint::CanvasSkiaPaint(GdkEventExpose
* event
)
15 window_(event
->window
),
16 region_(gdk_region_copy(event
->region
)),
17 composite_alpha_(false) {
21 CanvasSkiaPaint::CanvasSkiaPaint(GdkEventExpose
* event
, bool opaque
)
23 window_(event
->window
),
24 region_(gdk_region_copy(event
->region
)),
25 composite_alpha_(false) {
29 CanvasSkiaPaint::~CanvasSkiaPaint() {
31 platform_canvas()->restoreToCount(1);
33 // Blit the dirty rect to the window.
35 cairo_t
* cr
= gdk_cairo_create(window_
);
38 cairo_set_operator(cr
, CAIRO_OPERATOR_SOURCE
);
39 cairo_surface_t
* source_surface
= cairo_get_target(context_
);
40 CHECK(source_surface
);
41 // Flush cairo's cache of the surface.
42 cairo_surface_mark_dirty(source_surface
);
43 GdkRectangle bounds
= rectangle();
44 cairo_set_source_surface(cr
, source_surface
, bounds
.x
, bounds
.y
);
45 gdk_cairo_region(cr
, region_
);
50 gdk_region_destroy(region_
);
53 void CanvasSkiaPaint::Init(bool opaque
) {
54 GdkRectangle bounds
= rectangle();
55 RecreateBackingCanvas(gfx::Size(bounds
.width
, bounds
.height
),
56 ui::SCALE_FACTOR_100P
, opaque
);
58 skia::PlatformCanvas
* canvas
= platform_canvas();
60 // Need to translate so that the dirty region appears at the origin of the
62 canvas
->translate(-SkIntToScalar(bounds
.x
), -SkIntToScalar(bounds
.y
));
64 context_
= skia::BeginPlatformPaint(canvas
);