Add a basic settings page with a Polymer paper element which loads at chrome://md...
[chromium-blink-merge.git] / ui / gfx / canvas_paint_win.cc
blobc2104fb37caafb3c36fbc52a1e89d46dd30ca76a
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/geometry/rect.h"
11 namespace gfx {
13 CanvasSkiaPaint::CanvasSkiaPaint(HWND hwnd, HDC dc, const PAINTSTRUCT& ps)
14 : hwnd_(hwnd),
15 paint_dc_(dc) {
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;
21 Init(true);
24 CanvasSkiaPaint::CanvasSkiaPaint(HDC dc, bool opaque, int x, int y,
25 int w, int h)
26 : hwnd_(NULL),
27 paint_dc_(dc) {
28 memset(&ps_, 0, sizeof(ps_));
29 ps_.rcPaint.left = x;
30 ps_.rcPaint.right = x + w;
31 ps_.rcPaint.top = y;
32 ps_.rcPaint.bottom = y + h;
33 Init(opaque);
36 CanvasSkiaPaint::~CanvasSkiaPaint() {
37 if (!is_empty()) {
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
64 // dirty rect
65 canvas->translate(
66 -ps_.rcPaint.left / gfx::GetDPIScale(),
67 -ps_.rcPaint.top / gfx::GetDPIScale());
70 } // namespace gfx