| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 BASE_GFX_PLATFORM_CANVAS_WIN_H_ | 5 #ifndef BASE_GFX_PLATFORM_CANVAS_WIN_H_ |
| 6 #define BASE_GFX_PLATFORM_CANVAS_WIN_H_ | 6 #define BASE_GFX_PLATFORM_CANVAS_WIN_H_ |
| 7 | 7 |
| 8 #include "base/gfx/platform_device_win.h" | 8 #include "base/gfx/platform_device_win.h" |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 // parameter is passed to gfx::PlatformDevice::create. See it for details. | 22 // parameter is passed to gfx::PlatformDevice::create. See it for details. |
| 23 // | 23 // |
| 24 // If you use the version with no arguments, you MUST call initialize() | 24 // If you use the version with no arguments, you MUST call initialize() |
| 25 PlatformCanvasWin(); | 25 PlatformCanvasWin(); |
| 26 PlatformCanvasWin(int width, int height, bool is_opaque); | 26 PlatformCanvasWin(int width, int height, bool is_opaque); |
| 27 PlatformCanvasWin(int width, int height, bool is_opaque, | 27 PlatformCanvasWin(int width, int height, bool is_opaque, |
| 28 HANDLE shared_section); | 28 HANDLE shared_section); |
| 29 virtual ~PlatformCanvasWin(); | 29 virtual ~PlatformCanvasWin(); |
| 30 | 30 |
| 31 // For two-part init, call if you use the no-argument constructor above | 31 // For two-part init, call if you use the no-argument constructor above |
| 32 void initialize(int width, int height, bool is_opaque, HANDLE shared_section); | 32 bool initialize(int width, int height, bool is_opaque, HANDLE shared_section); |
| 33 | 33 |
| 34 // These calls should surround calls to platform drawing routines, the DC | 34 // These calls should surround calls to platform drawing routines, the DC |
| 35 // returned by beginPlatformPaint is the DC that can be used to draw into. | 35 // returned by beginPlatformPaint is the DC that can be used to draw into. |
| 36 // Call endPlatformPaint when you are done and want to use Skia operations | 36 // Call endPlatformPaint when you are done and want to use Skia operations |
| 37 // again; this will synchronize the bitmap to Windows. | 37 // again; this will synchronize the bitmap to Windows. |
| 38 virtual HDC beginPlatformPaint(); | 38 virtual HDC beginPlatformPaint(); |
| 39 virtual void endPlatformPaint(); | 39 virtual void endPlatformPaint(); |
| 40 | 40 |
| 41 // Returns the platform device pointer of the topmost rect with a non-empty | 41 // Returns the platform device pointer of the topmost rect with a non-empty |
| 42 // clip. In practice, this is usually either the top layer or nothing, since | 42 // clip. In practice, this is usually either the top layer or nothing, since |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 // case WM_PAINT: { | 86 // case WM_PAINT: { |
| 87 // gfx::PlatformCanvasWinPaint canvas(hwnd); | 87 // gfx::PlatformCanvasWinPaint canvas(hwnd); |
| 88 // if (!canvas.isEmpty()) { | 88 // if (!canvas.isEmpty()) { |
| 89 // ... paint to the canvas ... | 89 // ... paint to the canvas ... |
| 90 // } | 90 // } |
| 91 // return 0; | 91 // return 0; |
| 92 // } | 92 // } |
| 93 template <class T> | 93 template <class T> |
| 94 class CanvasPaintT : public T { | 94 class CanvasPaintT : public T { |
| 95 public: | 95 public: |
| 96 CanvasPaintT(HWND hwnd) : hwnd_(hwnd), for_paint_(true) { | 96 CanvasPaintT(HWND hwnd) : hwnd_(hwnd), paint_dc_(NULL), for_paint_(true) { |
| 97 memset(&ps_, 0, sizeof(ps_)); |
| 97 initPaint(true); | 98 initPaint(true); |
| 98 } | 99 } |
| 99 | 100 |
| 100 CanvasPaintT(HWND hwnd, bool opaque) : hwnd_(hwnd), for_paint_(true) { | 101 CanvasPaintT(HWND hwnd, bool opaque) : hwnd_(hwnd), paint_dc_(NULL), |
| 102 for_paint_(true) { |
| 103 memset(&ps_, 0, sizeof(ps_)); |
| 101 initPaint(opaque); | 104 initPaint(opaque); |
| 102 } | 105 } |
| 103 | 106 |
| 104 // Creates a CanvasPaintT for the specified region that paints to the | 107 // Creates a CanvasPaintT for the specified region that paints to the |
| 105 // specified dc. This does NOT do BeginPaint/EndPaint. | 108 // specified dc. This does NOT do BeginPaint/EndPaint. |
| 106 CanvasPaintT(HDC dc, bool opaque, int x, int y, int w, int h) | 109 CanvasPaintT(HDC dc, bool opaque, int x, int y, int w, int h) |
| 107 : hwnd_(NULL), | 110 : hwnd_(NULL), |
| 108 paint_dc_(dc), | 111 paint_dc_(dc), |
| 109 for_paint_(false) { | 112 for_paint_(false) { |
| 110 memset(&ps_, 0, sizeof(ps_)); | 113 memset(&ps_, 0, sizeof(ps_)); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 paint_dc_ = BeginPaint(hwnd_, &ps_); | 159 paint_dc_ = BeginPaint(hwnd_, &ps_); |
| 157 | 160 |
| 158 init(opaque); | 161 init(opaque); |
| 159 } | 162 } |
| 160 | 163 |
| 161 void init(bool opaque) { | 164 void init(bool opaque) { |
| 162 // FIXME(brettw) for ClearType, we probably want to expand the bounds of | 165 // FIXME(brettw) for ClearType, we probably want to expand the bounds of |
| 163 // painting by one pixel so that the boundaries will be correct (ClearType | 166 // painting by one pixel so that the boundaries will be correct (ClearType |
| 164 // text can depend on the adjacent pixel). Then we would paint just the | 167 // text can depend on the adjacent pixel). Then we would paint just the |
| 165 // inset pixels to the screen. | 168 // inset pixels to the screen. |
| 166 initialize(ps_.rcPaint.right - ps_.rcPaint.left, | 169 const int width = ps_.rcPaint.right - ps_.rcPaint.left; |
| 167 ps_.rcPaint.bottom - ps_.rcPaint.top, opaque, NULL); | 170 const int height = ps_.rcPaint.bottom - ps_.rcPaint.top; |
| 171 if (!initialize(width, height, opaque, NULL)) { |
| 172 // Cause a deliberate crash; |
| 173 *(char*) 0 = 0; |
| 174 } |
| 168 | 175 |
| 169 // This will bring the canvas into the screen coordinate system for the | 176 // This will bring the canvas into the screen coordinate system for the |
| 170 // dirty rect | 177 // dirty rect |
| 171 translate(SkIntToScalar(-ps_.rcPaint.left), | 178 translate(SkIntToScalar(-ps_.rcPaint.left), |
| 172 SkIntToScalar(-ps_.rcPaint.top)); | 179 SkIntToScalar(-ps_.rcPaint.top)); |
| 173 } | 180 } |
| 174 | 181 |
| 175 // If true, this canvas was created for a BeginPaint. | 182 // If true, this canvas was created for a BeginPaint. |
| 176 const bool for_paint_; | 183 const bool for_paint_; |
| 177 | 184 |
| 178 DISALLOW_COPY_AND_ASSIGN(CanvasPaintT); | 185 DISALLOW_COPY_AND_ASSIGN(CanvasPaintT); |
| 179 }; | 186 }; |
| 180 | 187 |
| 181 typedef CanvasPaintT<PlatformCanvasWin> PlatformCanvasWinPaint; | 188 typedef CanvasPaintT<PlatformCanvasWin> PlatformCanvasWinPaint; |
| 182 | 189 |
| 183 } // namespace gfx | 190 } // namespace gfx |
| 184 | 191 |
| 185 #endif // BASE_GFX_PLATFORM_CANVAS_WIN_H_ | 192 #endif // BASE_GFX_PLATFORM_CANVAS_WIN_H_ |
| 186 | 193 |
| OLD | NEW |