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 "SkImage_Gpu.h" | 8 #include "SkImage_Gpu.h" |
9 #include "GrContext.h" | 9 #include "GrContext.h" |
10 #include "GrDrawContext.h" | 10 #include "GrDrawContext.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 // Should this be handled by Ganesh? todo:? | 107 // Should this be handled by Ganesh? todo:? |
108 // | 108 // |
109 if (kPremul_SkAlphaType == info.alphaType() && kUnpremul_SkAlphaType == fAlp
haType) { | 109 if (kPremul_SkAlphaType == info.alphaType() && kUnpremul_SkAlphaType == fAlp
haType) { |
110 apply_premul(info, pixels, rowBytes); | 110 apply_premul(info, pixels, rowBytes); |
111 } | 111 } |
112 return true; | 112 return true; |
113 } | 113 } |
114 | 114 |
115 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 115 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
116 | 116 |
117 SkImage* SkImage::NewFromTexture(GrContext* ctx, const GrBackendTextureDesc& des
c, SkAlphaType at) { | 117 static SkImage* new_wrapped_texture_common(GrContext* ctx, const GrBackendTextur
eDesc& desc, |
| 118 SkAlphaType at, GrWrapOwnership owner
ship) { |
118 if (desc.fWidth <= 0 || desc.fHeight <= 0) { | 119 if (desc.fWidth <= 0 || desc.fHeight <= 0) { |
119 return NULL; | 120 return NULL; |
120 } | 121 } |
121 SkAutoTUnref<GrTexture> tex(ctx->textureProvider()->wrapBackendTexture(desc)
); | 122 SkAutoTUnref<GrTexture> tex(ctx->textureProvider()->wrapBackendTexture(desc,
ownership)); |
122 if (!tex) { | 123 if (!tex) { |
123 return NULL; | 124 return NULL; |
124 } | 125 } |
125 const SkSurface::Budgeted budgeted = SkSurface::kNo_Budgeted; | 126 const SkSurface::Budgeted budgeted = SkSurface::kNo_Budgeted; |
126 return SkNEW_ARGS(SkImage_Gpu, (desc.fWidth, desc.fHeight, at, tex, 0, budge
ted)); | 127 return SkNEW_ARGS(SkImage_Gpu, (desc.fWidth, desc.fHeight, at, tex, 0, budge
ted)); |
| 128 |
| 129 } |
| 130 |
| 131 SkImage* SkImage::NewFromTexture(GrContext* ctx, const GrBackendTextureDesc& des
c, SkAlphaType at) { |
| 132 return new_wrapped_texture_common(ctx, desc, at, kBorrow_GrWrapOwnership); |
| 133 } |
| 134 |
| 135 SkImage* SkImage::NewFromAdoptedTexture(GrContext* ctx, const GrBackendTextureDe
sc& desc, |
| 136 SkAlphaType at) { |
| 137 return new_wrapped_texture_common(ctx, desc, at, kAdopt_GrWrapOwnership); |
127 } | 138 } |
128 | 139 |
129 SkImage* SkImage::NewFromTextureCopy(GrContext* ctx, const GrBackendTextureDesc&
srcDesc, | 140 SkImage* SkImage::NewFromTextureCopy(GrContext* ctx, const GrBackendTextureDesc&
srcDesc, |
130 SkAlphaType at) { | 141 SkAlphaType at) { |
131 const bool isBudgeted = true; | 142 const bool isBudgeted = true; |
132 const SkSurface::Budgeted budgeted = SkSurface::kYes_Budgeted; | 143 const SkSurface::Budgeted budgeted = SkSurface::kYes_Budgeted; |
133 | 144 |
134 if (srcDesc.fWidth <= 0 || srcDesc.fHeight <= 0) { | 145 if (srcDesc.fWidth <= 0 || srcDesc.fHeight <= 0) { |
135 return NULL; | 146 return NULL; |
136 } | 147 } |
137 SkAutoTUnref<GrTexture> src(ctx->textureProvider()->wrapBackendTexture(srcDe
sc)); | 148 SkAutoTUnref<GrTexture> src(ctx->textureProvider()->wrapBackendTexture( |
| 149 srcDesc, kBorrow_GrWrapOwnership)); |
138 if (!src) { | 150 if (!src) { |
139 return NULL; | 151 return NULL; |
140 } | 152 } |
141 | 153 |
142 GrSurfaceDesc dstDesc; | 154 GrSurfaceDesc dstDesc; |
143 // need to be a rendertarget for readpixels to work, instead of kNone_GrSurf
aceFlags | 155 // need to be a rendertarget for readpixels to work, instead of kNone_GrSurf
aceFlags |
144 dstDesc.fFlags = kRenderTarget_GrSurfaceFlag; | 156 dstDesc.fFlags = kRenderTarget_GrSurfaceFlag; |
145 dstDesc.fOrigin = srcDesc.fOrigin; | 157 dstDesc.fOrigin = srcDesc.fOrigin; |
146 dstDesc.fWidth = srcDesc.fWidth; | 158 dstDesc.fWidth = srcDesc.fWidth; |
147 dstDesc.fHeight = srcDesc.fHeight; | 159 dstDesc.fHeight = srcDesc.fHeight; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 uDesc.fHeight = yuvSizes[1].fHeight; | 204 uDesc.fHeight = yuvSizes[1].fHeight; |
193 | 205 |
194 GrBackendTextureDesc vDesc; | 206 GrBackendTextureDesc vDesc; |
195 vDesc.fConfig = kConfig; | 207 vDesc.fConfig = kConfig; |
196 vDesc.fOrigin = origin; | 208 vDesc.fOrigin = origin; |
197 vDesc.fSampleCnt = 0; | 209 vDesc.fSampleCnt = 0; |
198 vDesc.fTextureHandle = yuvTextureHandles[2]; | 210 vDesc.fTextureHandle = yuvTextureHandles[2]; |
199 vDesc.fWidth = yuvSizes[2].fWidth; | 211 vDesc.fWidth = yuvSizes[2].fWidth; |
200 vDesc.fHeight = yuvSizes[2].fHeight; | 212 vDesc.fHeight = yuvSizes[2].fHeight; |
201 | 213 |
202 SkAutoTUnref<GrTexture> yTex(ctx->textureProvider()->wrapBackendTexture(yDes
c)); | 214 SkAutoTUnref<GrTexture> yTex(ctx->textureProvider()->wrapBackendTexture( |
203 SkAutoTUnref<GrTexture> uTex(ctx->textureProvider()->wrapBackendTexture(uDes
c)); | 215 yDesc, kBorrow_GrWrapOwnership)); |
204 SkAutoTUnref<GrTexture> vTex(ctx->textureProvider()->wrapBackendTexture(vDes
c)); | 216 SkAutoTUnref<GrTexture> uTex(ctx->textureProvider()->wrapBackendTexture( |
| 217 uDesc, kBorrow_GrWrapOwnership)); |
| 218 SkAutoTUnref<GrTexture> vTex(ctx->textureProvider()->wrapBackendTexture( |
| 219 vDesc, kBorrow_GrWrapOwnership)); |
205 if (!yTex || !uTex || !vTex) { | 220 if (!yTex || !uTex || !vTex) { |
206 return NULL; | 221 return NULL; |
207 } | 222 } |
208 | 223 |
209 GrSurfaceDesc dstDesc; | 224 GrSurfaceDesc dstDesc; |
210 // Needs to be a render target in order to draw to it for the yuv->rgb conve
rsion. | 225 // Needs to be a render target in order to draw to it for the yuv->rgb conve
rsion. |
211 dstDesc.fFlags = kRenderTarget_GrSurfaceFlag; | 226 dstDesc.fFlags = kRenderTarget_GrSurfaceFlag; |
212 dstDesc.fOrigin = origin; | 227 dstDesc.fOrigin = origin; |
213 dstDesc.fWidth = yuvSizes[0].fWidth; | 228 dstDesc.fWidth = yuvSizes[0].fWidth; |
214 dstDesc.fHeight = yuvSizes[0].fHeight; | 229 dstDesc.fHeight = yuvSizes[0].fHeight; |
(...skipping 12 matching lines...) Expand all Loading... |
227 colorSpace))->unref(); | 242 colorSpace))->unref(); |
228 | 243 |
229 const SkRect rect = SkRect::MakeWH(SkIntToScalar(dstDesc.fWidth), | 244 const SkRect rect = SkRect::MakeWH(SkIntToScalar(dstDesc.fWidth), |
230 SkIntToScalar(dstDesc.fHeight)); | 245 SkIntToScalar(dstDesc.fHeight)); |
231 GrDrawContext* drawContext = ctx->drawContext(); | 246 GrDrawContext* drawContext = ctx->drawContext(); |
232 drawContext->drawRect(dst->asRenderTarget(), GrClip::WideOpen(), paint, SkMa
trix::I(), rect); | 247 drawContext->drawRect(dst->asRenderTarget(), GrClip::WideOpen(), paint, SkMa
trix::I(), rect); |
233 ctx->flushSurfaceWrites(dst); | 248 ctx->flushSurfaceWrites(dst); |
234 return SkNEW_ARGS(SkImage_Gpu, (dstDesc.fWidth, dstDesc.fHeight, kOpaque_SkA
lphaType, dst, 0, | 249 return SkNEW_ARGS(SkImage_Gpu, (dstDesc.fWidth, dstDesc.fHeight, kOpaque_SkA
lphaType, dst, 0, |
235 budgeted)); | 250 budgeted)); |
236 } | 251 } |
OLD | NEW |