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" |
11 #include "GrContext.h" | 11 #include "GrContext.h" |
12 #include "GrDrawContext.h" | 12 #include "GrDrawContext.h" |
13 #include "GrTextureParamsAdjuster.h" | 13 #include "GrTextureParamsAdjuster.h" |
14 #include "effects/GrYUVtoRGBEffect.h" | 14 #include "effects/GrYUVtoRGBEffect.h" |
15 #include "SkCanvas.h" | 15 #include "SkCanvas.h" |
16 #include "SkGpuDevice.h" | 16 #include "SkGpuDevice.h" |
17 #include "SkGr.h" | 17 #include "SkGr.h" |
18 #include "SkPixelRef.h" | 18 #include "SkPixelRef.h" |
19 | 19 |
20 SkImage_Gpu::SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType at, GrText
ure* tex, | 20 SkImage_Gpu::SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType at, GrText
ure* tex, |
21 SkSurface::Budgeted budgeted) | 21 SkSurface::Budgeted budgeted) |
22 : INHERITED(w, h, uniqueID) | 22 : INHERITED(w, h, uniqueID) |
23 , fTexture(SkRef(tex)) | 23 , fTexture(SkRef(tex)) |
24 , fAlphaType(at) | 24 , fAlphaType(at) |
25 , fBudgeted(budgeted) | 25 , fBudgeted(budgeted) |
26 , fAddedRasterVersionToCache(false) | 26 , fAddedRasterVersionToCache(false) |
27 {} | 27 { |
| 28 SkASSERT(tex->width() == w); |
| 29 SkASSERT(tex->height() == h); |
| 30 } |
28 | 31 |
29 SkImage_Gpu::~SkImage_Gpu() { | 32 SkImage_Gpu::~SkImage_Gpu() { |
30 if (fAddedRasterVersionToCache.load()) { | 33 if (fAddedRasterVersionToCache.load()) { |
31 SkNotifyBitmapGenIDIsStale(this->uniqueID()); | 34 SkNotifyBitmapGenIDIsStale(this->uniqueID()); |
32 } | 35 } |
33 } | 36 } |
34 | 37 |
35 extern void SkTextureImageApplyBudgetedDecision(SkImage* image) { | 38 extern void SkTextureImageApplyBudgetedDecision(SkImage* image) { |
36 if (as_IB(image)->getTexture()) { | 39 if (as_IB(image)->getTexture()) { |
37 ((SkImage_Gpu*)image)->applyBudgetDecision(); | 40 ((SkImage_Gpu*)image)->applyBudgetDecision(); |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 bool forceResultToOriginalSize) const { | 232 bool forceResultToOriginalSize) const { |
230 const SkIRect srcBounds = SkIRect::MakeWH(this->width(), this->height()); | 233 const SkIRect srcBounds = SkIRect::MakeWH(this->width(), this->height()); |
231 | 234 |
232 if (forceResultToOriginalSize) { | 235 if (forceResultToOriginalSize) { |
233 SkBitmap src; | 236 SkBitmap src; |
234 GrWrapTextureInBitmap(fTexture, this->width(), this->height(), this->isO
paque(), &src); | 237 GrWrapTextureInBitmap(fTexture, this->width(), this->height(), this->isO
paque(), &src); |
235 | 238 |
236 const SkIRect clipBounds = srcBounds; | 239 const SkIRect clipBounds = srcBounds; |
237 SkGpuImageFilterProxy proxy(fTexture->getContext()); | 240 SkGpuImageFilterProxy proxy(fTexture->getContext()); |
238 SkAutoTUnref<SkImageFilter::Cache> cache(SkGpuDevice::NewImageFilterCach
e()); | 241 SkAutoTUnref<SkImageFilter::Cache> cache(SkGpuDevice::NewImageFilterCach
e()); |
239 SkImageFilter::Context ctx(SkMatrix::I(), clipBounds, cache); | 242 SkImageFilter::Context ctx(SkMatrix::I(), clipBounds, cache, SkImageFilt
er::kExact_SizeConstraint); |
240 | 243 |
241 SkBitmap dst; | 244 SkBitmap dst; |
242 if (!filter->filterImage(&proxy, src, ctx, &dst, offsetResult)) { | 245 if (!filter->filterImage(&proxy, src, ctx, &dst, offsetResult)) { |
243 return nullptr; | 246 return nullptr; |
244 } | 247 } |
245 return new SkImage_Gpu(dst.width(), dst.height(), kNeedNewImageUniqueID,
dst.alphaType(), | 248 return new SkImage_Gpu(dst.width(), dst.height(), kNeedNewImageUniqueID,
dst.alphaType(), |
246 dst.getTexture(), SkSurface::kNo_Budgeted); | 249 dst.getTexture(), SkSurface::kNo_Budgeted); |
247 } | 250 } |
248 | 251 |
249 const SkIRect dstR = compute_fast_ibounds(filter, srcBounds); | 252 const SkIRect dstR = compute_fast_ibounds(filter, srcBounds); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 if (!dst) { | 405 if (!dst) { |
403 return nullptr; | 406 return nullptr; |
404 } | 407 } |
405 | 408 |
406 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); | 409 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); |
407 const SkIPoint dstP = SkIPoint::Make(0, 0); | 410 const SkIPoint dstP = SkIPoint::Make(0, 0); |
408 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp); | 411 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp); |
409 return dst; | 412 return dst; |
410 } | 413 } |
411 | 414 |
OLD | NEW |