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

Unified Diff: src/image/SkImage_Gpu.cpp

Issue 1390913005: add applyFilter() to SkImage (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase to new effect factories, use stroke to show image bounds Created 5 years, 2 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/image/SkImage_Gpu.h ('k') | tests/ImageFilterTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/image/SkImage_Gpu.cpp
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index ccb27eed833ced3485b5fa31f7ffacfd38b31817..529df3abbd7bdbd5c9cd5a54cfc09dedb6ef8e69 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -38,6 +38,10 @@ extern void SkTextureImageApplyBudgetedDecision(SkImage* image) {
}
}
+static SkImageInfo make_info(int w, int h, bool isOpaque) {
+ return SkImageInfo::MakeN32(w, h, isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
+}
+
bool SkImage_Gpu::getROPixels(SkBitmap* dst) const {
if (SkBitmapCache::Find(this->uniqueID(), dst)) {
SkASSERT(dst->getGenerationID() == this->uniqueID());
@@ -46,8 +50,7 @@ bool SkImage_Gpu::getROPixels(SkBitmap* dst) const {
return true;
}
- SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaType;
- if (!dst->tryAllocPixels(SkImageInfo::MakeN32(this->width(), this->height(), at))) {
+ if (!dst->tryAllocPixels(make_info(this->width(), this->height(), this->isOpaque()))) {
return false;
}
if (!fTexture->readPixels(0, 0, dst->width(), dst->height(), kSkia8888_GrPixelConfig,
@@ -183,6 +186,69 @@ SkImage* SkImage_Gpu::onNewSubset(const SkIRect& subset) const {
///////////////////////////////////////////////////////////////////////////////////////////////////
+#include "SkBitmapDevice.h"
+#include "SkGrPixelRef.h"
+#include "SkImageFilter.h"
+
+class SkGpuImageFilterProxy : public SkImageFilter::Proxy {
+ GrContext* fCtx;
+
+public:
+ SkGpuImageFilterProxy(GrContext* ctx) : fCtx(ctx) {}
+
+ SkBaseDevice* createDevice(int width, int height) override {
+ GrSurfaceDesc desc;
+ desc.fConfig = kSkia8888_GrPixelConfig;
+ desc.fFlags = kRenderTarget_GrSurfaceFlag;
+ desc.fWidth = width;
+ desc.fHeight = height;
+ desc.fSampleCnt = 0;
+
+ SkAutoTUnref<GrTexture> texture(fCtx->textureProvider()->createTexture(desc, true));
+
+ if (texture) {
+ SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
+ return SkGpuDevice::Create(texture->asRenderTarget(), width, height, &props,
+ SkGpuDevice::kClear_InitContents);
+ } else {
+ return nullptr;
+ }
+ }
+
+ bool filterImage(const SkImageFilter*, const SkBitmap&, const SkImageFilter::Context&,
+ SkBitmap*, SkIPoint*) override {
+ return false;
+ }
+};
+
+SkImage* SkImage_Gpu::onApplyFilter(SkImageFilter* filter, SkIPoint* offsetResult,
+ bool forceResultToOriginalSize) const {
+ if (!forceResultToOriginalSize || !filter->canFilterImageGPU()) {
+ return this->INHERITED::onApplyFilter(filter, offsetResult, forceResultToOriginalSize);
+ }
+
+ const SkImageInfo info = make_info(this->width(), this->height(), this->isOpaque());
+ SkAutoTUnref<SkGrPixelRef> pr(new SkGrPixelRef(info, fTexture));
+ SkBitmap src;
+ src.setInfo(info);
+ src.setPixelRef(pr, 0, 0);
+
+ GrContext* context = fTexture->getContext();
+ SkGpuImageFilterProxy proxy(context);
+ SkImageFilter::Context ctx(SkMatrix::I(),
+ SkIRect::MakeWH(this->width(), this->height()),
+ SkImageFilter::Cache::Get());
+
+ SkBitmap dst;
+ if (filter->filterImageGPU(&proxy, src, ctx, &dst, offsetResult)) {
Stephen White 2015/10/14 19:22:23 I'm not 100% certain, but I think if you call filt
+ return new SkImage_Gpu(dst.width(), dst.height(), kNeedNewImageUniqueID, info.alphaType(),
+ dst.getTexture(), SkSurface::kNo_Budgeted);
+ }
+ return nullptr;
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
static SkImage* new_wrapped_texture_common(GrContext* ctx, const GrBackendTextureDesc& desc,
SkAlphaType at, GrWrapOwnership ownership,
SkImage::TextureReleaseProc releaseProc,
« no previous file with comments | « src/image/SkImage_Gpu.h ('k') | tests/ImageFilterTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698