Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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); | |
|
Stephen White
2015/10/16 20:14:05
This part looks good, I think.
| |
| 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 { |
|
Stephen White
2015/10/16 20:14:05
I'd really appreciate if this could be turned into
reed1
2015/10/16 20:41:52
Adding a variant of the public API that takes a re
Stephen White
2015/10/16 21:12:04
BTW, if we also added an SkMatrix param here, and
Stephen White
2015/10/16 21:12:04
It just seems like it would be very easy:
SkImage
| |
| 225 if (!forceResultToOriginalSize || !filter->canFilterImageGPU()) { | 233 const SkIRect srcBounds = SkIRect::MakeWH(this->width(), this->height()); |
| 226 return this->INHERITED::onApplyFilter(filter, offsetResult, forceResultT oOriginalSize); | 234 |
| 235 if (forceResultToOriginalSize) { | |
| 236 SkBitmap src; | |
| 237 GrWrapTextureInBitmap(fTexture, this->width(), this->height(), this->isO paque(), &src); | |
| 238 | |
| 239 const SkIRect clipBounds = srcBounds; | |
| 240 SkGpuImageFilterProxy proxy(fTexture->getContext()); | |
| 241 SkImageFilter::Context ctx(SkMatrix::I(), clipBounds, SkImageFilter::Cac he::Get()); | |
| 242 | |
| 243 SkBitmap dst; | |
| 244 if (!filter->filterImage(&proxy, src, ctx, &dst, offsetResult)) { | |
| 245 return nullptr; | |
| 246 } | |
| 247 if (dst.getTexture()) { | |
| 248 return new SkImage_Gpu(dst.width(), dst.height(), kNeedNewImageUniqu eID, dst.alphaType(), | |
| 249 dst.getTexture(), SkSurface::kNo_Budgeted); | |
| 250 } | |
| 251 | |
| 252 // fall-through to the drawing case | |
| 253 SkDebugf("------ got raster result from gpu-src using filter %s\n", | |
|
Stephen White
2015/10/16 20:14:05
This shouldn't happen. Is it?
reed1
2015/10/16 20:41:52
Done.
| |
| 254 filter->getTypeName()); | |
| 227 } | 255 } |
| 228 | 256 |
| 229 SkBitmap src; | 257 const SkIRect dstR = forceResultToOriginalSize ? |
| 230 GrWrapTextureInBitmap(fTexture, this->width(), this->height(), this->isOpaqu e(), &src); | 258 srcBounds : compute_fast_ibounds(filter, srcBounds); |
| 231 | 259 |
| 232 GrContext* context = fTexture->getContext(); | 260 SkImageInfo info = SkImageInfo::MakeN32Premul(dstR.width(), dstR.height()); |
| 233 SkGpuImageFilterProxy proxy(context); | 261 SkAutoTUnref<SkSurface> surface(this->onNewSurface(info)); |
| 234 SkImageFilter::Context ctx(SkMatrix::I(), | |
| 235 SkIRect::MakeWH(this->width(), this->height()), | |
| 236 SkImageFilter::Cache::Get()); | |
| 237 | 262 |
| 238 SkBitmap dst; | 263 SkPaint paint; |
| 239 if (filter->filterImageGPU(&proxy, src, ctx, &dst, offsetResult)) { | 264 paint.setImageFilter(filter); |
| 240 return new SkImage_Gpu(dst.width(), dst.height(), kNeedNewImageUniqueID, dst.alphaType(), | 265 surface->getCanvas()->drawImage(this, SkIntToScalar(-dstR.x()), SkIntToScala r(-dstR.y()), |
|
Stephen White
2015/10/16 20:14:05
It looks like if we fall-through here (when fForce
reed1
2015/10/16 20:41:52
Ah, good point. However, I think your previous poi
| |
| 241 dst.getTexture(), SkSurface::kNo_Budgeted); | 266 &paint); |
| 242 } | 267 |
| 243 return nullptr; | 268 offsetResult->set(dstR.x(), dstR.y()); |
| 269 return surface->newImageSnapshot(); | |
| 244 } | 270 } |
| 245 | 271 |
| 246 //////////////////////////////////////////////////////////////////////////////// /////////////////// | 272 //////////////////////////////////////////////////////////////////////////////// /////////////////// |
| 247 | 273 |
| 248 static SkImage* new_wrapped_texture_common(GrContext* ctx, const GrBackendTextur eDesc& desc, | 274 static SkImage* new_wrapped_texture_common(GrContext* ctx, const GrBackendTextur eDesc& desc, |
| 249 SkAlphaType at, GrWrapOwnership owner ship, | 275 SkAlphaType at, GrWrapOwnership owner ship, |
| 250 SkImage::TextureReleaseProc releasePr oc, | 276 SkImage::TextureReleaseProc releasePr oc, |
| 251 SkImage::ReleaseContext releaseCtx) { | 277 SkImage::ReleaseContext releaseCtx) { |
| 252 if (desc.fWidth <= 0 || desc.fHeight <= 0) { | 278 if (desc.fWidth <= 0 || desc.fHeight <= 0) { |
| 253 return nullptr; | 279 return nullptr; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 385 if (!dst) { | 411 if (!dst) { |
| 386 return nullptr; | 412 return nullptr; |
| 387 } | 413 } |
| 388 | 414 |
| 389 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); | 415 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); |
| 390 const SkIPoint dstP = SkIPoint::Make(0, 0); | 416 const SkIPoint dstP = SkIPoint::Make(0, 0); |
| 391 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp); | 417 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp); |
| 392 return dst; | 418 return dst; |
| 393 } | 419 } |
| 394 | 420 |
| OLD | NEW |