blob: 139174da30af56c05c9ce68ee1020f3aadd7e7ac [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001#include "SkDevice.h"
2#include "SkDraw.h"
3#include "SkRect.h"
4
5SkDevice::SkDevice() {}
6
7SkDevice::SkDevice(const SkBitmap& bitmap) : fBitmap(bitmap) {}
8
9void SkDevice::lockPixels() {
10 fBitmap.lockPixels();
11}
12
13void SkDevice::unlockPixels() {
14 fBitmap.unlockPixels();
15}
16
17const SkBitmap& SkDevice::accessBitmap(bool changePixels) {
18 this->onAccessBitmap(&fBitmap);
19 if (changePixels) {
20 fBitmap.notifyPixelsChanged();
21 }
22 return fBitmap;
23}
24
25void SkDevice::getBounds(SkIRect* bounds) const {
26 if (bounds) {
27 bounds->set(0, 0, fBitmap.width(), fBitmap.height());
28 }
29}
30
31bool SkDevice::intersects(const SkIRect& r, SkIRect* sect) const {
32 SkIRect bounds;
33
34 this->getBounds(&bounds);
35 return sect ? sect->intersect(r, bounds) : SkIRect::Intersects(r, bounds);
36}
37
38void SkDevice::eraseColor(SkColor eraseColor) {
39 fBitmap.eraseColor(eraseColor);
40}
41
42void SkDevice::onAccessBitmap(SkBitmap* bitmap) {}
43
44void SkDevice::setMatrixClip(const SkMatrix&, const SkRegion&) {}
45
46///////////////////////////////////////////////////////////////////////////////
47
48void SkDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) {
49 draw.drawPaint(paint);
50}
51
52void SkDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, size_t count,
53 const SkPoint pts[], const SkPaint& paint) {
54 draw.drawPoints(mode, count, pts, paint);
55}
56
57void SkDevice::drawRect(const SkDraw& draw, const SkRect& r,
58 const SkPaint& paint) {
59 draw.drawRect(r, paint);
60}
61
62void SkDevice::drawPath(const SkDraw& draw, const SkPath& path,
63 const SkPaint& paint) {
64 draw.drawPath(path, paint);
65}
66
67void SkDevice::drawBitmap(const SkDraw& draw, const SkBitmap& bitmap,
68 const SkMatrix& matrix, const SkPaint& paint) {
69 draw.drawBitmap(bitmap, matrix, paint);
70}
71
72void SkDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
73 int x, int y, const SkPaint& paint) {
74 draw.drawSprite(bitmap, x, y, paint);
75}
76
77void SkDevice::drawText(const SkDraw& draw, const void* text, size_t len,
78 SkScalar x, SkScalar y, const SkPaint& paint) {
79 draw.drawText((const char*)text, len, x, y, paint);
80}
81
82void SkDevice::drawPosText(const SkDraw& draw, const void* text, size_t len,
83 const SkScalar xpos[], SkScalar y,
84 int scalarsPerPos, const SkPaint& paint) {
85 draw.drawPosText((const char*)text, len, xpos, y, scalarsPerPos, paint);
86}
87
88void SkDevice::drawTextOnPath(const SkDraw& draw, const void* text,
89 size_t len, const SkPath& path,
90 const SkMatrix* matrix,
91 const SkPaint& paint) {
92 draw.drawTextOnPath((const char*)text, len, path, matrix, paint);
93}
94
95void SkDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode,
96 int vertexCount,
97 const SkPoint verts[], const SkPoint textures[],
98 const SkColor colors[], SkXfermode* xmode,
99 const uint16_t indices[], int indexCount,
100 const SkPaint& paint) {
101 draw.drawVertices(vmode, vertexCount, verts, textures, colors, xmode,
102 indices, indexCount, paint);
103}
104
105void SkDevice::drawDevice(const SkDraw& draw, SkDevice* device,
106 int x, int y, const SkPaint& paint) {
107 draw.drawSprite(device->accessBitmap(false), x, y, paint);
108}
109
110