19241e33ca900c5fd8f902829255f381f8e6e17c8robertphillips@google.com 29241e33ca900c5fd8f902829255f381f8e6e17c8robertphillips@google.com/* 39241e33ca900c5fd8f902829255f381f8e6e17c8robertphillips@google.com * Copyright 2013 Google Inc. 49241e33ca900c5fd8f902829255f381f8e6e17c8robertphillips@google.com * 59241e33ca900c5fd8f902829255f381f8e6e17c8robertphillips@google.com * Use of this source code is governed by a BSD-style license that can be 69241e33ca900c5fd8f902829255f381f8e6e17c8robertphillips@google.com * found in the LICENSE file. 79241e33ca900c5fd8f902829255f381f8e6e17c8robertphillips@google.com */ 89241e33ca900c5fd8f902829255f381f8e6e17c8robertphillips@google.com 99241e33ca900c5fd8f902829255f381f8e6e17c8robertphillips@google.com#ifndef SkBitmapDevice_DEFINED 109241e33ca900c5fd8f902829255f381f8e6e17c8robertphillips@google.com#define SkBitmapDevice_DEFINED 119241e33ca900c5fd8f902829255f381f8e6e17c8robertphillips@google.com 129241e33ca900c5fd8f902829255f381f8e6e17c8robertphillips@google.com#include "SkDevice.h" 139241e33ca900c5fd8f902829255f381f8e6e17c8robertphillips@google.com 141f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com/////////////////////////////////////////////////////////////////////////////// 151f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.comclass SK_API SkBitmapDevice : public SkBaseDevice { 161f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.compublic: 171f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com SK_DECLARE_INST_COUNT(SkBitmapDevice) 181f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com 191f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com /** 201f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com * Construct a new device with the specified bitmap as its backend. It is 211f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com * valid for the bitmap to have no pixels associated with it. In that case, 221f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com * any drawing to this device will have no effect. 231f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com */ 241f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com SkBitmapDevice(const SkBitmap& bitmap); 25e010f1c2a0e6fe9cbaa73be01c7d878308b5166creedprivate: 261f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com /** 271f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com * Construct a new device with the specified bitmap as its backend. It is 281f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com * valid for the bitmap to have no pixels associated with it. In that case, 291f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com * any drawing to this device will have no effect. 301f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com */ 311f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com SkBitmapDevice(const SkBitmap& bitmap, const SkDeviceProperties& deviceProperties); 32e010f1c2a0e6fe9cbaa73be01c7d878308b5166creed static SkBitmapDevice* Create(const SkImageInfo&, const SkDeviceProperties*); 33e010f1c2a0e6fe9cbaa73be01c7d878308b5166creedpublic: 34e010f1c2a0e6fe9cbaa73be01c7d878308b5166creed static SkBitmapDevice* Create(const SkImageInfo& info) { 35e010f1c2a0e6fe9cbaa73be01c7d878308b5166creed return Create(info, NULL); 36e010f1c2a0e6fe9cbaa73be01c7d878308b5166creed } 371f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com 38c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org virtual SkImageInfo imageInfo() const SK_OVERRIDE; 39c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org 401f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.comprotected: 411f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com virtual bool filterTextFlags(const SkPaint& paint, TextFlags*) SK_OVERRIDE; 421f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com 431f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com /** Clears the entire device to the specified color (including alpha). 441f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com * Ignores the clip. 451f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com */ 461f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com virtual void clear(SkColor color) SK_OVERRIDE; 471f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com 481f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com /** These are called inside the per-device-layer loop for each draw call. 491f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com When these are called, we have already applied any saveLayer operations, 501f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com and are handling any looping from the paint, and any effects from the 511f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com DrawFilter. 521f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com */ 531f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com virtual void drawPaint(const SkDraw&, const SkPaint& paint) SK_OVERRIDE; 541f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, size_t count, 551f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com const SkPoint[], const SkPaint& paint) SK_OVERRIDE; 561f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com virtual void drawRect(const SkDraw&, const SkRect& r, 571f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com const SkPaint& paint) SK_OVERRIDE; 581f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com virtual void drawOval(const SkDraw&, const SkRect& oval, 591f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com const SkPaint& paint) SK_OVERRIDE; 601f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com virtual void drawRRect(const SkDraw&, const SkRRect& rr, 611f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com const SkPaint& paint) SK_OVERRIDE; 621f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com 631f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com /** 641f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com * If pathIsMutable, then the implementation is allowed to cast path to a 651f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com * non-const pointer and modify it in place (as an optimization). Canvas 661f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com * may do this to implement helpers such as drawOval, by placing a temp 671f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com * path on the stack to hold the representation of the oval. 681f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com * 691f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com * If prePathMatrix is not null, it should logically be applied before any 701f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com * stroking or other effects. If there are no effects on the paint that 711f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com * affect the geometry/rasterization, then the pre matrix can just be 721f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com * pre-concated with the current matrix. 731f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com */ 741f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com virtual void drawPath(const SkDraw&, const SkPath& path, 751f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com const SkPaint& paint, 761f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com const SkMatrix* prePathMatrix = NULL, 771f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com bool pathIsMutable = false) SK_OVERRIDE; 781f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap, 791f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com const SkMatrix& matrix, const SkPaint& paint) SK_OVERRIDE; 801f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap, 811f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com int x, int y, const SkPaint& paint) SK_OVERRIDE; 821f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com 831f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com /** 841f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com * The default impl. will create a bitmap-shader from the bitmap, 851f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com * and call drawRect with it. 861f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com */ 871f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com virtual void drawBitmapRect(const SkDraw&, const SkBitmap&, 881f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com const SkRect* srcOrNull, const SkRect& dst, 891f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com const SkPaint& paint, 901f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com SkCanvas::DrawBitmapRectFlags flags) SK_OVERRIDE; 911f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com 921f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com /** 931f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com * Does not handle text decoration. 941f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com * Decorations (underline and stike-thru) will be handled by SkCanvas. 951f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com */ 961f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com virtual void drawText(const SkDraw&, const void* text, size_t len, 971f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com SkScalar x, SkScalar y, const SkPaint& paint) SK_OVERRIDE; 981f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com virtual void drawPosText(const SkDraw&, const void* text, size_t len, 991f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com const SkScalar pos[], SkScalar constY, 1001f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com int scalarsPerPos, const SkPaint& paint) SK_OVERRIDE; 1011f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len, 1021f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com const SkPath& path, const SkMatrix* matrix, 1031f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com const SkPaint& paint) SK_OVERRIDE; 1041f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, int vertexCount, 1051f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com const SkPoint verts[], const SkPoint texs[], 1061f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com const SkColor colors[], SkXfermode* xmode, 1071f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com const uint16_t indices[], int indexCount, 1081f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com const SkPaint& paint) SK_OVERRIDE; 1091f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com /** The SkBaseDevice passed will be an SkBaseDevice which was returned by a call to 11015a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org onCreateDevice on this device with kSaveLayer_Usage. 1111f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com */ 1121f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y, 1131f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com const SkPaint&) SK_OVERRIDE; 1141f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com 1151f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com /////////////////////////////////////////////////////////////////////////// 1161f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com 1171f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com /** Update as needed the pixel value in the bitmap, so that the caller can 1181f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com access the pixels directly. Note: only the pixels field should be 1191f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com altered. The config/width/height/rowbytes must remain unchanged. 1201f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com @return the device contents as a bitmap 1211f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com */ 1221f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com virtual const SkBitmap& onAccessBitmap() SK_OVERRIDE; 1231f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com 1241f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); } 1251f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com // just for subclasses, to assign a custom pixelref 126672588b684d484dce6ae251e9e163e4a46924322reed@google.com SkPixelRef* setPixelRef(SkPixelRef* pr) { 127672588b684d484dce6ae251e9e163e4a46924322reed@google.com fBitmap.setPixelRef(pr); 1281f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com return pr; 1291f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com } 1301f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com 131a713f9c6f6a06d216d53e268b9c691941053dabfcommit-bot@chromium.org virtual bool onReadPixels(const SkImageInfo&, void*, size_t, int x, int y) SK_OVERRIDE; 1324cd9e2169e35cd67ee7358acea6541245e1d1744commit-bot@chromium.org virtual bool onWritePixels(const SkImageInfo&, const void*, size_t, int, int) SK_OVERRIDE; 1339c135db83d198e7d8200027c7d2cf60f38517ee3reed@google.com virtual void* onAccessPixels(SkImageInfo* info, size_t* rowBytes) SK_OVERRIDE; 1341f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com 1351f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com /** Called when this device is installed into a Canvas. Balanced by a call 1361f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com to unlockPixels() when the device is removed from a Canvas. 1371f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com */ 1381f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com virtual void lockPixels() SK_OVERRIDE; 1391f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com virtual void unlockPixels() SK_OVERRIDE; 1401f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com 1411f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.comprivate: 1421f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com friend class SkCanvas; 1431f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com friend struct DeviceCM; //for setMatrixClip 1441f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com friend class SkDraw; 1451f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com friend class SkDrawIter; 1461f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com friend class SkDeviceFilteredPaint; 1471f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com friend class SkDeviceImageFilterProxy; 1481f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com 1491f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com friend class SkSurface_Raster; 1501f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com 1511f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com // used to change the backend's pixels (and possibly config/rowbytes) 1521f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com // but cannot change the width/height, so there should be no change to 1531f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com // any clip information. 1541f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com virtual void replaceBitmapBackendForRasterSurface(const SkBitmap&) SK_OVERRIDE; 1551f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com 15615a140599942f70e47380e3f700a825c7cece3b4commit-bot@chromium.org virtual SkBaseDevice* onCreateDevice(const SkImageInfo&, Usage) SK_OVERRIDE; 1571f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com 1584a8126e7f81384526629b1e21bf89b632ea13cd9reed virtual SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&) SK_OVERRIDE; 159c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org virtual const void* peekPixels(SkImageInfo*, size_t* rowBytes) SK_OVERRIDE; 16076f10a3bd936af7dbe2b5873d5a7eedd73cdc5dareed@google.com 161be129b26f13d575fd6b396c6ae759838ecc9bd1asenorblanco virtual SkImageFilter::Cache* getImageFilterCache() SK_OVERRIDE; 16255b6d8be997a447ef9ce0f029697677a940bfc24senorblanco 1631f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com SkBitmap fBitmap; 1641f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com 1651f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com typedef SkBaseDevice INHERITED; 1661f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com}; 1679241e33ca900c5fd8f902829255f381f8e6e17c8robertphillips@google.com 1689241e33ca900c5fd8f902829255f381f8e6e17c8robertphillips@google.com#endif // SkBitmapDevice_DEFINED 169