aboutsummaryrefslogtreecommitdiffstats
path: root/src/core/SkBitmap.cpp
diff options
context:
space:
mode:
authorLucas Crowthers <lucasc@codeaurora.org>2012-12-03 17:21:30 -0500
committerSteve Kondik <shade@chemlab.org>2013-03-04 15:46:32 -0800
commit705eb622415dc3db0d1740ff29aa0fbf4e8aafa5 (patch)
treeb2c036b96b9eb54bc9d35aa46e0cbf893afe86f0 /src/core/SkBitmap.cpp
parent425325c48d72df437bd734ba0820403204fa79ae (diff)
downloadexternal_skia-705eb622415dc3db0d1740ff29aa0fbf4e8aafa5.zip
external_skia-705eb622415dc3db0d1740ff29aa0fbf4e8aafa5.tar.gz
external_skia-705eb622415dc3db0d1740ff29aa0fbf4e8aafa5.tar.bz2
Skia: Introduce caching of unscaled Bitmaps.
This allows skia to choose whether to use the prescaled bitmap or the unscaled bitmap depending on which would be optimal in the current situation. This commit also introduces two functions necessary for properly resizing Rects when using the non-pre-scaled bitmaps. CRs-fixed: 451681 Change-Id: I36779d8a680a3ced7c28da492e879de02c7e87a5
Diffstat (limited to 'src/core/SkBitmap.cpp')
-rw-r--r--src/core/SkBitmap.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp
index 0b98513..84bb9b2 100644
--- a/src/core/SkBitmap.cpp
+++ b/src/core/SkBitmap.cpp
@@ -116,6 +116,7 @@ SkBitmap& SkBitmap::operator=(const SkBitmap& src) {
} else { // we have a pixelref, so pixels/ctable reflect it
// ignore the values from the memcpy
fPixels = NULL;
+ fUnscaledBitmap = NULL;
fColorTable = NULL;
// Note that what to for genID is somewhat arbitrary. We have no
// way to track changes to raw pixels across multiple SkBitmaps.
@@ -137,6 +138,7 @@ void SkBitmap::swap(SkBitmap& other) {
SkTSwap(fPixelLockCount, other.fPixelLockCount);
SkTSwap(fMipMap, other.fMipMap);
SkTSwap(fPixels, other.fPixels);
+ SkTSwap(fUnscaledBitmap, other.fUnscaledBitmap);
SkTSwap(fRawPixelGenerationID, other.fRawPixelGenerationID);
SkTSwap(fRowBytes, other.fRowBytes);
SkTSwap(fWidth, other.fWidth);
@@ -291,10 +293,18 @@ void SkBitmap::updatePixelsFromRef() const {
p = (char*)p + fPixelRefOffset;
}
fPixels = p;
+ if (NULL != fUnscaledBitmap) {
+ delete fUnscaledBitmap;
+ fUnscaledBitmap = NULL;
+ }
SkRefCnt_SafeAssign(fColorTable, fPixelRef->colorTable());
} else {
SkASSERT(0 == fPixelLockCount);
fPixels = NULL;
+ if (NULL != fUnscaledBitmap) {
+ delete fUnscaledBitmap;
+ fUnscaledBitmap = NULL;
+ }
if (fColorTable) {
fColorTable->unref();
fColorTable = NULL;
@@ -377,6 +387,8 @@ void SkBitmap::freePixels() {
fColorTable = NULL;
}
+ freeUnscaledBitmap();
+
if (NULL != fPixelRef) {
if (fPixelLockCount > 0) {
fPixelRef->unlockPixels();
@@ -389,6 +401,13 @@ void SkBitmap::freePixels() {
fPixels = NULL;
}
+void SkBitmap::freeUnscaledBitmap() {
+ if (NULL != fUnscaledBitmap) {
+ delete fUnscaledBitmap;
+ fUnscaledBitmap = NULL;
+ }
+}
+
void SkBitmap::freeMipMap() {
if (fMipMap) {
fMipMap->unref();
@@ -888,6 +907,7 @@ bool SkBitmap::copyTo(SkBitmap* dst, Config dstConfig, Allocator* alloc) const {
// did we get lucky and we can just return tmpSrc?
if (tmpSrc.config() == dstConfig && NULL == alloc) {
dst->swap(tmpSrc);
+ dst->fUnscaledBitmap = NULL;
return true;
}
@@ -950,6 +970,7 @@ bool SkBitmap::copyTo(SkBitmap* dst, Config dstConfig, Allocator* alloc) const {
tmpDst.setIsOpaque(src->isOpaque());
dst->swap(tmpDst);
+ dst->fUnscaledBitmap = NULL;
return true;
}