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

Unified Diff: src/core/SkImageCacherator.h

Issue 1313423002: make cacherator thread-safe (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 4 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 | « no previous file | src/core/SkImageCacherator.cpp » ('j') | src/core/SkImageCacherator.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkImageCacherator.h
diff --git a/src/core/SkImageCacherator.h b/src/core/SkImageCacherator.h
index f05147e5710be6f45da800d3c12248e6854d1fc2..c9aa121d2629ecf297de30744d3ef65cb4078dad 100644
--- a/src/core/SkImageCacherator.h
+++ b/src/core/SkImageCacherator.h
@@ -9,6 +9,8 @@
#define SkImageCacherator_DEFINED
#include "SkImageGenerator.h"
+#include "SkMutex.h"
+#include "SkTemplates.h"
class GrContext;
class SkBitmap;
@@ -21,8 +23,6 @@ public:
// Takes ownership of the generator
static SkImageCacherator* NewFromGenerator(SkImageGenerator*, const SkIRect* subset = nullptr);
- ~SkImageCacherator();
-
const SkImageInfo& info() const { return fInfo; }
uint32_t uniqueID() const { return fUniqueID; }
@@ -40,13 +40,34 @@ public:
*/
GrTexture* lockAsTexture(GrContext*, SkImageUsageType);
+ /**
+ * If the underlying src naturally is represented by an encoded blob (in SkData), this returns
+ * a ref to that data. If not, it returns null.
+ */
+ SkData* refEncoded();
+
private:
SkImageCacherator(SkImageGenerator*, const SkImageInfo&, const SkIPoint&, uint32_t uniqueID);
+ bool generateBitmap(SkBitmap*);
bool tryLockAsBitmap(SkBitmap*);
- GrTexture* tryLockAsTexture(GrContext*, SkImageUsageType);
- SkImageGenerator* fGenerator;
+ class ScopedGenerator {
+ SkImageCacherator* fCacher;
+ public:
+ ScopedGenerator(SkImageCacherator* cacher) : fCacher(cacher) {
+ fCacher->fMutexForGenerator.acquire();
+ }
+ ~ScopedGenerator() {
+ fCacher->fMutexForGenerator.release();
+ }
+ SkImageGenerator* operator->() const { return fCacher->fNotThreadSafeGenerator; }
+ operator SkImageGenerator*() const { return fCacher->fNotThreadSafeGenerator; }
+ };
+
+ SkMutex fMutexForGenerator;
+ SkAutoTDelete<SkImageGenerator> fNotThreadSafeGenerator;
+
const SkImageInfo fInfo;
const SkIPoint fOrigin;
const uint32_t fUniqueID;
« no previous file with comments | « no previous file | src/core/SkImageCacherator.cpp » ('j') | src/core/SkImageCacherator.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698