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

Unified Diff: src/image/SkImage_Raster.cpp

Issue 1348023004: have raster-image return itself as a texture (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: remove unneeded includes Created 5 years, 3 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_Base.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/image/SkImage_Raster.cpp
diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp
index 042107e3e3fcb5ad51eb13d17c84e78e85d61cce..67498f0e112cf4a5e2f001258906fc6c323316a1 100644
--- a/src/image/SkImage_Raster.cpp
+++ b/src/image/SkImage_Raster.cpp
@@ -10,11 +10,16 @@
#include "SkCanvas.h"
#include "SkColorTable.h"
#include "SkData.h"
-#include "SkImageGeneratorPriv.h"
#include "SkImagePriv.h"
#include "SkPixelRef.h"
#include "SkSurface.h"
+#if SK_SUPPORT_GPU
+#include "GrContext.h"
+#include "SkGr.h"
+#include "SkGrPriv.h"
+#endif
+
class SkImage_Raster : public SkImage_Base {
public:
static bool ValidArgs(const Info& info, size_t rowBytes, SkColorTable* ctable,
@@ -67,6 +72,7 @@ public:
const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const override;
SkData* onRefEncoded() const override;
bool getROPixels(SkBitmap*) const override;
+ GrTexture* asTextureRef(GrContext*, SkImageUsageType) const override;
// exposed for SkSurface_Raster via SkNewImageFromPixelRef
SkImage_Raster(const SkImageInfo&, SkPixelRef*, const SkIPoint& pixelRefOrigin, size_t rowBytes,
@@ -180,6 +186,32 @@ bool SkImage_Raster::getROPixels(SkBitmap* dst) const {
return true;
}
+GrTexture* SkImage_Raster::asTextureRef(GrContext* ctx, SkImageUsageType usage) const {
+#if SK_SUPPORT_GPU
+ if (!ctx) {
+ return nullptr;
+ }
+
+ // textures (at least the texture-key) only support 16bit dimensions, so abort early
+ // if we're too big.
+ if (fBitmap.width() > 0xFFFF || fBitmap.height() > 0xFFFF) {
+ return nullptr;
+ }
+
+ GrUniqueKey key;
+ GrMakeKeyFromImageID(&key, fBitmap.getGenerationID(),
+ SkIRect::MakeWH(fBitmap.width(), fBitmap.height()),
+ *ctx->caps(), usage);
+
+ if (GrTexture* tex = ctx->textureProvider()->findAndRefTextureByUniqueKey(key)) {
+ return tex;
+ }
+ return GrRefCachedBitmapTexture(ctx, fBitmap, usage);
+#endif
+
+ return nullptr;
+}
+
///////////////////////////////////////////////////////////////////////////////
SkImage* SkImage::NewRasterCopy(const SkImageInfo& info, const void* pixels, size_t rowBytes,
« no previous file with comments | « src/image/SkImage_Base.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698