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

Unified Diff: src/image/SkImage_Gpu.cpp

Issue 1631053003: Add SkImage factory method that forces image to be resolved to a texture. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: static->class method Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/image/SkImage.cpp ('k') | tests/ImageTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/image/SkImage_Gpu.cpp
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index a758efed5c884e55d8d96bcab46a88264b3964d4..1956958b3c740c3efa64ee17814933120cf0c162 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -282,6 +282,37 @@ SkImage* SkImage::NewFromYUVTexturesCopy(GrContext* ctx , SkYUVColorSpace colorS
kOpaque_SkAlphaType, dst, budgeted);
}
+static SkImage* create_image_from_maker(GrTextureMaker* maker, SkAlphaType at, uint32_t id) {
+ SkAutoTUnref<GrTexture> texture(maker->refTextureForParams(GrTextureParams::ClampNoFilter()));
+ if (!texture) {
+ return nullptr;
+ }
+ return new SkImage_Gpu(texture->width(), texture->height(), id, at, texture,
+ SkSurface::kNo_Budgeted);
+}
+
+SkImage* SkImage::newTextureImage(GrContext *context) const {
+ if (!context) {
+ return nullptr;
+ }
+ if (GrTexture* peek = as_IB(this)->peekTexture()) {
+ return peek->getContext() == context ? SkRef(const_cast<SkImage*>(this)) : nullptr;
+ }
+ // No way to check whether a image is premul or not?
+ SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaType;
+
+ if (SkImageCacherator* cacher = as_IB(this)->peekCacherator()) {
+ GrImageTextureMaker maker(context, cacher, this, kDisallow_CachingHint);
+ return create_image_from_maker(&maker, at, this->uniqueID());
+ }
+ SkBitmap bmp;
+ if (!this->asLegacyBitmap(&bmp, kRO_LegacyBitmapMode)) {
+ return nullptr;
+ }
+ GrBitmapTextureMaker maker(context, bmp);
+ return create_image_from_maker(&maker, at, this->uniqueID());
+}
+
///////////////////////////////////////////////////////////////////////////////////////////////////
GrTexture* GrDeepCopyTexture(GrTexture* src, bool budgeted) {
« no previous file with comments | « src/image/SkImage.cpp ('k') | tests/ImageTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698