1771cbf43d
This patch removes static initializers related to static and global mutexes from the final library's machine code when building on a pthread-capable system. We use PTHREAD_MUTEX_INITIALIZER to perform POD-style initialization. You need a line like the following to declare a global mutex with it: SkBaseMutex gMutex = { PTHREAD_MUTEX_INITIALIZER }; We introduce the SK_DECLARE_STATIC_MUTEX and SK_DECLARE_GLOBAL_MUTEX macros to be able to declare static/global mutexes in the source tree uniformly. SkMutex is now defined as a sub-class of SkBaseMutex, with standard construction/destruction semantics. This is useful if the mutex object is a member of another C++ class, or allocated dynamically. We also modify a few places to refer to SkBaseMutex instead of a SkMutex, where it makes sense. Generally speaking, client code should hold and use pointers to SkBaseMutex whenever they can now. We defined a new built-time macro named SK_USE_POSIX_THREADS to indicate that we're using a pthread-based SkThread.h interface. The macro will also be used in future patches to implement other helper thread synchronization classes. Finally, we inline the acquire() and release() functions in the case of Posix to improve performance a bit. Running: 'bench -repeat 10 -match mutex' on an Android device or a 2.4GHz Xeon Linux desktop shows the following improvements: Before After Galaxy Nexus 1.64 1.45 Nexus S 1.47 1.16 Xoom 1.86 1.66 Xeon 0.36 0.31 This removes 5 static mutex initializers from the library Review URL: https://codereview.appspot.com/5501066 git-svn-id: http://skia.googlecode.com/svn/trunk@3091 2bbb7eff-a529-9590-31e7-b0007b416f81
66 lines
1.9 KiB
C++
66 lines
1.9 KiB
C++
|
|
/*
|
|
* Copyright 2011 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
|
|
#ifndef SkPDFShader_DEFINED
|
|
#define SkPDFShader_DEFINED
|
|
|
|
#include "SkPDFStream.h"
|
|
#include "SkPDFTypes.h"
|
|
#include "SkMatrix.h"
|
|
#include "SkRefCnt.h"
|
|
#include "SkShader.h"
|
|
|
|
class SkObjRef;
|
|
class SkPDFCatalog;
|
|
|
|
/** \class SkPDFShader
|
|
|
|
In PDF parlance, this is a pattern, used in place of a color when the
|
|
pattern color space is selected.
|
|
*/
|
|
|
|
class SkPDFShader {
|
|
public:
|
|
/** Get the PDF shader for the passed SkShader. If the SkShader is
|
|
* invalid in some way, returns NULL. The reference count of
|
|
* the object is incremented and it is the caller's responsibility to
|
|
* unreference it when done. This is needed to accommodate the weak
|
|
* reference pattern used when the returned object is new and has no
|
|
* other references.
|
|
* @param shader The SkShader to emulate.
|
|
* @param matrix The current transform. (PDF shaders are absolutely
|
|
* positioned, relative to where the page is drawn.)
|
|
* @param surfceBBox The bounding box of the drawing surface (with matrix
|
|
* already applied).
|
|
*/
|
|
static SkPDFObject* GetPDFShader(const SkShader& shader,
|
|
const SkMatrix& matrix,
|
|
const SkIRect& surfaceBBox);
|
|
|
|
protected:
|
|
class State;
|
|
|
|
class ShaderCanonicalEntry {
|
|
public:
|
|
ShaderCanonicalEntry(SkPDFObject* pdfShader, const State* state);
|
|
bool operator==(const ShaderCanonicalEntry& b) const;
|
|
|
|
SkPDFObject* fPDFShader;
|
|
const State* fState;
|
|
};
|
|
// This should be made a hash table if performance is a problem.
|
|
static SkTDArray<ShaderCanonicalEntry>& CanonicalShaders();
|
|
static SkBaseMutex& CanonicalShadersMutex();
|
|
static void RemoveShader(SkPDFObject* shader);
|
|
|
|
SkPDFShader();
|
|
};
|
|
|
|
#endif
|