Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Unified Diff: src/effects/SkDisplacementMapEffect.cpp

Issue 920513003: Make filters use SkImage instead of SkBitmap Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/effects/SkComposeImageFilter.cpp ('k') | src/effects/SkDropShadowImageFilter.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/effects/SkDisplacementMapEffect.cpp
diff --git a/src/effects/SkDisplacementMapEffect.cpp b/src/effects/SkDisplacementMapEffect.cpp
index e280817e384fd3ae35445a43de289816754aabb7..ab54fa97258e1cb57938ecc6841d03273b72a5f6 100644
--- a/src/effects/SkDisplacementMapEffect.cpp
+++ b/src/effects/SkDisplacementMapEffect.cpp
@@ -6,10 +6,12 @@
*/
#include "SkDisplacementMapEffect.h"
+#include "SkColorPriv.h"
+#include "SkImagePriv.h"
+#include "SkImage_Base.h"
#include "SkReadBuffer.h"
-#include "SkWriteBuffer.h"
#include "SkUnPreMultiply.h"
-#include "SkColorPriv.h"
+#include "SkWriteBuffer.h"
#if SK_SUPPORT_GPU
#include "GrContext.h"
#include "GrCoordTransform.h"
@@ -206,41 +208,49 @@ void SkDisplacementMapEffect::flatten(SkWriteBuffer& buffer) const {
}
bool SkDisplacementMapEffect::onFilterImage(Proxy* proxy,
- const SkBitmap& src,
+ const SkImage* src,
const Context& ctx,
- SkBitmap* dst,
+ SkAutoTUnref<const SkImage>& dst,
SkIPoint* offset) const {
- SkBitmap displ = src, color = src;
+ SkIRect bounds;
+ SkIPoint colorOffset = SkIPoint::Make(0, 0), displOffset = SkIPoint::Make(0, 0);
+
+ SkAutoTUnref<const SkImage> displ(SkRef(src));
+ SkAutoTUnref<const SkImage> color(SkRef(src));
const SkImageFilter* colorInput = getColorInput();
const SkImageFilter* displInput = getDisplacementInput();
- SkIPoint colorOffset = SkIPoint::Make(0, 0), displOffset = SkIPoint::Make(0, 0);
- if ((colorInput && !colorInput->filterImage(proxy, src, ctx, &color, &colorOffset)) ||
- (displInput && !displInput->filterImage(proxy, src, ctx, &displ, &displOffset))) {
- return false;
- }
- if ((displ.colorType() != kN32_SkColorType) ||
- (color.colorType() != kN32_SkColorType)) {
+
+ if ((colorInput && !colorInput->filterImage(proxy, src, ctx, color, &colorOffset)) ||
+ (displInput && !displInput->filterImage(proxy, src, ctx, displ, &displOffset))) {
return false;
}
- SkIRect bounds;
// Since computeDisplacement does bounds checking on color pixel access, we don't need to pad
// the color bitmap to bounds here.
if (!this->applyCropRect(ctx, color, colorOffset, &bounds)) {
return false;
}
SkIRect displBounds;
- if (!this->applyCropRect(ctx, proxy, displ, &displOffset, &displBounds, &displ)) {
+ if (!this->applyCropRect(ctx, proxy, displ, &displOffset, &displBounds, displ)) {
return false;
}
if (!bounds.intersect(displBounds)) {
return false;
}
- SkAutoLockPixels alp_displacement(displ), alp_color(color);
- if (!displ.getPixels() || !color.getPixels()) {
+
+ SkBitmap displacementBitmap;
+ SkAutoAdoptImageAsN32Bitmap aai_displacement(displ, &displacementBitmap);
+ if (NULL == displacementBitmap.getPixels()) {
+ return false;
+ }
+
+ SkBitmap colorBitmap;
+ SkAutoAdoptImageAsN32Bitmap aai_color(color, &colorBitmap);
+ if (NULL == colorBitmap.getPixels()) {
return false;
}
- if (!dst->tryAllocPixels(color.info().makeWH(bounds.width(), bounds.height()))) {
+ SkBitmap dstBitmap;
+ if (!dstBitmap.tryAllocPixels(colorBitmap.info().makeWH(bounds.width(), bounds.height()))) {
return false;
}
@@ -249,9 +259,19 @@ bool SkDisplacementMapEffect::onFilterImage(Proxy* proxy,
SkIRect colorBounds = bounds;
colorBounds.offset(-colorOffset);
- computeDisplacement(fXChannelSelector, fYChannelSelector, scale, dst,
- &displ, colorOffset - displOffset, &color, colorBounds);
+ computeDisplacement(fXChannelSelector, fYChannelSelector, scale, &dstBitmap,
+ &displacementBitmap, colorOffset - displOffset,
+ &colorBitmap, colorBounds);
+
+ displacementBitmap = SkBitmap();
+ colorBitmap = SkBitmap();
+
+ SkImage* image = SkNewImageFromBitmap(dstBitmap, NULL);
+ if (NULL == image) {
+ return false;
+ }
+ dst.reset(image);
offset->fX = bounds.left();
offset->fY = bounds.top();
return true;
@@ -382,18 +402,19 @@ private:
typedef GrFragmentProcessor INHERITED;
};
-bool SkDisplacementMapEffect::filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx,
- SkBitmap* result, SkIPoint* offset) const {
- SkBitmap colorBM = src;
+bool SkDisplacementMapEffect::filterImageGPU(Proxy* proxy, const SkImage* src, const Context& ctx,
+ SkAutoTUnref<const SkImage>& result,
+ SkIPoint* offset) const {
+ SkAutoTUnref<const SkImage> colorBM(SkRef(src));
SkIPoint colorOffset = SkIPoint::Make(0, 0);
- if (getColorInput() && !getColorInput()->getInputResultGPU(proxy, src, ctx, &colorBM,
+ if (getColorInput() && !getColorInput()->getInputResultGPU(proxy, src, ctx, colorBM,
&colorOffset)) {
return false;
}
- SkBitmap displacementBM = src;
+ SkAutoTUnref<const SkImage> displacementBM(SkRef(src));
SkIPoint displacementOffset = SkIPoint::Make(0, 0);
if (getDisplacementInput() &&
- !getDisplacementInput()->getInputResultGPU(proxy, src, ctx, &displacementBM,
+ !getDisplacementInput()->getInputResultGPU(proxy, src, ctx, displacementBM,
&displacementOffset)) {
return false;
}
@@ -405,14 +426,14 @@ bool SkDisplacementMapEffect::filterImageGPU(Proxy* proxy, const SkBitmap& src,
}
SkIRect displBounds;
if (!this->applyCropRect(ctx, proxy, displacementBM,
- &displacementOffset, &displBounds, &displacementBM)) {
+ &displacementOffset, &displBounds, displacementBM)) {
return false;
}
if (!bounds.intersect(displBounds)) {
return false;
}
- GrTexture* color = colorBM.getTexture();
- GrTexture* displacement = displacementBM.getTexture();
+ GrTexture* color = colorBM->getTexture();
+ GrTexture* displacement = displacementBM->getTexture();
GrContext* context = color->getContext();
GrSurfaceDesc desc;
@@ -450,9 +471,11 @@ bool SkDisplacementMapEffect::filterImageGPU(Proxy* proxy, const SkBitmap& src,
-SkIntToScalar(colorBounds.y()));
context->drawRect(dst->asRenderTarget(), GrClip::WideOpen(), paint, matrix,
SkRect::Make(colorBounds));
+ if (!WrapTexture(dst, bounds.width(), bounds.height(), result)) {
+ return false;
+ }
offset->fX = bounds.left();
offset->fY = bounds.top();
- WrapTexture(dst, bounds.width(), bounds.height(), result);
return true;
}
« no previous file with comments | « src/effects/SkComposeImageFilter.cpp ('k') | src/effects/SkDropShadowImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698