Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SkBitmap_DEFINED | 8 #ifndef SkBitmap_DEFINED |
| 9 #define SkBitmap_DEFINED | 9 #define SkBitmap_DEFINED |
| 10 | 10 |
| 11 #include "SkColor.h" | 11 #include "SkColor.h" |
| 12 #include "SkColorTable.h" | 12 #include "SkColorTable.h" |
| 13 #include "SkImageInfo.h" | 13 #include "SkImageInfo.h" |
| 14 #include "SkPixmap.h" | |
| 14 #include "SkPoint.h" | 15 #include "SkPoint.h" |
| 15 #include "SkRefCnt.h" | 16 #include "SkRefCnt.h" |
| 16 | 17 |
| 17 struct SkMask; | 18 struct SkMask; |
| 18 struct SkIRect; | 19 struct SkIRect; |
| 19 struct SkRect; | 20 struct SkRect; |
| 20 class SkPaint; | 21 class SkPaint; |
| 21 class SkPixelRef; | 22 class SkPixelRef; |
| 22 class SkPixelRefFactory; | 23 class SkPixelRefFactory; |
| 23 class SkRegion; | 24 class SkRegion; |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 421 void unlockPixels() const; | 422 void unlockPixels() const; |
| 422 | 423 |
| 423 /** | 424 /** |
| 424 * Some bitmaps can return a copy of their pixels for lockPixels(), but | 425 * Some bitmaps can return a copy of their pixels for lockPixels(), but |
| 425 * that copy, if modified, will not be pushed back. These bitmaps should | 426 * that copy, if modified, will not be pushed back. These bitmaps should |
| 426 * not be used as targets for a raster device/canvas (since all pixels | 427 * not be used as targets for a raster device/canvas (since all pixels |
| 427 * modifications will be lost when unlockPixels() is called.) | 428 * modifications will be lost when unlockPixels() is called.) |
| 428 */ | 429 */ |
| 429 bool lockPixelsAreWritable() const; | 430 bool lockPixelsAreWritable() const; |
| 430 | 431 |
| 432 class LockResult { | |
|
scroggo
2015/05/19 20:11:41
inherit from SkNoncopyable?
reed1
2015/05/21 20:59:34
Done.
| |
| 433 public: | |
| 434 LockResult() : fUnlockProc(NULL), fUnlockContext(NULL) { | |
| 435 SkDEBUGCODE(fIsLocked = false;) | |
| 436 } | |
| 437 | |
| 438 const SkPixmap& pixmap() const { return fPixmap; } | |
| 439 | |
| 440 SkDEBUGCODE(bool isLocked() const { return fIsLocked; }) | |
| 441 void unlock(); | |
|
scroggo
2015/05/19 20:11:42
Should this get called by a destructor, if it wasn
reed1
2015/05/21 20:59:34
Done.
| |
| 442 | |
| 443 private: | |
| 444 LockResult(const SkPixmap& pm, void (*unlock)(void*), void* ctx) | |
| 445 : fUnlockProc(unlock), fUnlockContext(ctx), fPixmap(pm) | |
| 446 { | |
| 447 SkDEBUGCODE(fIsLocked = true;) | |
| 448 } | |
| 449 | |
| 450 void (*fUnlockProc)(void*); | |
| 451 void* fUnlockContext; | |
| 452 SkPixmap fPixmap; | |
| 453 SkDEBUGCODE(bool fIsLocked;) | |
| 454 | |
| 455 friend class SkBitmap; | |
| 456 }; | |
| 457 | |
| 458 bool requestLock(LockResult* result) const; | |
| 459 | |
| 431 /** Call this to be sure that the bitmap is valid enough to be drawn (i.e. | 460 /** Call this to be sure that the bitmap is valid enough to be drawn (i.e. |
| 432 it has non-null pixels, and if required by its colortype, it has a | 461 it has non-null pixels, and if required by its colortype, it has a |
| 433 non-null colortable. Returns true if all of the above are met. | 462 non-null colortable. Returns true if all of the above are met. |
| 434 */ | 463 */ |
| 435 bool readyToDraw() const { | 464 bool readyToDraw() const { |
| 436 return this->getPixels() != NULL && | 465 return this->getPixels() != NULL && |
| 437 (this->colorType() != kIndex_8_SkColorType || fColorTable); | 466 (this->colorType() != kIndex_8_SkColorType || fColorTable); |
| 438 } | 467 } |
| 439 | 468 |
| 440 /** Returns the pixelRef's texture, or NULL | 469 /** Returns the pixelRef's texture, or NULL |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 776 } | 805 } |
| 777 } | 806 } |
| 778 | 807 |
| 779 private: | 808 private: |
| 780 const SkBitmap& fBitmap; | 809 const SkBitmap& fBitmap; |
| 781 bool fDidLock; | 810 bool fDidLock; |
| 782 }; | 811 }; |
| 783 //TODO(mtklein): uncomment when 71713004 lands and Chromium's fixed. | 812 //TODO(mtklein): uncomment when 71713004 lands and Chromium's fixed. |
| 784 //#define SkAutoLockPixels(...) SK_REQUIRE_LOCAL_VAR(SkAutoLockPixels) | 813 //#define SkAutoLockPixels(...) SK_REQUIRE_LOCAL_VAR(SkAutoLockPixels) |
| 785 | 814 |
| 815 class SkAutoBitmapLockResult : public SkBitmap::LockResult { | |
| 816 public: | |
| 817 SkAutoBitmapLockResult() {} | |
| 818 ~SkAutoBitmapLockResult() { | |
| 819 this->unlock(); | |
| 820 } | |
| 821 }; | |
| 822 | |
| 786 /////////////////////////////////////////////////////////////////////////////// | 823 /////////////////////////////////////////////////////////////////////////////// |
| 787 | 824 |
| 788 inline uint32_t* SkBitmap::getAddr32(int x, int y) const { | 825 inline uint32_t* SkBitmap::getAddr32(int x, int y) const { |
| 789 SkASSERT(fPixels); | 826 SkASSERT(fPixels); |
| 790 SkASSERT(4 == this->bytesPerPixel()); | 827 SkASSERT(4 == this->bytesPerPixel()); |
| 791 SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)th is->height()); | 828 SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)th is->height()); |
| 792 return (uint32_t*)((char*)fPixels + y * fRowBytes + (x << 2)); | 829 return (uint32_t*)((char*)fPixels + y * fRowBytes + (x << 2)); |
| 793 } | 830 } |
| 794 | 831 |
| 795 inline uint16_t* SkBitmap::getAddr16(int x, int y) const { | 832 inline uint16_t* SkBitmap::getAddr16(int x, int y) const { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 808 | 845 |
| 809 inline SkPMColor SkBitmap::getIndex8Color(int x, int y) const { | 846 inline SkPMColor SkBitmap::getIndex8Color(int x, int y) const { |
| 810 SkASSERT(fPixels); | 847 SkASSERT(fPixels); |
| 811 SkASSERT(kIndex_8_SkColorType == this->colorType()); | 848 SkASSERT(kIndex_8_SkColorType == this->colorType()); |
| 812 SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)th is->height()); | 849 SkASSERT((unsigned)x < (unsigned)this->width() && (unsigned)y < (unsigned)th is->height()); |
| 813 SkASSERT(fColorTable); | 850 SkASSERT(fColorTable); |
| 814 return (*fColorTable)[*((const uint8_t*)fPixels + y * fRowBytes + x)]; | 851 return (*fColorTable)[*((const uint8_t*)fPixels + y * fRowBytes + x)]; |
| 815 } | 852 } |
| 816 | 853 |
| 817 #endif | 854 #endif |
| OLD | NEW |