aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/image/SkImage_Gpu.cpp
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2015-09-30 12:21:45 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-09-30 12:21:45 -0700
commit856e9d921462136da8562f8f122d42e114cd4710 (patch)
tree9ebc00a92f5aacdd54d00c528fa3ed19f48f6fd6 /src/image/SkImage_Gpu.cpp
parent8a6697af95b340aad6dee7e6228048fa305c1e59 (diff)
Revert[4] of add ImageShader, sharing code with its Bitmap cousin
Now with GrTextureMaker subclasses to handle npot usage. This reverts commit 476506d070dbc59b158acc1a00c34bff95ab2968. BUG=skia: Review URL: https://codereview.chromium.org/1370223002
Diffstat (limited to 'src/image/SkImage_Gpu.cpp')
-rw-r--r--src/image/SkImage_Gpu.cpp61
1 files changed, 52 insertions, 9 deletions
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index 1a63a0d6ba..2cc0241a48 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -7,11 +7,14 @@
#include "SkBitmapCache.h"
#include "SkImage_Gpu.h"
+#include "GrCaps.h"
#include "GrContext.h"
#include "GrDrawContext.h"
+#include "GrTextureMaker.h"
#include "effects/GrYUVtoRGBEffect.h"
#include "SkCanvas.h"
#include "SkGpuDevice.h"
+#include "SkGrPriv.h"
#include "SkPixelRef.h"
SkImage_Gpu::SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType at, GrTexture* tex,
@@ -35,13 +38,6 @@ extern void SkTextureImageApplyBudgetedDecision(SkImage* image) {
}
}
-SkShader* SkImage_Gpu::onNewShader(SkShader::TileMode tileX, SkShader::TileMode tileY,
- const SkMatrix* localMatrix) const {
- SkBitmap bm;
- GrWrapTextureInBitmap(fTexture, this->width(), this->height(), this->isOpaque(), &bm);
- return SkShader::CreateBitmapShader(bm, tileX, tileY, localMatrix);
-}
-
bool SkImage_Gpu::getROPixels(SkBitmap* dst) const {
if (SkBitmapCache::Find(this->uniqueID(), dst)) {
SkASSERT(dst->getGenerationID() == this->uniqueID());
@@ -65,9 +61,56 @@ bool SkImage_Gpu::getROPixels(SkBitmap* dst) const {
return true;
}
+static void make_raw_texture_stretched_key(uint32_t imageID, const SkGrStretch& stretch,
+ GrUniqueKey* stretchedKey) {
+ SkASSERT(SkGrStretch::kNone_Type != stretch.fType);
+
+ uint32_t width = SkToU16(stretch.fWidth);
+ uint32_t height = SkToU16(stretch.fHeight);
+
+ static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
+ GrUniqueKey::Builder builder(stretchedKey, kDomain, 3);
+ builder[0] = imageID;
+ builder[1] = stretch.fType;
+ builder[2] = width | (height << 16);
+ builder.finish();
+}
+
+class Texture_GrTextureMaker : public GrTextureMaker {
+public:
+ Texture_GrTextureMaker(const SkImage* image, GrTexture* unstretched)
+ : INHERITED(image->width(), image->height())
+ , fImage(image)
+ , fUnstretched(unstretched)
+ {}
+
+protected:
+ GrTexture* onRefUnstretchedTexture(GrContext* ctx) override {
+ return SkRef(fUnstretched);
+ }
+
+ bool onMakeStretchedKey(const SkGrStretch& stretch, GrUniqueKey* stretchedKey) override {
+ make_raw_texture_stretched_key(fImage->uniqueID(), stretch, stretchedKey);
+ return stretchedKey->isValid();
+ }
+
+ void onNotifyStretchCached(const GrUniqueKey& stretchedKey) override {
+ as_IB(fImage)->notifyAddedToCache();
+ }
+
+ bool onGetROBitmap(SkBitmap* bitmap) override {
+ return as_IB(fImage)->getROPixels(bitmap);
+ }
+
+private:
+ const SkImage* fImage;
+ GrTexture* fUnstretched;
+
+ typedef GrTextureMaker INHERITED;
+};
+
GrTexture* SkImage_Gpu::asTextureRef(GrContext* ctx, SkImageUsageType usage) const {
- fTexture->ref();
- return fTexture;
+ return Texture_GrTextureMaker(this, fTexture).refCachedTexture(ctx, usage);
}
bool SkImage_Gpu::isOpaque() const {