| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/platform_canvas.h" | 10 #include "skia/ext/platform_canvas.h" |
| 10 | 11 |
| 11 namespace skia { | 12 namespace skia { |
| 12 | 13 |
| 13 // A class designed to help with WM_PAINT operations on Windows. It will | 14 // A class designed to help with WM_PAINT operations on Windows. It will |
| 14 // do BeginPaint/EndPaint on init/destruction, and will create the bitmap and | 15 // do BeginPaint/EndPaint on init/destruction, and will create the bitmap and |
| 15 // canvas with the correct size and transform for the dirty rect. The bitmap | 16 // canvas with the correct size and transform for the dirty rect. The bitmap |
| 16 // will be automatically painted to the screen on destruction. | 17 // will be automatically painted to the screen on destruction. |
| 17 // | 18 // |
| 18 // You MUST call isEmpty before painting to determine if anything needs | 19 // You MUST call isEmpty before painting to determine if anything needs |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 memset(&ps_, 0, sizeof(ps_)); | 54 memset(&ps_, 0, sizeof(ps_)); |
| 54 ps_.rcPaint.left = x; | 55 ps_.rcPaint.left = x; |
| 55 ps_.rcPaint.right = x + w; | 56 ps_.rcPaint.right = x + w; |
| 56 ps_.rcPaint.top = y; | 57 ps_.rcPaint.top = y; |
| 57 ps_.rcPaint.bottom = y + h; | 58 ps_.rcPaint.bottom = y + h; |
| 58 init(opaque); | 59 init(opaque); |
| 59 } | 60 } |
| 60 | 61 |
| 61 virtual ~CanvasPaintT() { | 62 virtual ~CanvasPaintT() { |
| 62 if (!isEmpty()) { | 63 if (!isEmpty()) { |
| 63 restoreToCount(1); | 64 PlatformCanvas* canvas = GetPlatformCanvas(this); |
| 65 canvas->restoreToCount(1); |
| 64 // Commit the drawing to the screen | 66 // Commit the drawing to the screen |
| 65 skia::DrawToNativeContext(this, paint_dc_, ps_.rcPaint.left, | 67 skia::DrawToNativeContext(canvas, paint_dc_, ps_.rcPaint.left, |
| 66 ps_.rcPaint.top, NULL); | 68 ps_.rcPaint.top, NULL); |
| 67 } | 69 } |
| 68 if (for_paint_) | 70 if (for_paint_) |
| 69 EndPaint(hwnd_, &ps_); | 71 EndPaint(hwnd_, &ps_); |
| 70 } | 72 } |
| 71 | 73 |
| 72 // Returns true if the invalid region is empty. The caller should call this | 74 // Returns true if the invalid region is empty. The caller should call this |
| 73 // function to determine if anything needs painting. | 75 // function to determine if anything needs painting. |
| 74 bool isEmpty() const { | 76 bool isEmpty() const { |
| 75 return ps_.rcPaint.right - ps_.rcPaint.left == 0 || | 77 return ps_.rcPaint.right - ps_.rcPaint.left == 0 || |
| (...skipping 17 matching lines...) Expand all Loading... |
| 93 PAINTSTRUCT ps_; | 95 PAINTSTRUCT ps_; |
| 94 | 96 |
| 95 private: | 97 private: |
| 96 void initPaint(bool opaque) { | 98 void initPaint(bool opaque) { |
| 97 paint_dc_ = BeginPaint(hwnd_, &ps_); | 99 paint_dc_ = BeginPaint(hwnd_, &ps_); |
| 98 | 100 |
| 99 init(opaque); | 101 init(opaque); |
| 100 } | 102 } |
| 101 | 103 |
| 102 void init(bool opaque) { | 104 void init(bool opaque) { |
| 105 PlatformCanvas* canvas = GetPlatformCanvas(this); |
| 103 // FIXME(brettw) for ClearType, we probably want to expand the bounds of | 106 // FIXME(brettw) for ClearType, we probably want to expand the bounds of |
| 104 // painting by one pixel so that the boundaries will be correct (ClearType | 107 // painting by one pixel so that the boundaries will be correct (ClearType |
| 105 // text can depend on the adjacent pixel). Then we would paint just the | 108 // text can depend on the adjacent pixel). Then we would paint just the |
| 106 // inset pixels to the screen. | 109 // inset pixels to the screen. |
| 107 const int width = ps_.rcPaint.right - ps_.rcPaint.left; | 110 const int width = ps_.rcPaint.right - ps_.rcPaint.left; |
| 108 const int height = ps_.rcPaint.bottom - ps_.rcPaint.top; | 111 const int height = ps_.rcPaint.bottom - ps_.rcPaint.top; |
| 109 if (!initialize(width, height, opaque, NULL)) { | 112 if (!canvas->initialize(width, height, opaque, NULL)) { |
| 110 // Cause a deliberate crash; | 113 // Cause a deliberate crash; |
| 111 *(char*) 0 = 0; | 114 *(char*) 0 = 0; |
| 112 } | 115 } |
| 113 | 116 |
| 114 // This will bring the canvas into the screen coordinate system for the | 117 // This will bring the canvas into the screen coordinate system for the |
| 115 // dirty rect | 118 // dirty rect |
| 116 translate(SkIntToScalar(-ps_.rcPaint.left), | 119 canvas->translate(SkIntToScalar(-ps_.rcPaint.left), |
| 117 SkIntToScalar(-ps_.rcPaint.top)); | 120 SkIntToScalar(-ps_.rcPaint.top)); |
| 118 } | 121 } |
| 119 | 122 |
| 120 // If true, this canvas was created for a BeginPaint. | 123 // If true, this canvas was created for a BeginPaint. |
| 121 const bool for_paint_; | 124 const bool for_paint_; |
| 122 | 125 |
| 123 // Disallow copy and assign. | 126 // Disallow copy and assign. |
| 124 CanvasPaintT(const CanvasPaintT&); | 127 CanvasPaintT(const CanvasPaintT&); |
| 125 CanvasPaintT& operator=(const CanvasPaintT&); | 128 CanvasPaintT& operator=(const CanvasPaintT&); |
| 126 }; | 129 }; |
| 127 | 130 |
| 128 typedef CanvasPaintT<PlatformCanvas> PlatformCanvasPaint; | 131 typedef CanvasPaintT<PlatformCanvas> PlatformCanvasPaint; |
| 129 | 132 |
| 130 } // namespace skia | 133 } // namespace skia |
| 131 | 134 |
| 132 #endif // SKIA_EXT_CANVAS_PAINT_WIN_H_ | 135 #endif // SKIA_EXT_CANVAS_PAINT_WIN_H_ |
| OLD | NEW |