aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorDerek Sollenberger <djsollen@google.com>2012-05-16 10:40:31 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-05-16 10:40:31 -0700
commit41b64c065a09cf5957f2929e471d04fc7ca9656f (patch)
tree6dbe3a801fe20deb01746fee4253059f354420cc /include
parent7249c95ffc05fb8775e6ecb567c9450680eb1b65 (diff)
parentf1a1e8d5528d123890c9e86f672084b86c69dcfe (diff)
downloadexternal_skia-41b64c065a09cf5957f2929e471d04fc7ca9656f.zip
external_skia-41b64c065a09cf5957f2929e471d04fc7ca9656f.tar.gz
external_skia-41b64c065a09cf5957f2929e471d04fc7ca9656f.tar.bz2
Merge "Cleanup pixel ref mutexes in Skia" into jb-dev
Diffstat (limited to 'include')
-rw-r--r--include/core/SkPixelRef.h23
-rw-r--r--include/core/SkThread_platform.h7
2 files changed, 25 insertions, 5 deletions
diff --git a/include/core/SkPixelRef.h b/include/core/SkPixelRef.h
index d5f6ab2..f01ba15 100644
--- a/include/core/SkPixelRef.h
+++ b/include/core/SkPixelRef.h
@@ -63,9 +63,10 @@ public:
*/
SkColorTable* colorTable() const { return fColorTable; }
- /** Return the current lockcount (defaults to 0)
- */
- int getLockCount() const { return fLockCount; }
+ /**
+ * Returns true if the lockcount > 0
+ */
+ bool isLocked() const { return fLockCount > 0; }
/** Call to access the pixel memory, which is returned. Balance with a call
to unlockPixels().
@@ -205,6 +206,18 @@ protected:
SkPixelRef(SkFlattenableReadBuffer&, SkBaseMutex*);
+ // only call from constructor. Flags this to always be locked, removing
+ // the need to grab the mutex and call onLockPixels/onUnlockPixels.
+ // Performance tweak to avoid those calls (esp. in multi-thread use case).
+ void setPreLocked(void* pixels, SkColorTable* ctable);
+
+ // only call from constructor. Specify a (possibly) different mutex, or
+ // null to use the default. Use with caution.
+ // The default logic is to provide a mutex, but possibly one that is
+ // shared with other instances, though this sharing is implementation
+ // specific, and it is legal for each instance to have its own mutex.
+ void useDefaultMutex() { this->setMutex(NULL); }
+
private:
#if !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
static void InitializeFlattenables();
@@ -221,6 +234,10 @@ private:
// can go from false to true, but never from true to false
bool fIsImmutable;
+ // only ever set in constructor, const after that
+ bool fPreLocked;
+
+ void setMutex(SkBaseMutex* mutex);
friend class SkGraphics;
};
diff --git a/include/core/SkThread_platform.h b/include/core/SkThread_platform.h
index 863f6e3..58311e1 100644
--- a/include/core/SkThread_platform.h
+++ b/include/core/SkThread_platform.h
@@ -75,6 +75,8 @@ struct SkBaseMutex {
// Special case used when the static mutex must be available globally.
#define SK_DECLARE_GLOBAL_MUTEX(name) SkBaseMutex name = { PTHREAD_MUTEX_INITIALIZER }
+#define SK_DECLARE_MUTEX_ARRAY(name, count) SkBaseMutex name[count] = { PTHREAD_MUTEX_INITIALIZER }
+
// A normal mutex that requires to be initialized through normal C++ construction,
// i.e. when it's a member of another class, or allocated on the heap.
class SkMutex : public SkBaseMutex, SkNoncopyable {
@@ -106,8 +108,9 @@ private:
typedef SkMutex SkBaseMutex;
-#define SK_DECLARE_STATIC_MUTEX(name) static SkBaseMutex name
-#define SK_DECLARE_GLOBAL_MUTEX(name) SkBaseMutex name
+#define SK_DECLARE_STATIC_MUTEX(name) static SkBaseMutex name
+#define SK_DECLARE_GLOBAL_MUTEX(name) SkBaseMutex name
+#define SK_DECLARE_MUTEX_ARRAY(name, count) SkBaseMutex name[count]
#endif // !SK_USE_POSIX_THREADS