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

Side by Side Diff: src/image/SkImage_Gpu.cpp

Issue 1401053003: change SkImage_Gpu to handle all filters (w/ and w/o gpu support (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « gm/spritebitmap.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkBitmapCache.h" 8 #include "SkBitmapCache.h"
9 #include "SkImage_Gpu.h" 9 #include "SkImage_Gpu.h"
10 #include "GrCaps.h" 10 #include "GrCaps.h"
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 207
208 if (texture) { 208 if (texture) {
209 SkSurfaceProps props(0, kUnknown_SkPixelGeometry); 209 SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
210 return SkGpuDevice::Create(texture->asRenderTarget(), width, height, &props, 210 return SkGpuDevice::Create(texture->asRenderTarget(), width, height, &props,
211 SkGpuDevice::kClear_InitContents); 211 SkGpuDevice::kClear_InitContents);
212 } else { 212 } else {
213 return nullptr; 213 return nullptr;
214 } 214 }
215 } 215 }
216 216
217 bool filterImage(const SkImageFilter*, const SkBitmap&, const SkImageFilter: :Context&, 217 bool filterImage(const SkImageFilter* filter, const SkBitmap& src,
218 SkBitmap*, SkIPoint*) override { 218 const SkImageFilter::Context& ctx, SkBitmap* dst, SkIPoint* offset) override {
219 return false; 219 return filter->canFilterImageGPU() &&
220 filter->filterImageGPU(this, src, ctx, dst, offset);
220 } 221 }
221 }; 222 };
222 223
224 static SkIRect compute_fast_ibounds(SkImageFilter* filter, const SkIRect& srcBou nds) {
225 SkRect fastBounds;
226 fastBounds.set(srcBounds);
227 filter->computeFastBounds(fastBounds, &fastBounds);
228 return fastBounds.roundOut();
229 }
230
223 SkImage* SkImage_Gpu::onApplyFilter(SkImageFilter* filter, SkIPoint* offsetResul t, 231 SkImage* SkImage_Gpu::onApplyFilter(SkImageFilter* filter, SkIPoint* offsetResul t,
224 bool forceResultToOriginalSize) const { 232 bool forceResultToOriginalSize) const {
225 if (!forceResultToOriginalSize || !filter->canFilterImageGPU()) { 233 const SkIRect srcBounds = SkIRect::MakeWH(this->width(), this->height());
226 return this->INHERITED::onApplyFilter(filter, offsetResult, forceResultT oOriginalSize);
227 }
228 234
229 SkBitmap src; 235 if (forceResultToOriginalSize) {
230 GrWrapTextureInBitmap(fTexture, this->width(), this->height(), this->isOpaqu e(), &src); 236 SkBitmap src;
237 GrWrapTextureInBitmap(fTexture, this->width(), this->height(), this->isO paque(), &src);
231 238
232 GrContext* context = fTexture->getContext(); 239 const SkIRect clipBounds = srcBounds;
233 SkGpuImageFilterProxy proxy(context); 240 SkGpuImageFilterProxy proxy(fTexture->getContext());
234 SkImageFilter::Context ctx(SkMatrix::I(), 241 SkImageFilter::Context ctx(SkMatrix::I(), clipBounds, SkImageFilter::Cac he::Get());
235 SkIRect::MakeWH(this->width(), this->height()),
236 SkImageFilter::Cache::Get());
237 242
238 SkBitmap dst; 243 SkBitmap dst;
239 if (filter->filterImageGPU(&proxy, src, ctx, &dst, offsetResult)) { 244 if (!filter->filterImage(&proxy, src, ctx, &dst, offsetResult)) {
245 return nullptr;
246 }
240 return new SkImage_Gpu(dst.width(), dst.height(), kNeedNewImageUniqueID, dst.alphaType(), 247 return new SkImage_Gpu(dst.width(), dst.height(), kNeedNewImageUniqueID, dst.alphaType(),
241 dst.getTexture(), SkSurface::kNo_Budgeted); 248 dst.getTexture(), SkSurface::kNo_Budgeted);
242 } 249 }
243 return nullptr; 250
251 const SkIRect dstR = compute_fast_ibounds(filter, srcBounds);
252
253 SkImageInfo info = SkImageInfo::MakeN32Premul(dstR.width(), dstR.height());
254 SkAutoTUnref<SkSurface> surface(this->onNewSurface(info));
255
256 SkPaint paint;
257 paint.setImageFilter(filter);
258 surface->getCanvas()->drawImage(this, SkIntToScalar(-dstR.x()), SkIntToScala r(-dstR.y()),
259 &paint);
260
261 offsetResult->set(dstR.x(), dstR.y());
262 return surface->newImageSnapshot();
244 } 263 }
245 264
246 //////////////////////////////////////////////////////////////////////////////// /////////////////// 265 //////////////////////////////////////////////////////////////////////////////// ///////////////////
247 266
248 static SkImage* new_wrapped_texture_common(GrContext* ctx, const GrBackendTextur eDesc& desc, 267 static SkImage* new_wrapped_texture_common(GrContext* ctx, const GrBackendTextur eDesc& desc,
249 SkAlphaType at, GrWrapOwnership owner ship, 268 SkAlphaType at, GrWrapOwnership owner ship,
250 SkImage::TextureReleaseProc releasePr oc, 269 SkImage::TextureReleaseProc releasePr oc,
251 SkImage::ReleaseContext releaseCtx) { 270 SkImage::ReleaseContext releaseCtx) {
252 if (desc.fWidth <= 0 || desc.fHeight <= 0) { 271 if (desc.fWidth <= 0 || desc.fHeight <= 0) {
253 return nullptr; 272 return nullptr;
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 if (!dst) { 404 if (!dst) {
386 return nullptr; 405 return nullptr;
387 } 406 }
388 407
389 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); 408 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight);
390 const SkIPoint dstP = SkIPoint::Make(0, 0); 409 const SkIPoint dstP = SkIPoint::Make(0, 0);
391 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp); 410 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp);
392 return dst; 411 return dst;
393 } 412 }
394 413
OLDNEW
« no previous file with comments | « gm/spritebitmap.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698