This source file includes following definitions.
- paint_dc_
- paint_dc_
- GetInvalidRect
- Init
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/canvas_skia_paint.h"
#include "ui/gfx/rect.h"
namespace gfx {
CanvasSkiaPaint::CanvasSkiaPaint(HWND hwnd, HDC dc, const PAINTSTRUCT& ps)
: hwnd_(hwnd),
paint_dc_(dc) {
memset(&ps_, 0, sizeof(ps_));
ps_.rcPaint.left = ps.rcPaint.left;
ps_.rcPaint.right = ps.rcPaint.right;
ps_.rcPaint.top = ps.rcPaint.top;
ps_.rcPaint.bottom = ps.rcPaint.bottom;
Init(true);
}
CanvasSkiaPaint::CanvasSkiaPaint(HDC dc, bool opaque, int x, int y,
int w, int h)
: hwnd_(NULL),
paint_dc_(dc) {
memset(&ps_, 0, sizeof(ps_));
ps_.rcPaint.left = x;
ps_.rcPaint.right = x + w;
ps_.rcPaint.top = y;
ps_.rcPaint.bottom = y + h;
Init(opaque);
}
CanvasSkiaPaint::~CanvasSkiaPaint() {
if (!is_empty()) {
skia::PlatformCanvas* canvas = platform_canvas();
canvas->restoreToCount(1);
skia::DrawToNativeContext(canvas, paint_dc_, ps_.rcPaint.left,
ps_.rcPaint.top, NULL);
}
}
gfx::Rect CanvasSkiaPaint::GetInvalidRect() const {
return gfx::Rect(paint_struct().rcPaint);
}
void CanvasSkiaPaint::Init(bool opaque) {
const int width = ps_.rcPaint.right - ps_.rcPaint.left;
const int height = ps_.rcPaint.bottom - ps_.rcPaint.top;
RecreateBackingCanvas(gfx::Size(width, height),
gfx::win::GetDeviceScaleFactor(),
opaque);
skia::PlatformCanvas* canvas = platform_canvas();
canvas->clear(SkColorSetARGB(0, 0, 0, 0));
canvas->translate(
-ps_.rcPaint.left / gfx::win::GetDeviceScaleFactor(),
-ps_.rcPaint.top / gfx::win::GetDeviceScaleFactor());
}
}