Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(465)

Side by Side Diff: src/image/SkImage_Gpu.cpp

Issue 1217053003: add SkImage::NewFromBitmap (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 SkImage* SkImage::NewFromTexture(GrContext* ctx, const GrBackendTextureDesc& des c, SkAlphaType at, 137 SkImage* SkImage::NewFromTexture(GrContext* ctx, const GrBackendTextureDesc& des c, SkAlphaType at,
138 TextureReleaseProc releaseP, ReleaseContext rel easeC) { 138 TextureReleaseProc releaseP, ReleaseContext rel easeC) {
139 return new_wrapped_texture_common(ctx, desc, at, kBorrow_GrWrapOwnership, re leaseP, releaseC); 139 return new_wrapped_texture_common(ctx, desc, at, kBorrow_GrWrapOwnership, re leaseP, releaseC);
140 } 140 }
141 141
142 SkImage* SkImage::NewFromAdoptedTexture(GrContext* ctx, const GrBackendTextureDe sc& desc, 142 SkImage* SkImage::NewFromAdoptedTexture(GrContext* ctx, const GrBackendTextureDe sc& desc,
143 SkAlphaType at) { 143 SkAlphaType at) {
144 return new_wrapped_texture_common(ctx, desc, at, kAdopt_GrWrapOwnership, NUL L, NULL); 144 return new_wrapped_texture_common(ctx, desc, at, kAdopt_GrWrapOwnership, NUL L, NULL);
145 } 145 }
146 146
147 SkImage* SkImage::NewFromTextureCopy(GrContext* ctx, const GrBackendTextureDesc& srcDesc, 147 SkImage* SkImage::NewFromTextureCopy(GrContext* ctx, const GrBackendTextureDesc& desc,
148 SkAlphaType at) { 148 SkAlphaType at) {
149 const bool isBudgeted = true; 149 if (desc.fWidth <= 0 || desc.fHeight <= 0) {
150 const SkSurface::Budgeted budgeted = SkSurface::kYes_Budgeted;
151
152 if (srcDesc.fWidth <= 0 || srcDesc.fHeight <= 0) {
153 return NULL; 150 return NULL;
154 } 151 }
152
155 SkAutoTUnref<GrTexture> src(ctx->textureProvider()->wrapBackendTexture( 153 SkAutoTUnref<GrTexture> src(ctx->textureProvider()->wrapBackendTexture(
156 srcDesc, kBorrow_GrWrapOwnership)); 154 desc, kBorrow_GrWrapOwnership));
157 if (!src) { 155 if (!src) {
158 return NULL; 156 return NULL;
159 } 157 }
160 158
161 GrSurfaceDesc dstDesc; 159 const bool isBudgeted = true;
162 // need to be a rendertarget for readpixels to work, instead of kNone_GrSurf aceFlags 160 SkAutoTUnref<GrTexture> dst(GrDeepCopyTexture(src, isBudgeted));
163 dstDesc.fFlags = kRenderTarget_GrSurfaceFlag;
164 dstDesc.fOrigin = srcDesc.fOrigin;
165 dstDesc.fWidth = srcDesc.fWidth;
166 dstDesc.fHeight = srcDesc.fHeight;
167 dstDesc.fConfig = srcDesc.fConfig;
168 dstDesc.fSampleCnt = srcDesc.fSampleCnt;
169
170 SkAutoTUnref<GrTexture> dst(ctx->textureProvider()->createTexture(
171 dstDesc, isBud geted, NULL, 0));
172 if (!dst) { 161 if (!dst) {
173 return NULL; 162 return NULL;
174 } 163 }
175 164
176 const SkIRect srcR = SkIRect::MakeWH(dstDesc.fWidth, dstDesc.fHeight); 165 const SkSurface::Budgeted budgeted = SkSurface::kYes_Budgeted;
177 const SkIPoint dstP = SkIPoint::Make(0, 0);
178 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp);
179
180 const int sampleCount = 0; // todo: make this an explicit parameter to newS urface()? 166 const int sampleCount = 0; // todo: make this an explicit parameter to newS urface()?
181 return SkNEW_ARGS(SkImage_Gpu, (dstDesc.fWidth, dstDesc.fHeight, at, dst, sa mpleCount, 167 return SkNEW_ARGS(SkImage_Gpu, (desc.fWidth, desc.fHeight, at, dst, sampleCo unt, budgeted));
182 budgeted));
183 } 168 }
184 169
185 SkImage* SkImage::NewFromYUVTexturesCopy(GrContext* ctx , SkYUVColorSpace colorS pace, 170 SkImage* SkImage::NewFromYUVTexturesCopy(GrContext* ctx , SkYUVColorSpace colorS pace,
186 const GrBackendObject yuvTextureHandles [3], 171 const GrBackendObject yuvTextureHandles [3],
187 const SkISize yuvSizes[3], 172 const SkISize yuvSizes[3],
188 GrSurfaceOrigin origin) { 173 GrSurfaceOrigin origin) {
189 const SkSurface::Budgeted budgeted = SkSurface::kYes_Budgeted; 174 const SkSurface::Budgeted budgeted = SkSurface::kYes_Budgeted;
190 175
191 if (yuvSizes[0].fWidth <= 0 || yuvSizes[0].fHeight <= 0 || 176 if (yuvSizes[0].fWidth <= 0 || yuvSizes[0].fHeight <= 0 ||
192 yuvSizes[1].fWidth <= 0 || yuvSizes[1].fHeight <= 0 || 177 yuvSizes[1].fWidth <= 0 || yuvSizes[1].fHeight <= 0 ||
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 colorSpace))->unref(); 234 colorSpace))->unref();
250 235
251 const SkRect rect = SkRect::MakeWH(SkIntToScalar(dstDesc.fWidth), 236 const SkRect rect = SkRect::MakeWH(SkIntToScalar(dstDesc.fWidth),
252 SkIntToScalar(dstDesc.fHeight)); 237 SkIntToScalar(dstDesc.fHeight));
253 GrDrawContext* drawContext = ctx->drawContext(); 238 GrDrawContext* drawContext = ctx->drawContext();
254 drawContext->drawRect(dst->asRenderTarget(), GrClip::WideOpen(), paint, SkMa trix::I(), rect); 239 drawContext->drawRect(dst->asRenderTarget(), GrClip::WideOpen(), paint, SkMa trix::I(), rect);
255 ctx->flushSurfaceWrites(dst); 240 ctx->flushSurfaceWrites(dst);
256 return SkNEW_ARGS(SkImage_Gpu, (dstDesc.fWidth, dstDesc.fHeight, kOpaque_SkA lphaType, dst, 0, 241 return SkNEW_ARGS(SkImage_Gpu, (dstDesc.fWidth, dstDesc.fHeight, kOpaque_SkA lphaType, dst, 0,
257 budgeted)); 242 budgeted));
258 } 243 }
244
245 //////////////////////////////////////////////////////////////////////////////// ///////////////////
246
247 GrTexture* GrDeepCopyTexture(GrTexture* src, bool budgeted) {
248 GrContext* ctx = src->getContext();
249
250 GrSurfaceDesc desc = src->desc();
251 // need to be a rendertarget for readpixels to work, instead of kNone_GrSurf aceFlags
252 desc.fFlags = kRenderTarget_GrSurfaceFlag;
253 GrTexture* dst = ctx->textureProvider()->createTexture(desc, budgeted, NULL, 0);
254 if (!dst) {
255 return NULL;
256 }
257
258 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight);
259 const SkIPoint dstP = SkIPoint::Make(0, 0);
260 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp);
261 return dst;
262 }
263
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698