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(HWND hwnd
, HDC dc
, const PAINTSTRUCT
& ps
)
16 memset(&ps_
, 0, sizeof(ps_
));
17 ps_
.rcPaint
.left
= ps
.rcPaint
.left
;
18 ps_
.rcPaint
.right
= ps
.rcPaint
.right
;
19 ps_
.rcPaint
.top
= ps
.rcPaint
.top
;
20 ps_
.rcPaint
.bottom
= ps
.rcPaint
.bottom
;
24 CanvasSkiaPaint::CanvasSkiaPaint(HDC dc
, bool opaque
, int x
, int y
,
28 memset(&ps_
, 0, sizeof(ps_
));
30 ps_
.rcPaint
.right
= x
+ w
;
32 ps_
.rcPaint
.bottom
= y
+ h
;
36 CanvasSkiaPaint::~CanvasSkiaPaint() {
38 skia::PlatformCanvas
* canvas
= platform_canvas();
39 canvas
->restoreToCount(1);
40 // Commit the drawing to the screen
41 skia::DrawToNativeContext(canvas
, paint_dc_
, ps_
.rcPaint
.left
,
42 ps_
.rcPaint
.top
, NULL
);
46 gfx::Rect
CanvasSkiaPaint::GetInvalidRect() const {
47 return gfx::Rect(paint_struct().rcPaint
);
50 void CanvasSkiaPaint::Init(bool opaque
) {
51 // FIXME(brettw) for ClearType, we probably want to expand the bounds of
52 // painting by one pixel so that the boundaries will be correct (ClearType
53 // text can depend on the adjacent pixel). Then we would paint just the
54 // inset pixels to the screen.
55 const int width
= ps_
.rcPaint
.right
- ps_
.rcPaint
.left
;
56 const int height
= ps_
.rcPaint
.bottom
- ps_
.rcPaint
.top
;
58 RecreateBackingCanvas(gfx::Size(width
, height
), gfx::GetDPIScale(), opaque
);
59 skia::PlatformCanvas
* canvas
= platform_canvas();
61 canvas
->clear(SkColorSetARGB(0, 0, 0, 0));
63 // This will bring the canvas into the screen coordinate system for the
66 -ps_
.rcPaint
.left
/ gfx::GetDPIScale(),
67 -ps_
.rcPaint
.top
/ gfx::GetDPIScale());