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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 static SkImage* new_wrapped_texture_common(GrContext* ctx, const GrBackendTextur
eDesc& desc, | 117 static SkImage* new_wrapped_texture_common(GrContext* ctx, const GrBackendTextur
eDesc& desc, |
118 SkAlphaType at, GrWrapOwnership owner
ship) { | 118 SkAlphaType at, GrWrapOwnership owner
ship, |
| 119 SkImage::TextureReleaseProc releasePr
oc, |
| 120 SkImage::ReleaseContext releaseCtx) { |
119 if (desc.fWidth <= 0 || desc.fHeight <= 0) { | 121 if (desc.fWidth <= 0 || desc.fHeight <= 0) { |
120 return NULL; | 122 return NULL; |
121 } | 123 } |
122 SkAutoTUnref<GrTexture> tex(ctx->textureProvider()->wrapBackendTexture(desc,
ownership)); | 124 SkAutoTUnref<GrTexture> tex(ctx->textureProvider()->wrapBackendTexture(desc,
ownership)); |
123 if (!tex) { | 125 if (!tex) { |
124 return NULL; | 126 return NULL; |
125 } | 127 } |
| 128 if (releaseProc) { |
| 129 tex->setRelease(releaseProc, releaseCtx); |
| 130 } |
| 131 |
126 const SkSurface::Budgeted budgeted = SkSurface::kNo_Budgeted; | 132 const SkSurface::Budgeted budgeted = SkSurface::kNo_Budgeted; |
127 return SkNEW_ARGS(SkImage_Gpu, (desc.fWidth, desc.fHeight, at, tex, 0, budge
ted)); | 133 return SkNEW_ARGS(SkImage_Gpu, (desc.fWidth, desc.fHeight, at, tex, 0, budge
ted)); |
128 | 134 |
129 } | 135 } |
130 | 136 |
131 SkImage* SkImage::NewFromTexture(GrContext* ctx, const GrBackendTextureDesc& des
c, SkAlphaType at) { | 137 SkImage* SkImage::NewFromTexture(GrContext* ctx, const GrBackendTextureDesc& des
c, SkAlphaType at, |
132 return new_wrapped_texture_common(ctx, desc, at, kBorrow_GrWrapOwnership); | 138 TextureReleaseProc releaseP, ReleaseContext rel
easeC) { |
| 139 return new_wrapped_texture_common(ctx, desc, at, kBorrow_GrWrapOwnership, re
leaseP, releaseC); |
133 } | 140 } |
134 | 141 |
135 SkImage* SkImage::NewFromAdoptedTexture(GrContext* ctx, const GrBackendTextureDe
sc& desc, | 142 SkImage* SkImage::NewFromAdoptedTexture(GrContext* ctx, const GrBackendTextureDe
sc& desc, |
136 SkAlphaType at) { | 143 SkAlphaType at) { |
137 return new_wrapped_texture_common(ctx, desc, at, kAdopt_GrWrapOwnership); | 144 return new_wrapped_texture_common(ctx, desc, at, kAdopt_GrWrapOwnership, NUL
L, NULL); |
138 } | 145 } |
139 | 146 |
140 SkImage* SkImage::NewFromTextureCopy(GrContext* ctx, const GrBackendTextureDesc&
srcDesc, | 147 SkImage* SkImage::NewFromTextureCopy(GrContext* ctx, const GrBackendTextureDesc&
srcDesc, |
141 SkAlphaType at) { | 148 SkAlphaType at) { |
142 const bool isBudgeted = true; | 149 const bool isBudgeted = true; |
143 const SkSurface::Budgeted budgeted = SkSurface::kYes_Budgeted; | 150 const SkSurface::Budgeted budgeted = SkSurface::kYes_Budgeted; |
144 | 151 |
145 if (srcDesc.fWidth <= 0 || srcDesc.fHeight <= 0) { | 152 if (srcDesc.fWidth <= 0 || srcDesc.fHeight <= 0) { |
146 return NULL; | 153 return NULL; |
147 } | 154 } |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 colorSpace))->unref(); | 249 colorSpace))->unref(); |
243 | 250 |
244 const SkRect rect = SkRect::MakeWH(SkIntToScalar(dstDesc.fWidth), | 251 const SkRect rect = SkRect::MakeWH(SkIntToScalar(dstDesc.fWidth), |
245 SkIntToScalar(dstDesc.fHeight)); | 252 SkIntToScalar(dstDesc.fHeight)); |
246 GrDrawContext* drawContext = ctx->drawContext(); | 253 GrDrawContext* drawContext = ctx->drawContext(); |
247 drawContext->drawRect(dst->asRenderTarget(), GrClip::WideOpen(), paint, SkMa
trix::I(), rect); | 254 drawContext->drawRect(dst->asRenderTarget(), GrClip::WideOpen(), paint, SkMa
trix::I(), rect); |
248 ctx->flushSurfaceWrites(dst); | 255 ctx->flushSurfaceWrites(dst); |
249 return SkNEW_ARGS(SkImage_Gpu, (dstDesc.fWidth, dstDesc.fHeight, kOpaque_SkA
lphaType, dst, 0, | 256 return SkNEW_ARGS(SkImage_Gpu, (dstDesc.fWidth, dstDesc.fHeight, kOpaque_SkA
lphaType, dst, 0, |
250 budgeted)); | 257 budgeted)); |
251 } | 258 } |
OLD | NEW |