Home | History | Annotate | Download | only in core
      1 #include "SkDevice.h"
      2 #include "SkDraw.h"
      3 #include "SkRect.h"
      4 
      5 SkDevice::SkDevice() {}
      6 
      7 SkDevice::SkDevice(const SkBitmap& bitmap) : fBitmap(bitmap) {}
      8 
      9 void SkDevice::lockPixels() {
     10     fBitmap.lockPixels();
     11 }
     12 
     13 void SkDevice::unlockPixels() {
     14     fBitmap.unlockPixels();
     15 }
     16 
     17 const SkBitmap& SkDevice::accessBitmap(bool changePixels) {
     18     this->onAccessBitmap(&fBitmap);
     19     if (changePixels) {
     20         fBitmap.notifyPixelsChanged();
     21     }
     22     return fBitmap;
     23 }
     24 
     25 void SkDevice::getBounds(SkIRect* bounds) const {
     26     if (bounds) {
     27         bounds->set(0, 0, fBitmap.width(), fBitmap.height());
     28     }
     29 }
     30 
     31 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 
     38 void SkDevice::eraseColor(SkColor eraseColor) {
     39     fBitmap.eraseColor(eraseColor);
     40 }
     41 
     42 void SkDevice::onAccessBitmap(SkBitmap* bitmap) {}
     43 
     44 void SkDevice::setMatrixClip(const SkMatrix&, const SkRegion&) {}
     45 
     46 ///////////////////////////////////////////////////////////////////////////////
     47 
     48 void SkDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) {
     49     draw.drawPaint(paint);
     50 }
     51 
     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 
     57 void SkDevice::drawRect(const SkDraw& draw, const SkRect& r,
     58                             const SkPaint& paint) {
     59     draw.drawRect(r, paint);
     60 }
     61 
     62 void SkDevice::drawPath(const SkDraw& draw, const SkPath& path,
     63                             const SkPaint& paint) {
     64     draw.drawPath(path, paint);
     65 }
     66 
     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 
     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 
     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 
     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 
     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 
     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 
    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