OLD | NEW |
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_WIN_H_ | 5 #ifndef SKIA_EXT_CANVAS_PAINT_WIN_H_ |
6 #define SKIA_EXT_CANVAS_PAINT_WIN_H_ | 6 #define SKIA_EXT_CANVAS_PAINT_WIN_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "skia/ext/canvas_paint_common.h" | 9 #include "skia/ext/canvas_paint_common.h" |
10 #include "skia/ext/platform_canvas.h" | 10 #include "skia/ext/platform_canvas.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 // case. | 22 // case. |
23 // | 23 // |
24 // Therefore, all you need to do is: | 24 // Therefore, all you need to do is: |
25 // case WM_PAINT: { | 25 // case WM_PAINT: { |
26 // gfx::PlatformCanvasPaint canvas(hwnd); | 26 // gfx::PlatformCanvasPaint canvas(hwnd); |
27 // if (!canvas.isEmpty()) { | 27 // if (!canvas.isEmpty()) { |
28 // ... paint to the canvas ... | 28 // ... paint to the canvas ... |
29 // } | 29 // } |
30 // return 0; | 30 // return 0; |
31 // } | 31 // } |
| 32 // Note: The created context is always inialized to (0, 0, 0, 0). |
32 template <class T> | 33 template <class T> |
33 class CanvasPaintT : public T { | 34 class CanvasPaintT : public T { |
34 public: | 35 public: |
35 // This constructor assumes the canvas is opaque. | 36 // This constructor assumes the canvas is opaque. |
36 explicit CanvasPaintT(HWND hwnd) : hwnd_(hwnd), paint_dc_(NULL), | 37 explicit CanvasPaintT(HWND hwnd) : hwnd_(hwnd), paint_dc_(NULL), |
37 for_paint_(true) { | 38 for_paint_(true) { |
38 memset(&ps_, 0, sizeof(ps_)); | 39 memset(&ps_, 0, sizeof(ps_)); |
39 initPaint(true); | 40 initPaint(true); |
40 } | 41 } |
41 | 42 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 // FIXME(brettw) for ClearType, we probably want to expand the bounds of | 107 // FIXME(brettw) for ClearType, we probably want to expand the bounds of |
107 // painting by one pixel so that the boundaries will be correct (ClearType | 108 // painting by one pixel so that the boundaries will be correct (ClearType |
108 // text can depend on the adjacent pixel). Then we would paint just the | 109 // text can depend on the adjacent pixel). Then we would paint just the |
109 // inset pixels to the screen. | 110 // inset pixels to the screen. |
110 const int width = ps_.rcPaint.right - ps_.rcPaint.left; | 111 const int width = ps_.rcPaint.right - ps_.rcPaint.left; |
111 const int height = ps_.rcPaint.bottom - ps_.rcPaint.top; | 112 const int height = ps_.rcPaint.bottom - ps_.rcPaint.top; |
112 if (!canvas->initialize(width, height, opaque, NULL)) { | 113 if (!canvas->initialize(width, height, opaque, NULL)) { |
113 // Cause a deliberate crash; | 114 // Cause a deliberate crash; |
114 *(char*) 0 = 0; | 115 *(char*) 0 = 0; |
115 } | 116 } |
| 117 canvas->clear(SkColorSetARGB(0, 0, 0, 0)); |
116 | 118 |
117 // This will bring the canvas into the screen coordinate system for the | 119 // This will bring the canvas into the screen coordinate system for the |
118 // dirty rect | 120 // dirty rect |
119 canvas->translate(SkIntToScalar(-ps_.rcPaint.left), | 121 canvas->translate(SkIntToScalar(-ps_.rcPaint.left), |
120 SkIntToScalar(-ps_.rcPaint.top)); | 122 SkIntToScalar(-ps_.rcPaint.top)); |
121 } | 123 } |
122 | 124 |
123 // If true, this canvas was created for a BeginPaint. | 125 // If true, this canvas was created for a BeginPaint. |
124 const bool for_paint_; | 126 const bool for_paint_; |
125 | 127 |
126 // Disallow copy and assign. | 128 // Disallow copy and assign. |
127 CanvasPaintT(const CanvasPaintT&); | 129 CanvasPaintT(const CanvasPaintT&); |
128 CanvasPaintT& operator=(const CanvasPaintT&); | 130 CanvasPaintT& operator=(const CanvasPaintT&); |
129 }; | 131 }; |
130 | 132 |
131 typedef CanvasPaintT<PlatformCanvas> PlatformCanvasPaint; | 133 typedef CanvasPaintT<PlatformCanvas> PlatformCanvasPaint; |
132 | 134 |
133 } // namespace skia | 135 } // namespace skia |
134 | 136 |
135 #endif // SKIA_EXT_CANVAS_PAINT_WIN_H_ | 137 #endif // SKIA_EXT_CANVAS_PAINT_WIN_H_ |
OLD | NEW |