aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar senorblanco <senorblanco@chromium.org>2015-10-20 10:17:34 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-10-20 10:17:34 -0700
commit1d3ff434954189e194c468f429598465146dcf4b (patch)
treeb26baea51421dca92277b8adfca8f24dcb1a3d62 /src
parent0bccd8749bdce79b2d71518fe65783b1a9b06445 (diff)
Image filters: Replace all use of tryAllocPixels() with createDevice().
In order to have a central pinch point for bitmap allocation, change all filters to use Proxy::createDevice() instead of allocating memory directly with SkBitmap::tryAllocPixels(). This will aid in moving filter backing stores and caches to discardable memory. BUG=skia: Review URL: https://codereview.chromium.org/1414843003
Diffstat (limited to 'src')
-rw-r--r--src/effects/SkAlphaThresholdFilter.cpp8
-rw-r--r--src/effects/SkBlurImageFilter.cpp12
-rw-r--r--src/effects/SkDisplacementMapEffect.cpp6
-rw-r--r--src/effects/SkLightingImageFilter.cpp11
-rw-r--r--src/effects/SkMagnifierImageFilter.cpp8
-rw-r--r--src/effects/SkMatrixConvolutionImageFilter.cpp16
-rw-r--r--src/effects/SkMorphologyImageFilter.cpp17
7 files changed, 57 insertions, 21 deletions
diff --git a/src/effects/SkAlphaThresholdFilter.cpp b/src/effects/SkAlphaThresholdFilter.cpp
index 32de52250a..e7a4c4ffd4 100644
--- a/src/effects/SkAlphaThresholdFilter.cpp
+++ b/src/effects/SkAlphaThresholdFilter.cpp
@@ -7,6 +7,7 @@
#include "SkAlphaThresholdFilter.h"
#include "SkBitmap.h"
+#include "SkDevice.h"
#include "SkReadBuffer.h"
#include "SkWriteBuffer.h"
#include "SkRegion.h"
@@ -303,7 +304,7 @@ void SkAlphaThresholdFilterImpl::flatten(SkWriteBuffer& buffer) const {
buffer.writeRegion(fRegion);
}
-bool SkAlphaThresholdFilterImpl::onFilterImage(Proxy*, const SkBitmap& src,
+bool SkAlphaThresholdFilterImpl::onFilterImage(Proxy* proxy, const SkBitmap& src,
const Context& ctx, SkBitmap* dst,
SkIPoint* offset) const {
SkASSERT(src.colorType() == kN32_SkColorType);
@@ -323,9 +324,12 @@ bool SkAlphaThresholdFilterImpl::onFilterImage(Proxy*, const SkBitmap& src,
return false;
}
- if (!dst->tryAllocPixels(src.info())) {
+ SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(src.width(), src.height()));
+ if (!device) {
return false;
}
+ *dst = device->accessBitmap(false);
+ SkAutoLockPixels alp_dst(*dst);
U8CPU innerThreshold = (U8CPU)(fInnerThreshold * 0xFF);
U8CPU outerThreshold = (U8CPU)(fOuterThreshold * 0xFF);
diff --git a/src/effects/SkBlurImageFilter.cpp b/src/effects/SkBlurImageFilter.cpp
index 20976968fe..8398f48b7f 100644
--- a/src/effects/SkBlurImageFilter.cpp
+++ b/src/effects/SkBlurImageFilter.cpp
@@ -8,6 +8,7 @@
#include "SkBitmap.h"
#include "SkBlurImageFilter.h"
#include "SkColorPriv.h"
+#include "SkDevice.h"
#include "SkGpuBlurUtils.h"
#include "SkOpts.h"
#include "SkReadBuffer.h"
@@ -90,9 +91,12 @@ bool SkBlurImageFilter::onFilterImage(Proxy* proxy,
return false;
}
- if (!dst->tryAllocPixels(src.info().makeWH(srcBounds.width(), srcBounds.height()))) {
+ SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(srcBounds.width(), srcBounds.height()));
+ if (!device) {
return false;
}
+ *dst = device->accessBitmap(false);
+ SkAutoLockPixels alp_dst(*dst);
dst->getBounds(&dstBounds);
SkVector sigma = mapSigma(fSigma, ctx.ctm());
@@ -113,10 +117,12 @@ bool SkBlurImageFilter::onFilterImage(Proxy* proxy,
return true;
}
- SkBitmap temp;
- if (!temp.tryAllocPixels(dst->info())) {
+ SkAutoTUnref<SkBaseDevice> tempDevice(proxy->createDevice(dst->width(), dst->height()));
+ if (!tempDevice) {
return false;
}
+ SkBitmap temp = tempDevice->accessBitmap(false);
+ SkAutoLockPixels alpTemp(temp);
offset->fX = srcBounds.fLeft;
offset->fY = srcBounds.fTop;
diff --git a/src/effects/SkDisplacementMapEffect.cpp b/src/effects/SkDisplacementMapEffect.cpp
index 4be8d77351..387877941d 100644
--- a/src/effects/SkDisplacementMapEffect.cpp
+++ b/src/effects/SkDisplacementMapEffect.cpp
@@ -6,6 +6,7 @@
*/
#include "SkDisplacementMapEffect.h"
+#include "SkDevice.h"
#include "SkReadBuffer.h"
#include "SkWriteBuffer.h"
#include "SkUnPreMultiply.h"
@@ -239,9 +240,12 @@ bool SkDisplacementMapEffect::onFilterImage(Proxy* proxy,
return false;
}
- if (!dst->tryAllocPixels(color.info().makeWH(bounds.width(), bounds.height()))) {
+ SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds.height()));
+ if (!device) {
return false;
}
+ *dst = device->accessBitmap(false);
+ SkAutoLockPixels alp_dst(*dst);
SkVector scale = SkVector::Make(fScale, fScale);
ctx.ctm().mapVectors(&scale, 1);
diff --git a/src/effects/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp
index 199bb4d684..bac83e537d 100644
--- a/src/effects/SkLightingImageFilter.cpp
+++ b/src/effects/SkLightingImageFilter.cpp
@@ -8,6 +8,7 @@
#include "SkLightingImageFilter.h"
#include "SkBitmap.h"
#include "SkColorPriv.h"
+#include "SkDevice.h"
#include "SkPoint3.h"
#include "SkReadBuffer.h"
#include "SkTypes.h"
@@ -1190,9 +1191,12 @@ bool SkDiffuseLightingImageFilter::onFilterImage(Proxy* proxy,
return false;
}
- if (!dst->tryAllocPixels(src.info().makeWH(bounds.width(), bounds.height()))) {
+ SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds.height()));
+ if (!device) {
return false;
}
+ *dst = device->accessBitmap(false);
+ SkAutoLockPixels alp_dst(*dst);
SkMatrix matrix(ctx.ctm());
matrix.postTranslate(SkIntToScalar(-srcOffset.x()), SkIntToScalar(-srcOffset.y()));
@@ -1331,9 +1335,12 @@ bool SkSpecularLightingImageFilter::onFilterImage(Proxy* proxy,
return false;
}
- if (!dst->tryAllocPixels(src.info().makeWH(bounds.width(), bounds.height()))) {
+ SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds.height()));
+ if (!device) {
return false;
}
+ *dst = device->accessBitmap(false);
+ SkAutoLockPixels alp_dst(*dst);
SpecularLightingType lightingType(fKS, fShininess);
offset->fX = bounds.left();
diff --git a/src/effects/SkMagnifierImageFilter.cpp b/src/effects/SkMagnifierImageFilter.cpp
index 9138c867b5..903f34ca14 100644
--- a/src/effects/SkMagnifierImageFilter.cpp
+++ b/src/effects/SkMagnifierImageFilter.cpp
@@ -8,6 +8,7 @@
#include "SkBitmap.h"
#include "SkMagnifierImageFilter.h"
#include "SkColorPriv.h"
+#include "SkDevice.h"
#include "SkReadBuffer.h"
#include "SkWriteBuffer.h"
#include "SkValidationUtils.h"
@@ -300,7 +301,7 @@ void SkMagnifierImageFilter::flatten(SkWriteBuffer& buffer) const {
buffer.writeScalar(fInset);
}
-bool SkMagnifierImageFilter::onFilterImage(Proxy*, const SkBitmap& src,
+bool SkMagnifierImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& src,
const Context&, SkBitmap* dst,
SkIPoint* offset) const {
if ((src.colorType() != kN32_SkColorType) ||
@@ -315,9 +316,12 @@ bool SkMagnifierImageFilter::onFilterImage(Proxy*, const SkBitmap& src,
return false;
}
- if (!dst->tryAllocPixels(src.info())) {
+ SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(src.width(), src.height()));
+ if (!device) {
return false;
}
+ *dst = device->accessBitmap(false);
+ SkAutoLockPixels alp_dst(*dst);
SkScalar inv_inset = fInset > 0 ? SkScalarInvert(fInset) : SK_Scalar1;
diff --git a/src/effects/SkMatrixConvolutionImageFilter.cpp b/src/effects/SkMatrixConvolutionImageFilter.cpp
index 67813fd259..e58eec10f4 100644
--- a/src/effects/SkMatrixConvolutionImageFilter.cpp
+++ b/src/effects/SkMatrixConvolutionImageFilter.cpp
@@ -8,6 +8,7 @@
#include "SkMatrixConvolutionImageFilter.h"
#include "SkBitmap.h"
#include "SkColorPriv.h"
+#include "SkDevice.h"
#include "SkReadBuffer.h"
#include "SkWriteBuffer.h"
#include "SkRect.h"
@@ -241,16 +242,18 @@ void SkMatrixConvolutionImageFilter::filterBorderPixels(const SkBitmap& src,
// FIXME: This should be refactored to SkImageFilterUtils for
// use by other filters. For now, we assume the input is always
// premultiplied and unpremultiply it
-static SkBitmap unpremultiplyBitmap(const SkBitmap& src)
+static SkBitmap unpremultiplyBitmap(SkImageFilter::Proxy* proxy, const SkBitmap& src)
{
SkAutoLockPixels alp(src);
if (!src.getPixels()) {
return SkBitmap();
}
- SkBitmap result;
- if (!result.tryAllocPixels(src.info())) {
+ SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(src.width(), src.height()));
+ if (!device) {
return SkBitmap();
}
+ SkBitmap result = device->accessBitmap(false);
+ SkAutoLockPixels alp_result(result);
for (int y = 0; y < src.height(); ++y) {
const uint32_t* srcRow = src.getAddr32(0, y);
uint32_t* dstRow = result.getAddr32(0, y);
@@ -282,7 +285,7 @@ bool SkMatrixConvolutionImageFilter::onFilterImage(Proxy* proxy,
}
if (!fConvolveAlpha && !src.isOpaque()) {
- src = unpremultiplyBitmap(src);
+ src = unpremultiplyBitmap(proxy, src);
}
SkAutoLockPixels alp(src);
@@ -290,9 +293,12 @@ bool SkMatrixConvolutionImageFilter::onFilterImage(Proxy* proxy,
return false;
}
- if (!result->tryAllocPixels(src.info().makeWH(bounds.width(), bounds.height()))) {
+ SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds.height()));
+ if (!device) {
return false;
}
+ *result = device->accessBitmap(false);
+ SkAutoLockPixels alp_result(*result);
offset->fX = bounds.fLeft;
offset->fY = bounds.fTop;
diff --git a/src/effects/SkMorphologyImageFilter.cpp b/src/effects/SkMorphologyImageFilter.cpp
index 416bd23567..4e08d9dd73 100644
--- a/src/effects/SkMorphologyImageFilter.cpp
+++ b/src/effects/SkMorphologyImageFilter.cpp
@@ -8,6 +8,7 @@
#include "SkMorphologyImageFilter.h"
#include "SkBitmap.h"
#include "SkColorPriv.h"
+#include "SkDevice.h"
#include "SkOpts.h"
#include "SkReadBuffer.h"
#include "SkRect.h"
@@ -76,10 +77,6 @@ bool SkMorphologyImageFilter::filterImageGeneric(SkMorphologyImageFilter::Proc p
return false;
}
- if (!dst->tryAllocPixels(src.info().makeWH(bounds.width(), bounds.height()))) {
- return false;
- }
-
SkVector radius = SkVector::Make(SkIntToScalar(this->radius().width()),
SkIntToScalar(this->radius().height()));
ctx.ctm().mapVectors(&radius, 1);
@@ -100,12 +97,20 @@ bool SkMorphologyImageFilter::filterImageGeneric(SkMorphologyImageFilter::Proc p
return true;
}
- SkBitmap temp;
- if (!temp.tryAllocPixels(dst->info())) {
+ SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds.height()));
+ if (!device) {
return false;
}
+ *dst = device->accessBitmap(false);
+ SkAutoLockPixels alp_dst(*dst);
if (width > 0 && height > 0) {
+ SkAutoTUnref<SkBaseDevice> tempDevice(proxy->createDevice(dst->width(), dst->height()));
+ if (!tempDevice) {
+ return false;
+ }
+ SkBitmap temp = tempDevice->accessBitmap(false);
+ SkAutoLockPixels alp_temp(temp);
callProcX(procX, src, &temp, width, srcBounds);
SkIRect tmpBounds = SkIRect::MakeWH(srcBounds.width(), srcBounds.height());
callProcY(procY, temp, dst, height, tmpBounds);