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 20 matching lines...) Expand all Loading... | |
31 SkNotifyBitmapGenIDIsStale(this->uniqueID()); | 31 SkNotifyBitmapGenIDIsStale(this->uniqueID()); |
32 } | 32 } |
33 } | 33 } |
34 | 34 |
35 extern void SkTextureImageApplyBudgetedDecision(SkImage* image) { | 35 extern void SkTextureImageApplyBudgetedDecision(SkImage* image) { |
36 if (as_IB(image)->getTexture()) { | 36 if (as_IB(image)->getTexture()) { |
37 ((SkImage_Gpu*)image)->applyBudgetDecision(); | 37 ((SkImage_Gpu*)image)->applyBudgetDecision(); |
38 } | 38 } |
39 } | 39 } |
40 | 40 |
41 static SkImageInfo make_info(int w, int h, bool isOpaque) { | |
42 return SkImageInfo::MakeN32(w, h, isOpaque ? kOpaque_SkAlphaType : kPremul_S kAlphaType); | |
43 } | |
44 | |
41 bool SkImage_Gpu::getROPixels(SkBitmap* dst) const { | 45 bool SkImage_Gpu::getROPixels(SkBitmap* dst) const { |
42 if (SkBitmapCache::Find(this->uniqueID(), dst)) { | 46 if (SkBitmapCache::Find(this->uniqueID(), dst)) { |
43 SkASSERT(dst->getGenerationID() == this->uniqueID()); | 47 SkASSERT(dst->getGenerationID() == this->uniqueID()); |
44 SkASSERT(dst->isImmutable()); | 48 SkASSERT(dst->isImmutable()); |
45 SkASSERT(dst->getPixels()); | 49 SkASSERT(dst->getPixels()); |
46 return true; | 50 return true; |
47 } | 51 } |
48 | 52 |
49 SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaTyp e; | 53 if (!dst->tryAllocPixels(make_info(this->width(), this->height(), this->isOp aque()))) { |
50 if (!dst->tryAllocPixels(SkImageInfo::MakeN32(this->width(), this->height(), at))) { | |
51 return false; | 54 return false; |
52 } | 55 } |
53 if (!fTexture->readPixels(0, 0, dst->width(), dst->height(), kSkia8888_GrPix elConfig, | 56 if (!fTexture->readPixels(0, 0, dst->width(), dst->height(), kSkia8888_GrPix elConfig, |
54 dst->getPixels(), dst->rowBytes())) { | 57 dst->getPixels(), dst->rowBytes())) { |
55 return false; | 58 return false; |
56 } | 59 } |
57 | 60 |
58 dst->pixelRef()->setImmutableWithID(this->uniqueID()); | 61 dst->pixelRef()->setImmutableWithID(this->uniqueID()); |
59 SkBitmapCache::Add(this->uniqueID(), *dst); | 62 SkBitmapCache::Add(this->uniqueID(), *dst); |
60 fAddedRasterVersionToCache.store(true); | 63 fAddedRasterVersionToCache.store(true); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 if (!subTx) { | 179 if (!subTx) { |
177 return nullptr; | 180 return nullptr; |
178 } | 181 } |
179 ctx->copySurface(subTx, fTexture, subset, SkIPoint::Make(0, 0)); | 182 ctx->copySurface(subTx, fTexture, subset, SkIPoint::Make(0, 0)); |
180 return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, fAl phaType, subTx, | 183 return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, fAl phaType, subTx, |
181 fBudgeted); | 184 fBudgeted); |
182 } | 185 } |
183 | 186 |
184 //////////////////////////////////////////////////////////////////////////////// /////////////////// | 187 //////////////////////////////////////////////////////////////////////////////// /////////////////// |
185 | 188 |
189 #include "SkBitmapDevice.h" | |
190 #include "SkGrPixelRef.h" | |
191 #include "SkImageFilter.h" | |
192 | |
193 class SkGpuImageFilterProxy : public SkImageFilter::Proxy { | |
194 GrContext* fCtx; | |
195 | |
196 public: | |
197 SkGpuImageFilterProxy(GrContext* ctx) : fCtx(ctx) {} | |
198 | |
199 SkBaseDevice* createDevice(int width, int height) override { | |
200 GrSurfaceDesc desc; | |
201 desc.fConfig = kSkia8888_GrPixelConfig; | |
202 desc.fFlags = kRenderTarget_GrSurfaceFlag; | |
203 desc.fWidth = width; | |
204 desc.fHeight = height; | |
205 desc.fSampleCnt = 0; | |
206 | |
207 SkAutoTUnref<GrTexture> texture(fCtx->textureProvider()->createTexture(d esc, true)); | |
208 | |
209 if (texture) { | |
210 SkSurfaceProps props(0, kUnknown_SkPixelGeometry); | |
211 return SkGpuDevice::Create(texture->asRenderTarget(), width, height, &props, | |
212 SkGpuDevice::kClear_InitContents); | |
213 } else { | |
214 return nullptr; | |
215 } | |
216 } | |
217 | |
218 bool filterImage(const SkImageFilter*, const SkBitmap&, const SkImageFilter: :Context&, | |
219 SkBitmap*, SkIPoint*) override { | |
220 return false; | |
221 } | |
222 }; | |
223 | |
224 SkImage* SkImage_Gpu::onApplyFilter(SkImageFilter* filter, SkIPoint* offsetResul t, | |
225 bool forceResultToOriginalSize) const { | |
226 if (!forceResultToOriginalSize || !filter->canFilterImageGPU()) { | |
227 return this->INHERITED::onApplyFilter(filter, offsetResult, forceResultT oOriginalSize); | |
228 } | |
229 | |
230 const SkImageInfo info = make_info(this->width(), this->height(), this->isOp aque()); | |
231 SkAutoTUnref<SkGrPixelRef> pr(new SkGrPixelRef(info, fTexture)); | |
232 SkBitmap src; | |
233 src.setInfo(info); | |
234 src.setPixelRef(pr, 0, 0); | |
235 | |
236 GrContext* context = fTexture->getContext(); | |
237 SkGpuImageFilterProxy proxy(context); | |
238 SkImageFilter::Context ctx(SkMatrix::I(), | |
239 SkIRect::MakeWH(this->width(), this->height()), | |
240 SkImageFilter::Cache::Get()); | |
241 | |
242 SkBitmap dst; | |
243 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
| |
244 return new SkImage_Gpu(dst.width(), dst.height(), kNeedNewImageUniqueID, info.alphaType(), | |
245 dst.getTexture(), SkSurface::kNo_Budgeted); | |
246 } | |
247 return nullptr; | |
248 } | |
249 | |
250 //////////////////////////////////////////////////////////////////////////////// /////////////////// | |
251 | |
186 static SkImage* new_wrapped_texture_common(GrContext* ctx, const GrBackendTextur eDesc& desc, | 252 static SkImage* new_wrapped_texture_common(GrContext* ctx, const GrBackendTextur eDesc& desc, |
187 SkAlphaType at, GrWrapOwnership owner ship, | 253 SkAlphaType at, GrWrapOwnership owner ship, |
188 SkImage::TextureReleaseProc releasePr oc, | 254 SkImage::TextureReleaseProc releasePr oc, |
189 SkImage::ReleaseContext releaseCtx) { | 255 SkImage::ReleaseContext releaseCtx) { |
190 if (desc.fWidth <= 0 || desc.fHeight <= 0) { | 256 if (desc.fWidth <= 0 || desc.fHeight <= 0) { |
191 return nullptr; | 257 return nullptr; |
192 } | 258 } |
193 SkAutoTUnref<GrTexture> tex(ctx->textureProvider()->wrapBackendTexture(desc, ownership)); | 259 SkAutoTUnref<GrTexture> tex(ctx->textureProvider()->wrapBackendTexture(desc, ownership)); |
194 if (!tex) { | 260 if (!tex) { |
195 return nullptr; | 261 return nullptr; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
323 if (!dst) { | 389 if (!dst) { |
324 return nullptr; | 390 return nullptr; |
325 } | 391 } |
326 | 392 |
327 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); | 393 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); |
328 const SkIPoint dstP = SkIPoint::Make(0, 0); | 394 const SkIPoint dstP = SkIPoint::Make(0, 0); |
329 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp); | 395 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp); |
330 return dst; | 396 return dst; |
331 } | 397 } |
332 | 398 |
OLD | NEW |