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

Unified Diff: src/core/SkImageCacherator.cpp

Issue 1409923003: Revert of Rewrite GrTextureMaker to disentangle bitmap case from base class and give GPU object a say in what… (Closed) Base URL: https://skia.googlesource.com/skia.git@move
Patch Set: Created 5 years, 2 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/core/SkImageCacherator.h ('k') | src/gpu/GrGpu.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkImageCacherator.cpp
diff --git a/src/core/SkImageCacherator.cpp b/src/core/SkImageCacherator.cpp
index f59be324119ef1fea3b07f4ea9decd684baa3b1d..cd5ae57699b2ea52e186b88f4063e37496113bb4 100644
--- a/src/core/SkImageCacherator.cpp
+++ b/src/core/SkImageCacherator.cpp
@@ -204,9 +204,7 @@
};
static GrTexture* set_key_and_return(GrTexture* tex, const GrUniqueKey& key) {
- if (key.isValid()) {
- tex->resourcePriv().setUniqueKey(key);
- }
+ tex->resourcePriv().setUniqueKey(key);
return tex;
}
@@ -219,16 +217,24 @@
* 4. Ask the generator to return YUV planes, which the GPU can convert
* 5. Ask the generator to return RGB(A) data, which the GPU can convert
*/
-GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& key,
- const SkImage* client) {
+GrTexture* SkImageCacherator::lockUnstretchedTexture(GrContext* ctx, const SkImage* client) {
+ // textures (at least the texture-key) only support 16bit dimensions, so abort early
+ // if we're too big.
+ if (fInfo.width() > 0xFFFF || fInfo.height() > 0xFFFF) {
+ return nullptr;
+ }
+
+ GrUniqueKey key;
+ const GrTextureParams& noStretchParams = GrTextureParams::ClampNoFilter();
+ GrMakeKeyFromImageID(&key, fUniqueID, SkIRect::MakeWH(fInfo.width(), fInfo.height()),
+ *ctx->caps(), noStretchParams);
+
// 1. Check the cache for a pre-existing one
- if (key.isValid()) {
- if (GrTexture* tex = ctx->textureProvider()->findAndRefTextureByUniqueKey(key)) {
- return tex;
- }
- }
-
- // 2. Ask the generator to natively create one
+ if (GrTexture* tex = ctx->textureProvider()->findAndRefTextureByUniqueKey(key)) {
+ return tex;
+ }
+
+ // 2. Ask the genreator to natively create one
{
ScopedGenerator generator(this);
SkIRect subset = SkIRect::MakeXYWH(fOrigin.x(), fOrigin.y(), fInfo.width(), fInfo.height());
@@ -261,62 +267,54 @@
// 5. Ask the generator to return RGB(A) data, which the GPU can convert
SkBitmap bitmap;
if (this->tryLockAsBitmap(&bitmap, client)) {
- GrTexture* tex = GrUploadBitmapToTexture(ctx, bitmap);
- if (tex) {
- return set_key_and_return(tex, key);
- }
+ return GrRefCachedBitmapTexture(ctx, bitmap, noStretchParams);
}
return nullptr;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
-#include "GrTextureParamsAdjuster.h"
-
-class Cacherator_GrTextureParamsAdjuster : public GrTextureParamsAdjuster {
+#include "GrTextureMaker.h"
+
+class Cacherator_GrTextureMaker : public GrTextureMaker {
public:
- Cacherator_GrTextureParamsAdjuster(SkImageCacherator* cacher, const SkImage* client)
+ Cacherator_GrTextureMaker(SkImageCacherator* cacher, const SkImage* client,
+ const GrUniqueKey& unstretchedKey)
: INHERITED(cacher->info().width(), cacher->info().height())
, fCacher(cacher)
, fClient(client)
- {
- if (client) {
- GrMakeKeyFromImageID(&fOriginalKey, client->uniqueID(),
- SkIRect::MakeWH(this->width(), this->height()));
- }
- }
+ , fUnstretchedKey(unstretchedKey)
+ {}
protected:
// TODO: consider overriding this, for the case where the underlying generator might be
// able to efficiently produce a "stretched" texture natively (e.g. picture-backed)
- // GrTexture* generateTextureForParams(GrContext*, const SkGrStretch&) override;
-
- GrTexture* refOriginalTexture(GrContext* ctx) override {
- return fCacher->lockTexture(ctx, fOriginalKey, fClient);
- }
-
- void makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey) override {
- if (fOriginalKey.isValid()) {
- MakeCopyKeyFromOrigKey(fOriginalKey, stretch, paramsCopyKey);
- }
- }
-
- void didCacheCopy(const GrUniqueKey& copyKey) override {
+// GrTexture* onGenerateStretchedTexture(GrContext*, const SkGrStretch&) override;
+
+ GrTexture* onRefUnstretchedTexture(GrContext* ctx) override {
+ return fCacher->lockUnstretchedTexture(ctx, fClient);
+ }
+
+ bool onMakeStretchedKey(const SkGrStretch& stretch, GrUniqueKey* stretchedKey) override {
+ return GrMakeStretchedKey(fUnstretchedKey, stretch, stretchedKey);
+ }
+
+ void onNotifyStretchCached(const GrUniqueKey& stretchedKey) override {
if (fClient) {
as_IB(fClient)->notifyAddedToCache();
}
}
- bool getROBitmap(SkBitmap* bitmap) override {
+ bool onGetROBitmap(SkBitmap* bitmap) override {
return fCacher->lockAsBitmap(bitmap, fClient);
}
private:
SkImageCacherator* fCacher;
const SkImage* fClient;
- GrUniqueKey fOriginalKey;
-
- typedef GrTextureParamsAdjuster INHERITED;
+ const GrUniqueKey fUnstretchedKey;
+
+ typedef GrTextureMaker INHERITED;
};
GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, const GrTextureParams& params,
@@ -325,7 +323,12 @@
return nullptr;
}
- return Cacherator_GrTextureParamsAdjuster(this, client).refTextureForParams(ctx, params);
+ GrUniqueKey key;
+ GrMakeKeyFromImageID(&key, this->uniqueID(),
+ SkIRect::MakeWH(this->info().width(), this->info().height()),
+ *ctx->caps(), GrTextureParams::ClampNoFilter());
+
+ return Cacherator_GrTextureMaker(this, client, key).refCachedTexture(ctx, params);
}
#else
« no previous file with comments | « src/core/SkImageCacherator.h ('k') | src/gpu/GrGpu.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698