diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-01-08 15:42:01 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-01-08 15:42:01 +0000 |
commit | 672588b684d484dce6ae251e9e163e4a46924322 (patch) | |
tree | c0fd674c6a905b9f7e4f9f8e58326653ab3fe816 /include | |
parent | c75b25af9e46019b13cde1e642a63b7c253ea5f4 (diff) |
change offset to xy for pixelref subsetting
BUG=
R=scroggo@google.com
Review URL: https://codereview.chromium.org/105893012
git-svn-id: http://skia.googlecode.com/svn/trunk@12958 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include')
-rw-r--r-- | include/core/SkBitmap.h | 48 | ||||
-rw-r--r-- | include/core/SkBitmapDevice.h | 4 | ||||
-rw-r--r-- | include/core/SkPicture.h | 7 | ||||
-rw-r--r-- | include/core/SkPixelRef.h | 2 |
4 files changed, 44 insertions, 17 deletions
diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h index 2b900bef34..fe0fc0f9c1 100644 --- a/include/core/SkBitmap.h +++ b/include/core/SkBitmap.h @@ -347,18 +347,41 @@ public: */ bool allocPixels(Allocator* allocator, SkColorTable* ctable); - /** Return the current pixelref object, if any - */ + /** + * Return the current pixelref object or NULL if there is none. This does + * not affect the refcount of the pixelref. + */ SkPixelRef* pixelRef() const { return fPixelRef; } - /** Return the offset into the pixelref, if any. Will return 0 if there is - no pixelref installed. - */ - size_t pixelRefOffset() const { return fPixelRefOffset; } - /** Assign a pixelref and optional offset. Pixelrefs are reference counted, - so the existing one (if any) will be unref'd and the new one will be - ref'd. - */ - SkPixelRef* setPixelRef(SkPixelRef* pr, size_t offset = 0); + + /** + * A bitmap can reference a subset of a pixelref's pixels. That means the + * bitmap's width/height can be <= the dimensions of the pixelref. The + * pixelref origin is the x,y location within the pixelref's pixels for + * the bitmap's top/left corner. To be valid the following must be true: + * + * origin_x + bitmap_width <= pixelref_width + * origin_y + bitmap_height <= pixelref_height + * + * pixelRefOrigin() returns this origin, or (0,0) if there is no pixelRef. + */ + SkIPoint pixelRefOrigin() const { return fPixelRefOrigin; } + + /** + * Assign a pixelref and origin to the bitmap. Pixelrefs are reference, + * so the existing one (if any) will be unref'd and the new one will be + * ref'd. (x,y) specify the offset within the pixelref's pixels for the + * top/left corner of the bitmap. For a bitmap that encompases the entire + * pixels of the pixelref, these will be (0,0). + */ + SkPixelRef* setPixelRef(SkPixelRef* pr, int dx, int dy); + + SkPixelRef* setPixelRef(SkPixelRef* pr, const SkIPoint& origin) { + return this->setPixelRef(pr, origin.fX, origin.fY); + } + + SkPixelRef* setPixelRef(SkPixelRef* pr) { + return this->setPixelRef(pr, 0, 0); + } /** Call this to ensure that the bitmap points to the current pixel address in the pixelref. Balance it with a call to unlockPixels(). These calls @@ -665,13 +688,14 @@ private: mutable MipMap* fMipMap; mutable SkPixelRef* fPixelRef; - mutable size_t fPixelRefOffset; mutable int fPixelLockCount; // either user-specified (in which case it is not treated as mutable) // or a cache of the returned value from fPixelRef->lockPixels() mutable void* fPixels; mutable SkColorTable* fColorTable; // only meaningful for kIndex8 + SkIPoint fPixelRefOrigin; + enum Flags { kImageIsOpaque_Flag = 0x01, kImageIsVolatile_Flag = 0x02, diff --git a/include/core/SkBitmapDevice.h b/include/core/SkBitmapDevice.h index f3d40d0ce8..a9208e20a0 100644 --- a/include/core/SkBitmapDevice.h +++ b/include/core/SkBitmapDevice.h @@ -199,8 +199,8 @@ protected: SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); } // just for subclasses, to assign a custom pixelref - SkPixelRef* setPixelRef(SkPixelRef* pr, size_t offset) { - fBitmap.setPixelRef(pr, offset); + SkPixelRef* setPixelRef(SkPixelRef* pr) { + fBitmap.setPixelRef(pr); return pr; } diff --git a/include/core/SkPicture.h b/include/core/SkPicture.h index a1d7644e53..4c7e4b3399 100644 --- a/include/core/SkPicture.h +++ b/include/core/SkPicture.h @@ -172,8 +172,8 @@ public: * signature can be passed to serialize() and SkOrderedWriteBuffer. * Returning NULL will tell the SkOrderedWriteBuffer to use * SkBitmap::flatten() to store the bitmap. - * @param pixelRefOffset Output parameter, telling the deserializer what - * offset in the bm's pixelRef corresponds to the encoded data. + * + * @param pixelRefOffset DEPRECATED -- caller assumes it will return 0. * @return SkData If non-NULL, holds encoded data representing the passed * in bitmap. The caller is responsible for calling unref(). */ @@ -221,10 +221,11 @@ protected: // V15: Remove A1 bitmpa config (and renumber remaining configs) // V16: Move SkPath's isOval flag to SkPathRef // V17: SkPixelRef now writes SkImageInfo + // V18: SkBitmap now records x,y for its pixelref origin, instead of offset. #ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V16_AND_ALL_OTHER_INSTANCES_TOO static const uint32_t PRIOR_PICTURE_VERSION = 15; // TODO: remove when .skps regenerated #endif - static const uint32_t PICTURE_VERSION = 17; + static const uint32_t PICTURE_VERSION = 18; // fPlayback, fRecord, fWidth & fHeight are protected to allow derived classes to // install their own SkPicturePlayback-derived players,SkPictureRecord-derived diff --git a/include/core/SkPixelRef.h b/include/core/SkPixelRef.h index 4811435721..e0bf8866c6 100644 --- a/include/core/SkPixelRef.h +++ b/include/core/SkPixelRef.h @@ -69,6 +69,8 @@ public: */ SkColorTable* colorTable() const { return fRec.fColorTable; } + size_t rowBytes() const { return fRec.fRowBytes; } + /** * To access the actual pixels of a pixelref, it must be "locked". * Calling lockPixels returns a LockRec struct (on success). |