| 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 "GrCaps.h" | 8 #include "GrCaps.h" |
| 9 #include "GrContext.h" | 9 #include "GrContext.h" |
| 10 #include "GrDrawContext.h" | 10 #include "GrDrawContext.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 if (!subTx) { | 145 if (!subTx) { |
| 146 return nullptr; | 146 return nullptr; |
| 147 } | 147 } |
| 148 ctx->copySurface(subTx, fTexture, subset, SkIPoint::Make(0, 0)); | 148 ctx->copySurface(subTx, fTexture, subset, SkIPoint::Make(0, 0)); |
| 149 return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, fAl
phaType, subTx, | 149 return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, fAl
phaType, subTx, |
| 150 fBudgeted); | 150 fBudgeted); |
| 151 } | 151 } |
| 152 | 152 |
| 153 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 153 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 154 | 154 |
| 155 class SkGpuImageFilterProxy : public SkImageFilter::Proxy { | |
| 156 GrContext* fCtx; | |
| 157 | |
| 158 public: | |
| 159 SkGpuImageFilterProxy(GrContext* ctx) : fCtx(ctx) {} | |
| 160 | |
| 161 SkBaseDevice* createDevice(int width, int height) override { | |
| 162 GrSurfaceDesc desc; | |
| 163 desc.fConfig = kSkia8888_GrPixelConfig; | |
| 164 desc.fFlags = kRenderTarget_GrSurfaceFlag; | |
| 165 desc.fWidth = width; | |
| 166 desc.fHeight = height; | |
| 167 desc.fSampleCnt = 0; | |
| 168 | |
| 169 SkAutoTUnref<GrTexture> texture(fCtx->textureProvider()->createTexture(d
esc, true)); | |
| 170 | |
| 171 if (texture) { | |
| 172 SkSurfaceProps props(0, kUnknown_SkPixelGeometry); | |
| 173 return SkGpuDevice::Create(texture->asRenderTarget(), width, height,
&props, | |
| 174 SkGpuDevice::kClear_InitContents); | |
| 175 } else { | |
| 176 return nullptr; | |
| 177 } | |
| 178 } | |
| 179 | |
| 180 bool filterImage(const SkImageFilter* filter, const SkBitmap& src, | |
| 181 const SkImageFilter::Context& ctx, SkBitmap* dst, SkIPoint*
offset) override { | |
| 182 return filter->canFilterImageGPU() && | |
| 183 filter->filterImageGPU(this, src, ctx, dst, offset); | |
| 184 } | |
| 185 }; | |
| 186 | |
| 187 static SkIRect compute_fast_ibounds(SkImageFilter* filter, const SkIRect& srcBou
nds) { | |
| 188 SkRect fastBounds; | |
| 189 fastBounds.set(srcBounds); | |
| 190 filter->computeFastBounds(fastBounds, &fastBounds); | |
| 191 return fastBounds.roundOut(); | |
| 192 } | |
| 193 | |
| 194 SkImage* SkImage_Gpu::onApplyFilter(SkImageFilter* filter, SkIPoint* offsetResul
t, | |
| 195 bool forceResultToOriginalSize) const { | |
| 196 const SkIRect srcBounds = SkIRect::MakeWH(this->width(), this->height()); | |
| 197 | |
| 198 if (forceResultToOriginalSize) { | |
| 199 SkBitmap src; | |
| 200 GrWrapTextureInBitmap(fTexture, this->width(), this->height(), this->isO
paque(), &src); | |
| 201 | |
| 202 const SkIRect clipBounds = srcBounds; | |
| 203 SkGpuImageFilterProxy proxy(fTexture->getContext()); | |
| 204 SkAutoTUnref<SkImageFilter::Cache> cache(SkGpuDevice::NewImageFilterCach
e()); | |
| 205 SkImageFilter::Context ctx(SkMatrix::I(), clipBounds, cache, SkImageFilt
er::kExact_SizeConstraint); | |
| 206 | |
| 207 SkBitmap dst; | |
| 208 if (!filter->filterImage(&proxy, src, ctx, &dst, offsetResult)) { | |
| 209 return nullptr; | |
| 210 } | |
| 211 return new SkImage_Gpu(dst.width(), dst.height(), kNeedNewImageUniqueID,
dst.alphaType(), | |
| 212 dst.getTexture(), SkSurface::kNo_Budgeted); | |
| 213 } | |
| 214 | |
| 215 const SkIRect dstR = compute_fast_ibounds(filter, srcBounds); | |
| 216 | |
| 217 SkImageInfo info = SkImageInfo::MakeN32Premul(dstR.width(), dstR.height()); | |
| 218 SkAutoTUnref<SkSurface> surface(this->onNewSurface(info)); | |
| 219 | |
| 220 SkPaint paint; | |
| 221 paint.setImageFilter(filter); | |
| 222 surface->getCanvas()->drawImage(this, SkIntToScalar(-dstR.x()), SkIntToScala
r(-dstR.y()), | |
| 223 &paint); | |
| 224 | |
| 225 offsetResult->set(dstR.x(), dstR.y()); | |
| 226 return surface->newImageSnapshot(); | |
| 227 } | |
| 228 | |
| 229 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | |
| 230 | |
| 231 static SkImage* new_wrapped_texture_common(GrContext* ctx, const GrBackendTextur
eDesc& desc, | 155 static SkImage* new_wrapped_texture_common(GrContext* ctx, const GrBackendTextur
eDesc& desc, |
| 232 SkAlphaType at, GrWrapOwnership owner
ship, | 156 SkAlphaType at, GrWrapOwnership owner
ship, |
| 233 SkImage::TextureReleaseProc releasePr
oc, | 157 SkImage::TextureReleaseProc releasePr
oc, |
| 234 SkImage::ReleaseContext releaseCtx) { | 158 SkImage::ReleaseContext releaseCtx) { |
| 235 if (desc.fWidth <= 0 || desc.fHeight <= 0) { | 159 if (desc.fWidth <= 0 || desc.fHeight <= 0) { |
| 236 return nullptr; | 160 return nullptr; |
| 237 } | 161 } |
| 238 SkAutoTUnref<GrTexture> tex(ctx->textureProvider()->wrapBackendTexture(desc,
ownership)); | 162 SkAutoTUnref<GrTexture> tex(ctx->textureProvider()->wrapBackendTexture(desc,
ownership)); |
| 239 if (!tex) { | 163 if (!tex) { |
| 240 return nullptr; | 164 return nullptr; |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 if (!dst) { | 292 if (!dst) { |
| 369 return nullptr; | 293 return nullptr; |
| 370 } | 294 } |
| 371 | 295 |
| 372 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); | 296 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); |
| 373 const SkIPoint dstP = SkIPoint::Make(0, 0); | 297 const SkIPoint dstP = SkIPoint::Make(0, 0); |
| 374 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp); | 298 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp); |
| 375 return dst; | 299 return dst; |
| 376 } | 300 } |
| 377 | 301 |
| OLD | NEW |