1 #include "SkDevice.h"
2 #include "SkDraw.h"
3 #include "SkRect.h"
4
SkDevice()5 SkDevice::SkDevice() {}
6
SkDevice(const SkBitmap & bitmap)7 SkDevice::SkDevice(const SkBitmap& bitmap) : fBitmap(bitmap) {}
8
lockPixels()9 void SkDevice::lockPixels() {
10 fBitmap.lockPixels();
11 }
12
unlockPixels()13 void SkDevice::unlockPixels() {
14 fBitmap.unlockPixels();
15 }
16
accessBitmap(bool changePixels)17 const SkBitmap& SkDevice::accessBitmap(bool changePixels) {
18 this->onAccessBitmap(&fBitmap);
19 if (changePixels) {
20 fBitmap.notifyPixelsChanged();
21 }
22 return fBitmap;
23 }
24
getBounds(SkIRect * bounds) const25 void SkDevice::getBounds(SkIRect* bounds) const {
26 if (bounds) {
27 bounds->set(0, 0, fBitmap.width(), fBitmap.height());
28 }
29 }
30
intersects(const SkIRect & r,SkIRect * sect) const31 bool 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
eraseColor(SkColor eraseColor)38 void SkDevice::eraseColor(SkColor eraseColor) {
39 fBitmap.eraseColor(eraseColor);
40 }
41
onAccessBitmap(SkBitmap * bitmap)42 void SkDevice::onAccessBitmap(SkBitmap* bitmap) {}
43
setMatrixClip(const SkMatrix &,const SkRegion &)44 void SkDevice::setMatrixClip(const SkMatrix&, const SkRegion&) {}
45
46 ///////////////////////////////////////////////////////////////////////////////
47
drawPaint(const SkDraw & draw,const SkPaint & paint)48 void SkDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) {
49 draw.drawPaint(paint);
50 }
51
drawPoints(const SkDraw & draw,SkCanvas::PointMode mode,size_t count,const SkPoint pts[],const SkPaint & paint)52 void 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
drawRect(const SkDraw & draw,const SkRect & r,const SkPaint & paint)57 void SkDevice::drawRect(const SkDraw& draw, const SkRect& r,
58 const SkPaint& paint) {
59 draw.drawRect(r, paint);
60 }
61
drawPath(const SkDraw & draw,const SkPath & path,const SkPaint & paint)62 void SkDevice::drawPath(const SkDraw& draw, const SkPath& path,
63 const SkPaint& paint) {
64 draw.drawPath(path, paint);
65 }
66
drawBitmap(const SkDraw & draw,const SkBitmap & bitmap,const SkMatrix & matrix,const SkPaint & paint)67 void SkDevice::drawBitmap(const SkDraw& draw, const SkBitmap& bitmap,
68 const SkMatrix& matrix, const SkPaint& paint) {
69 draw.drawBitmap(bitmap, matrix, paint);
70 }
71
drawSprite(const SkDraw & draw,const SkBitmap & bitmap,int x,int y,const SkPaint & paint)72 void 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
drawText(const SkDraw & draw,const void * text,size_t len,SkScalar x,SkScalar y,const SkPaint & paint)77 void 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
drawPosText(const SkDraw & draw,const void * text,size_t len,const SkScalar xpos[],SkScalar y,int scalarsPerPos,const SkPaint & paint)82 void 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
drawTextOnPath(const SkDraw & draw,const void * text,size_t len,const SkPath & path,const SkMatrix * matrix,const SkPaint & paint)88 void 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
drawVertices(const SkDraw & draw,SkCanvas::VertexMode vmode,int vertexCount,const SkPoint verts[],const SkPoint textures[],const SkColor colors[],SkXfermode * xmode,const uint16_t indices[],int indexCount,const SkPaint & paint)95 void 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
drawDevice(const SkDraw & draw,SkDevice * device,int x,int y,const SkPaint & paint)105 void 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
111