| 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 "GrCaps.h" | 8 #include "GrCaps.h" |
| 9 #include "GrContext.h" | 9 #include "GrContext.h" |
| 10 #include "GrDrawContext.h" | 10 #include "GrDrawContext.h" |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 if (!drawContext) { | 275 if (!drawContext) { |
| 276 return nullptr; | 276 return nullptr; |
| 277 } | 277 } |
| 278 | 278 |
| 279 drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), rect); | 279 drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), rect); |
| 280 ctx->flushSurfaceWrites(dst); | 280 ctx->flushSurfaceWrites(dst); |
| 281 return new SkImage_Gpu(dstDesc.fWidth, dstDesc.fHeight, kNeedNewImageUniqueI
D, | 281 return new SkImage_Gpu(dstDesc.fWidth, dstDesc.fHeight, kNeedNewImageUniqueI
D, |
| 282 kOpaque_SkAlphaType, dst, budgeted); | 282 kOpaque_SkAlphaType, dst, budgeted); |
| 283 } | 283 } |
| 284 | 284 |
| 285 static SkImage* create_image_from_maker(GrTextureMaker* maker, SkAlphaType at, u
int32_t id) { |
| 286 SkAutoTUnref<GrTexture> texture(maker->refTextureForParams(GrTextureParams::
ClampNoFilter())); |
| 287 if (!texture) { |
| 288 return nullptr; |
| 289 } |
| 290 return new SkImage_Gpu(texture->width(), texture->height(), id, at, texture, |
| 291 SkSurface::kNo_Budgeted); |
| 292 } |
| 293 |
| 294 SkImage* SkImage::newTextureImage(GrContext *context) const { |
| 295 if (!context) { |
| 296 return nullptr; |
| 297 } |
| 298 if (GrTexture* peek = as_IB(this)->peekTexture()) { |
| 299 return peek->getContext() == context ? SkRef(const_cast<SkImage*>(this))
: nullptr; |
| 300 } |
| 301 // No way to check whether a image is premul or not? |
| 302 SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaTyp
e; |
| 303 |
| 304 if (SkImageCacherator* cacher = as_IB(this)->peekCacherator()) { |
| 305 GrImageTextureMaker maker(context, cacher, this, kDisallow_CachingHint); |
| 306 return create_image_from_maker(&maker, at, this->uniqueID()); |
| 307 } |
| 308 SkBitmap bmp; |
| 309 if (!this->asLegacyBitmap(&bmp, kRO_LegacyBitmapMode)) { |
| 310 return nullptr; |
| 311 } |
| 312 GrBitmapTextureMaker maker(context, bmp); |
| 313 return create_image_from_maker(&maker, at, this->uniqueID()); |
| 314 } |
| 315 |
| 285 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 316 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 286 | 317 |
| 287 GrTexture* GrDeepCopyTexture(GrTexture* src, bool budgeted) { | 318 GrTexture* GrDeepCopyTexture(GrTexture* src, bool budgeted) { |
| 288 GrContext* ctx = src->getContext(); | 319 GrContext* ctx = src->getContext(); |
| 289 | 320 |
| 290 GrSurfaceDesc desc = src->desc(); | 321 GrSurfaceDesc desc = src->desc(); |
| 291 GrTexture* dst = ctx->textureProvider()->createTexture(desc, budgeted, nullp
tr, 0); | 322 GrTexture* dst = ctx->textureProvider()->createTexture(desc, budgeted, nullp
tr, 0); |
| 292 if (!dst) { | 323 if (!dst) { |
| 293 return nullptr; | 324 return nullptr; |
| 294 } | 325 } |
| 295 | 326 |
| 296 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); | 327 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); |
| 297 const SkIPoint dstP = SkIPoint::Make(0, 0); | 328 const SkIPoint dstP = SkIPoint::Make(0, 0); |
| 298 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp); | 329 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp); |
| 299 return dst; | 330 return dst; |
| 300 } | 331 } |
| 301 | 332 |
| OLD | NEW |