Remove overly complicated GR_CREATE_STATIC_PROCESSOR macro

This macro was responsible for producing code like:

    static SkAlignedStorage<sizeof(Foo)> g_gFoo_Storage;
    static Foo* gFoo = new(g_gFoo_Storage.get()) Foo;
    static SkAutoTDestroy<Foo> gFoo_ad(gFoo);

which would allocate static storage for an object of type Foo
(g_gFoo_Storage), lazily instantiate the object in that memory (via
gFoo's initializer), and then ensure that at global destruction time
the object is destroyed (via gFoo_Ad's destructor).

However, the exact same effect is achieved by just writing:

    static Foo gFoo;

Review URL: https://codereview.chromium.org/1314763009
This commit is contained in:
mdempsky 2015-08-27 12:57:01 -07:00 committed by Commit bot
parent 6904d1d3f1
commit 38f1f6f9e5
4 changed files with 7 additions and 17 deletions

View File

@ -52,8 +52,7 @@ private:
immutable: after being constructed, their fields may not change. immutable: after being constructed, their fields may not change.
Dynamically allocated GrProcessors are managed by a per-thread memory pool. The ref count of an Dynamically allocated GrProcessors are managed by a per-thread memory pool. The ref count of an
processor must reach 0 before the thread terminates and the pool is destroyed. To create a processor must reach 0 before the thread terminates and the pool is destroyed.
static processor use the helper macro GR_CREATE_STATIC_PROCESSOR declared below.
*/ */
class GrProcessor : public GrProgramElement { class GrProcessor : public GrProgramElement {
public: public:
@ -143,13 +142,4 @@ private:
typedef GrProgramElement INHERITED; typedef GrProgramElement INHERITED;
}; };
/**
* This creates a processor outside of the memory pool. The processor's destructor will be called
* at global destruction time. NAME will be the name of the created instance.
*/
#define GR_CREATE_STATIC_PROCESSOR(NAME, PROC_CLASS, ARGS) \
static SkAlignedSStorage<sizeof(PROC_CLASS)> g_##NAME##_Storage; \
static PROC_CLASS* NAME SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), PROC_CLASS, ARGS); \
static SkAutoTDestroy<GrProcessor> NAME##_ad(NAME);
#endif #endif

View File

@ -55,8 +55,8 @@ void SkLumaColorFilter::toString(SkString* str) const {
class LumaColorFilterEffect : public GrFragmentProcessor { class LumaColorFilterEffect : public GrFragmentProcessor {
public: public:
static GrFragmentProcessor* Create() { static GrFragmentProcessor* Create() {
GR_CREATE_STATIC_PROCESSOR(gLumaEffect, LumaColorFilterEffect, ()); static LumaColorFilterEffect gLumaEffect;
return SkRef(gLumaEffect); return SkRef(&gLumaEffect);
} }
const char* name() const override { return "Luminance-to-Alpha"; } const char* name() const override { return "Luminance-to-Alpha"; }

View File

@ -17,8 +17,8 @@
class DitherEffect : public GrFragmentProcessor { class DitherEffect : public GrFragmentProcessor {
public: public:
static GrFragmentProcessor* Create() { static GrFragmentProcessor* Create() {
GR_CREATE_STATIC_PROCESSOR(gDitherEffect, DitherEffect, ()) static DitherEffect gDitherEffect;
return SkRef(gDitherEffect); return SkRef(&gDitherEffect);
} }
virtual ~DitherEffect() {}; virtual ~DitherEffect() {};

View File

@ -62,8 +62,8 @@ private:
class BigKeyProcessor : public GrFragmentProcessor { class BigKeyProcessor : public GrFragmentProcessor {
public: public:
static GrFragmentProcessor* Create() { static GrFragmentProcessor* Create() {
GR_CREATE_STATIC_PROCESSOR(gBigKeyProcessor, BigKeyProcessor, ()) static BigKeyProcessor gBigKeyProcessor;
return SkRef(gBigKeyProcessor); return SkRef(&gBigKeyProcessor);
} }
const char* name() const override { return "Big Ole Key"; } const char* name() const override { return "Big Ole Key"; }