// return a read-only copy of the pixels. We promise to not modify them,
// but only inspect them (or encode them).
- virtual bool getROPixels(SkBitmap*) const { return false; }
+ virtual bool getROPixels(SkBitmap*) const = 0;
+
+ // Caller must call unref when they are done.
+ virtual GrTexture* asTextureRef(GrContext*, SkImageUsageType) const = 0;
virtual SkShader* onNewShader(SkShader::TileMode,
SkShader::TileMode,
virtual bool onIsLazyGenerated() const { return false; }
- // Caller must call unref when they are done.
- virtual GrTexture* asTextureRef(GrContext*, SkImageUsageType) const { return nullptr; }
-
private:
const SkSurfaceProps fProps;
#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,
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,
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,