aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-07-07 13:42:37 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-07-07 13:42:37 +0000
commit9c49bc3e643c435677727c1c0904c4a7cb7a6907 (patch)
tree20d6cb41a7367fddcdd4a8c8c958934fcb2c7955 /src/core
parent63e5e34c4ef180ea0f2d7b2f1343d92063c7cc10 (diff)
Allow texture-backed bitmaps to perform a read-back when lockPixels is called.
This means we have to be even more cautious about when we call lock, and we should always check getTexture() first if we can handle a texture directly, rather than forcing the read-back to get the bits. git-svn-id: http://skia.googlecode.com/svn/trunk@1815 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core')
-rw-r--r--src/core/SkBitmap.cpp8
-rw-r--r--src/core/SkDevice.cpp8
-rw-r--r--src/core/SkPixelRef.cpp11
3 files changed, 24 insertions, 3 deletions
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp
index cdb74bb1d6..92ff88ae66 100644
--- a/src/core/SkBitmap.cpp
+++ b/src/core/SkBitmap.cpp
@@ -350,6 +350,14 @@ void SkBitmap::unlockPixels() const {
SkDEBUGCODE(this->validate();)
}
+bool SkBitmap::lockPixelsAreWritable() const {
+ if (fPixelRef) {
+ return fPixelRef->lockPixelsAreWritable();
+ } else {
+ return fPixels != NULL;
+ }
+}
+
void SkBitmap::setPixels(void* p, SkColorTable* ctable) {
this->freePixels();
fPixels = p;
diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp
index 78b2dcc2ef..b4f5866981 100644
--- a/src/core/SkDevice.cpp
+++ b/src/core/SkDevice.cpp
@@ -57,11 +57,15 @@ SkMetaData& SkDevice::getMetaData() {
}
void SkDevice::lockPixels() {
- fBitmap.lockPixels();
+ if (fBitmap.lockPixelsAreWritable()) {
+ fBitmap.lockPixels();
+ }
}
void SkDevice::unlockPixels() {
- fBitmap.unlockPixels();
+ if (fBitmap.lockPixelsAreWritable()) {
+ fBitmap.unlockPixels();
+ }
}
const SkBitmap& SkDevice::accessBitmap(bool changePixels) {
diff --git a/src/core/SkPixelRef.cpp b/src/core/SkPixelRef.cpp
index 967a8721b9..f8508911e7 100644
--- a/src/core/SkPixelRef.cpp
+++ b/src/core/SkPixelRef.cpp
@@ -4,7 +4,8 @@
static SkMutex gPixelRefMutex;
-extern int32_t SkNextPixelRefGenerationID() {
+extern int32_t SkNextPixelRefGenerationID();
+int32_t SkNextPixelRefGenerationID() {
static int32_t gPixelRefGenerationID;
// do a loop in case our global wraps around, as we never want to
// return a 0
@@ -63,6 +64,14 @@ void SkPixelRef::unlockPixels() {
}
}
+bool SkPixelRef::lockPixelsAreWritable() const {
+ return this->onLockPixelsAreWritable();
+}
+
+bool SkPixelRef::onLockPixelsAreWritable() const {
+ return true;
+}
+
uint32_t SkPixelRef::getGenerationID() const {
if (0 == fGenerationID) {
fGenerationID = SkNextPixelRefGenerationID();