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 "GrContext.h" | 10 #include "GrContext.h" |
11 #include "GrDrawContext.h" | 11 #include "GrDrawContext.h" |
12 #include "effects/GrYUVtoRGBEffect.h" | 12 #include "effects/GrYUVtoRGBEffect.h" |
13 #include "SkCanvas.h" | 13 #include "SkCanvas.h" |
14 #include "SkGpuDevice.h" | 14 #include "SkGpuDevice.h" |
15 #include "SkPixelRef.h" | 15 #include "SkPixelRef.h" |
16 | 16 |
17 SkImage_Gpu::SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType at, GrText
ure* tex, | 17 SkImage_Gpu::SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType at, GrText
ure* tex, |
18 int sampleCountForNewSurfaces, SkSurface::Budgeted budg
eted) | 18 int sampleCountForNewSurfaces, SkSurface::Budgeted budg
eted) |
19 : INHERITED(w, h, uniqueID, NULL) | 19 : INHERITED(w, h, uniqueID, nullptr) |
20 , fTexture(SkRef(tex)) | 20 , fTexture(SkRef(tex)) |
21 , fSampleCountForNewSurfaces(sampleCountForNewSurfaces) | 21 , fSampleCountForNewSurfaces(sampleCountForNewSurfaces) |
22 , fAlphaType(at) | 22 , fAlphaType(at) |
23 , fBudgeted(budgeted) | 23 , fBudgeted(budgeted) |
24 , fAddedRasterVersionToCache(false) | 24 , fAddedRasterVersionToCache(false) |
25 {} | 25 {} |
26 | 26 |
27 SkImage_Gpu::~SkImage_Gpu() { | 27 SkImage_Gpu::~SkImage_Gpu() { |
28 if (fAddedRasterVersionToCache.load()) { | 28 if (fAddedRasterVersionToCache.load()) { |
29 SkNotifyBitmapGenIDIsStale(this->uniqueID()); | 29 SkNotifyBitmapGenIDIsStale(this->uniqueID()); |
30 } | 30 } |
31 } | 31 } |
32 | 32 |
33 SkSurface* SkImage_Gpu::onNewSurface(const SkImageInfo& info, const SkSurfacePro
ps& props) const { | 33 SkSurface* SkImage_Gpu::onNewSurface(const SkImageInfo& info, const SkSurfacePro
ps& props) const { |
34 GrTexture* tex = this->getTexture(); | 34 GrTexture* tex = this->getTexture(); |
35 SkASSERT(tex); | 35 SkASSERT(tex); |
36 GrContext* ctx = tex->getContext(); | 36 GrContext* ctx = tex->getContext(); |
37 if (!ctx) { | 37 if (!ctx) { |
38 // the texture may have been abandoned, so we have to check | 38 // the texture may have been abandoned, so we have to check |
39 return NULL; | 39 return nullptr; |
40 } | 40 } |
41 // TODO: Change signature of onNewSurface to take a budgeted param. | 41 // TODO: Change signature of onNewSurface to take a budgeted param. |
42 const SkSurface::Budgeted budgeted = SkSurface::kNo_Budgeted; | 42 const SkSurface::Budgeted budgeted = SkSurface::kNo_Budgeted; |
43 return SkSurface::NewRenderTarget(ctx, budgeted, info, fSampleCountForNewSur
faces, &props); | 43 return SkSurface::NewRenderTarget(ctx, budgeted, info, fSampleCountForNewSur
faces, &props); |
44 } | 44 } |
45 | 45 |
46 extern void SkTextureImageApplyBudgetedDecision(SkImage* image) { | 46 extern void SkTextureImageApplyBudgetedDecision(SkImage* image) { |
47 if (as_IB(image)->getTexture()) { | 47 if (as_IB(image)->getTexture()) { |
48 ((SkImage_Gpu*)image)->applyBudgetDecision(); | 48 ((SkImage_Gpu*)image)->applyBudgetDecision(); |
49 } | 49 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 return true; | 131 return true; |
132 } | 132 } |
133 | 133 |
134 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 134 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
135 | 135 |
136 static SkImage* new_wrapped_texture_common(GrContext* ctx, const GrBackendTextur
eDesc& desc, | 136 static SkImage* new_wrapped_texture_common(GrContext* ctx, const GrBackendTextur
eDesc& desc, |
137 SkAlphaType at, GrWrapOwnership owner
ship, | 137 SkAlphaType at, GrWrapOwnership owner
ship, |
138 SkImage::TextureReleaseProc releasePr
oc, | 138 SkImage::TextureReleaseProc releasePr
oc, |
139 SkImage::ReleaseContext releaseCtx) { | 139 SkImage::ReleaseContext releaseCtx) { |
140 if (desc.fWidth <= 0 || desc.fHeight <= 0) { | 140 if (desc.fWidth <= 0 || desc.fHeight <= 0) { |
141 return NULL; | 141 return nullptr; |
142 } | 142 } |
143 SkAutoTUnref<GrTexture> tex(ctx->textureProvider()->wrapBackendTexture(desc,
ownership)); | 143 SkAutoTUnref<GrTexture> tex(ctx->textureProvider()->wrapBackendTexture(desc,
ownership)); |
144 if (!tex) { | 144 if (!tex) { |
145 return NULL; | 145 return nullptr; |
146 } | 146 } |
147 if (releaseProc) { | 147 if (releaseProc) { |
148 tex->setRelease(releaseProc, releaseCtx); | 148 tex->setRelease(releaseProc, releaseCtx); |
149 } | 149 } |
150 | 150 |
151 const SkSurface::Budgeted budgeted = SkSurface::kNo_Budgeted; | 151 const SkSurface::Budgeted budgeted = SkSurface::kNo_Budgeted; |
152 return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, at,
tex, 0, budgeted); | 152 return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, at,
tex, 0, budgeted); |
153 } | 153 } |
154 | 154 |
155 SkImage* SkImage::NewFromTexture(GrContext* ctx, const GrBackendTextureDesc& des
c, SkAlphaType at, | 155 SkImage* SkImage::NewFromTexture(GrContext* ctx, const GrBackendTextureDesc& des
c, SkAlphaType at, |
156 TextureReleaseProc releaseP, ReleaseContext rel
easeC) { | 156 TextureReleaseProc releaseP, ReleaseContext rel
easeC) { |
157 return new_wrapped_texture_common(ctx, desc, at, kBorrow_GrWrapOwnership, re
leaseP, releaseC); | 157 return new_wrapped_texture_common(ctx, desc, at, kBorrow_GrWrapOwnership, re
leaseP, releaseC); |
158 } | 158 } |
159 | 159 |
160 SkImage* SkImage::NewFromAdoptedTexture(GrContext* ctx, const GrBackendTextureDe
sc& desc, | 160 SkImage* SkImage::NewFromAdoptedTexture(GrContext* ctx, const GrBackendTextureDe
sc& desc, |
161 SkAlphaType at) { | 161 SkAlphaType at) { |
162 return new_wrapped_texture_common(ctx, desc, at, kAdopt_GrWrapOwnership, NUL
L, NULL); | 162 return new_wrapped_texture_common(ctx, desc, at, kAdopt_GrWrapOwnership, nul
lptr, nullptr); |
163 } | 163 } |
164 | 164 |
165 SkImage* SkImage::NewFromTextureCopy(GrContext* ctx, const GrBackendTextureDesc&
desc, | 165 SkImage* SkImage::NewFromTextureCopy(GrContext* ctx, const GrBackendTextureDesc&
desc, |
166 SkAlphaType at) { | 166 SkAlphaType at) { |
167 if (desc.fWidth <= 0 || desc.fHeight <= 0) { | 167 if (desc.fWidth <= 0 || desc.fHeight <= 0) { |
168 return NULL; | 168 return nullptr; |
169 } | 169 } |
170 | 170 |
171 SkAutoTUnref<GrTexture> src(ctx->textureProvider()->wrapBackendTexture( | 171 SkAutoTUnref<GrTexture> src(ctx->textureProvider()->wrapBackendTexture( |
172 desc, kBorrow_GrWrapOwnership)); | 172 desc, kBorrow_GrWrapOwnership)); |
173 if (!src) { | 173 if (!src) { |
174 return NULL; | 174 return nullptr; |
175 } | 175 } |
176 | 176 |
177 const bool isBudgeted = true; | 177 const bool isBudgeted = true; |
178 SkAutoTUnref<GrTexture> dst(GrDeepCopyTexture(src, isBudgeted)); | 178 SkAutoTUnref<GrTexture> dst(GrDeepCopyTexture(src, isBudgeted)); |
179 if (!dst) { | 179 if (!dst) { |
180 return NULL; | 180 return nullptr; |
181 } | 181 } |
182 | 182 |
183 const SkSurface::Budgeted budgeted = SkSurface::kYes_Budgeted; | 183 const SkSurface::Budgeted budgeted = SkSurface::kYes_Budgeted; |
184 const int sampleCount = 0; // todo: make this an explicit parameter to newS
urface()? | 184 const int sampleCount = 0; // todo: make this an explicit parameter to newS
urface()? |
185 return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, at,
dst, sampleCount, | 185 return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, at,
dst, sampleCount, |
186 budgeted); | 186 budgeted); |
187 } | 187 } |
188 | 188 |
189 SkImage* SkImage::NewFromYUVTexturesCopy(GrContext* ctx , SkYUVColorSpace colorS
pace, | 189 SkImage* SkImage::NewFromYUVTexturesCopy(GrContext* ctx , SkYUVColorSpace colorS
pace, |
190 const GrBackendObject yuvTextureHandles
[3], | 190 const GrBackendObject yuvTextureHandles
[3], |
191 const SkISize yuvSizes[3], | 191 const SkISize yuvSizes[3], |
192 GrSurfaceOrigin origin) { | 192 GrSurfaceOrigin origin) { |
193 const SkSurface::Budgeted budgeted = SkSurface::kYes_Budgeted; | 193 const SkSurface::Budgeted budgeted = SkSurface::kYes_Budgeted; |
194 | 194 |
195 if (yuvSizes[0].fWidth <= 0 || yuvSizes[0].fHeight <= 0 || | 195 if (yuvSizes[0].fWidth <= 0 || yuvSizes[0].fHeight <= 0 || |
196 yuvSizes[1].fWidth <= 0 || yuvSizes[1].fHeight <= 0 || | 196 yuvSizes[1].fWidth <= 0 || yuvSizes[1].fHeight <= 0 || |
197 yuvSizes[2].fWidth <= 0 || yuvSizes[2].fHeight <= 0) { | 197 yuvSizes[2].fWidth <= 0 || yuvSizes[2].fHeight <= 0) { |
198 return NULL; | 198 return nullptr; |
199 } | 199 } |
200 static const GrPixelConfig kConfig = kAlpha_8_GrPixelConfig; | 200 static const GrPixelConfig kConfig = kAlpha_8_GrPixelConfig; |
201 GrBackendTextureDesc yDesc; | 201 GrBackendTextureDesc yDesc; |
202 yDesc.fConfig = kConfig; | 202 yDesc.fConfig = kConfig; |
203 yDesc.fOrigin = origin; | 203 yDesc.fOrigin = origin; |
204 yDesc.fSampleCnt = 0; | 204 yDesc.fSampleCnt = 0; |
205 yDesc.fTextureHandle = yuvTextureHandles[0]; | 205 yDesc.fTextureHandle = yuvTextureHandles[0]; |
206 yDesc.fWidth = yuvSizes[0].fWidth; | 206 yDesc.fWidth = yuvSizes[0].fWidth; |
207 yDesc.fHeight = yuvSizes[0].fHeight; | 207 yDesc.fHeight = yuvSizes[0].fHeight; |
208 | 208 |
(...skipping 13 matching lines...) Expand all Loading... |
222 vDesc.fWidth = yuvSizes[2].fWidth; | 222 vDesc.fWidth = yuvSizes[2].fWidth; |
223 vDesc.fHeight = yuvSizes[2].fHeight; | 223 vDesc.fHeight = yuvSizes[2].fHeight; |
224 | 224 |
225 SkAutoTUnref<GrTexture> yTex(ctx->textureProvider()->wrapBackendTexture( | 225 SkAutoTUnref<GrTexture> yTex(ctx->textureProvider()->wrapBackendTexture( |
226 yDesc, kBorrow_GrWrapOwnership)); | 226 yDesc, kBorrow_GrWrapOwnership)); |
227 SkAutoTUnref<GrTexture> uTex(ctx->textureProvider()->wrapBackendTexture( | 227 SkAutoTUnref<GrTexture> uTex(ctx->textureProvider()->wrapBackendTexture( |
228 uDesc, kBorrow_GrWrapOwnership)); | 228 uDesc, kBorrow_GrWrapOwnership)); |
229 SkAutoTUnref<GrTexture> vTex(ctx->textureProvider()->wrapBackendTexture( | 229 SkAutoTUnref<GrTexture> vTex(ctx->textureProvider()->wrapBackendTexture( |
230 vDesc, kBorrow_GrWrapOwnership)); | 230 vDesc, kBorrow_GrWrapOwnership)); |
231 if (!yTex || !uTex || !vTex) { | 231 if (!yTex || !uTex || !vTex) { |
232 return NULL; | 232 return nullptr; |
233 } | 233 } |
234 | 234 |
235 GrSurfaceDesc dstDesc; | 235 GrSurfaceDesc dstDesc; |
236 // Needs to be a render target in order to draw to it for the yuv->rgb conve
rsion. | 236 // Needs to be a render target in order to draw to it for the yuv->rgb conve
rsion. |
237 dstDesc.fFlags = kRenderTarget_GrSurfaceFlag; | 237 dstDesc.fFlags = kRenderTarget_GrSurfaceFlag; |
238 dstDesc.fOrigin = origin; | 238 dstDesc.fOrigin = origin; |
239 dstDesc.fWidth = yuvSizes[0].fWidth; | 239 dstDesc.fWidth = yuvSizes[0].fWidth; |
240 dstDesc.fHeight = yuvSizes[0].fHeight; | 240 dstDesc.fHeight = yuvSizes[0].fHeight; |
241 dstDesc.fConfig = kRGBA_8888_GrPixelConfig; | 241 dstDesc.fConfig = kRGBA_8888_GrPixelConfig; |
242 dstDesc.fSampleCnt = 0; | 242 dstDesc.fSampleCnt = 0; |
243 | 243 |
244 SkAutoTUnref<GrTexture> dst(ctx->textureProvider()->createTexture(dstDesc, t
rue)); | 244 SkAutoTUnref<GrTexture> dst(ctx->textureProvider()->createTexture(dstDesc, t
rue)); |
245 if (!dst) { | 245 if (!dst) { |
246 return NULL; | 246 return nullptr; |
247 } | 247 } |
248 | 248 |
249 GrPaint paint; | 249 GrPaint paint; |
250 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 250 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
251 paint.addColorFragmentProcessor(GrYUVtoRGBEffect::Create(paint.getProcessorD
ataManager(), | 251 paint.addColorFragmentProcessor(GrYUVtoRGBEffect::Create(paint.getProcessorD
ataManager(), |
252 yTex, uTex, vTex, y
uvSizes, | 252 yTex, uTex, vTex, y
uvSizes, |
253 colorSpace))->unref
(); | 253 colorSpace))->unref
(); |
254 | 254 |
255 const SkRect rect = SkRect::MakeWH(SkIntToScalar(dstDesc.fWidth), | 255 const SkRect rect = SkRect::MakeWH(SkIntToScalar(dstDesc.fWidth), |
256 SkIntToScalar(dstDesc.fHeight)); | 256 SkIntToScalar(dstDesc.fHeight)); |
257 GrDrawContext* drawContext = ctx->drawContext(); | 257 GrDrawContext* drawContext = ctx->drawContext(); |
258 drawContext->drawRect(dst->asRenderTarget(), GrClip::WideOpen(), paint, SkMa
trix::I(), rect); | 258 drawContext->drawRect(dst->asRenderTarget(), GrClip::WideOpen(), paint, SkMa
trix::I(), rect); |
259 ctx->flushSurfaceWrites(dst); | 259 ctx->flushSurfaceWrites(dst); |
260 return new SkImage_Gpu(dstDesc.fWidth, dstDesc.fHeight, kNeedNewImageUniqueI
D, | 260 return new SkImage_Gpu(dstDesc.fWidth, dstDesc.fHeight, kNeedNewImageUniqueI
D, |
261 kOpaque_SkAlphaType, dst, 0, budgeted); | 261 kOpaque_SkAlphaType, dst, 0, budgeted); |
262 } | 262 } |
263 | 263 |
264 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 264 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
265 | 265 |
266 GrTexture* GrDeepCopyTexture(GrTexture* src, bool budgeted) { | 266 GrTexture* GrDeepCopyTexture(GrTexture* src, bool budgeted) { |
267 GrContext* ctx = src->getContext(); | 267 GrContext* ctx = src->getContext(); |
268 | 268 |
269 GrSurfaceDesc desc = src->desc(); | 269 GrSurfaceDesc desc = src->desc(); |
270 GrTexture* dst = ctx->textureProvider()->createTexture(desc, budgeted, NULL,
0); | 270 GrTexture* dst = ctx->textureProvider()->createTexture(desc, budgeted, nullp
tr, 0); |
271 if (!dst) { | 271 if (!dst) { |
272 return NULL; | 272 return nullptr; |
273 } | 273 } |
274 | 274 |
275 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); | 275 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); |
276 const SkIPoint dstP = SkIPoint::Make(0, 0); | 276 const SkIPoint dstP = SkIPoint::Make(0, 0); |
277 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp); | 277 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp); |
278 return dst; | 278 return dst; |
279 } | 279 } |
280 | 280 |
OLD | NEW |