Remove some unnecessary uses of SkOnce.

- gm/imagefiltersgraph.cpp can just use a global registrar
  - SkScaledImageCache always accesses its global under a lock

BUG=skia:
R=bungeman@google.com, mtklein@google.com

Author: mtklein@chromium.org

Review URL: https://codereview.chromium.org/297273006

git-svn-id: http://skia.googlecode.com/svn/trunk@14897 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
commit-bot@chromium.org 2014-05-27 16:28:43 +00:00
parent 64f6d15451
commit 60c8d24f84
2 changed files with 18 additions and 26 deletions

View File

@ -18,7 +18,6 @@
#include "SkWriteBuffer.h"
#include "SkMergeImageFilter.h"
#include "SkMorphologyImageFilter.h"
#include "SkOnce.h"
#include "SkTestImageFilters.h"
#include "SkXfermodeImageFilter.h"
@ -77,17 +76,13 @@ private:
SkScalar fDX, fDY;
};
static void init_flattenable(int*) {
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SimpleOffsetFilter)
}
SkFlattenable::Registrar registrar("SimpleOffsetFilter",
SimpleOffsetFilter::CreateProc,
SimpleOffsetFilter::GetFlattenableType());
class ImageFiltersGraphGM : public skiagm::GM {
public:
ImageFiltersGraphGM() : fInitialized(false) {
int dummy;
SK_DECLARE_STATIC_ONCE(once);
SkOnce(&once, init_flattenable, &dummy);
}
ImageFiltersGraphGM() {}
protected:
virtual uint32_t onGetFlags() const SK_OVERRIDE {
@ -120,11 +115,11 @@ protected:
virtual SkISize onISize() { return SkISize::Make(500, 150); }
virtual void onOnceBeforeDraw() {
this->make_bitmap();
}
virtual void onDraw(SkCanvas* canvas) {
if (!fInitialized) {
this->make_bitmap();
fInitialized = true;
}
canvas->clear(0x00000000);
{
SkAutoTUnref<SkImageFilter> bitmapSource(SkBitmapSource::Create(fBitmap));
@ -215,7 +210,6 @@ protected:
private:
typedef GM INHERITED;
SkBitmap fBitmap;
bool fInitialized;
};
///////////////////////////////////////////////////////////////////////////////

View File

@ -7,7 +7,6 @@
#include "SkScaledImageCache.h"
#include "SkMipMap.h"
#include "SkOnce.h"
#include "SkPixelRef.h"
#include "SkRect.h"
@ -673,18 +672,17 @@ SK_DECLARE_STATIC_MUTEX(gMutex);
static SkScaledImageCache* gScaledImageCache = NULL;
static void cleanup_gScaledImageCache() { SkDELETE(gScaledImageCache); }
static void create_cache(int) {
#ifdef SK_USE_DISCARDABLE_SCALEDIMAGECACHE
gScaledImageCache = SkNEW_ARGS(SkScaledImageCache, (SkDiscardableMemory::Create));
#else
gScaledImageCache = SkNEW_ARGS(SkScaledImageCache, (SK_DEFAULT_IMAGE_CACHE_LIMIT));
#endif
}
/** Must hold gMutex when calling. */
static SkScaledImageCache* get_cache() {
SK_DECLARE_STATIC_ONCE(once);
SkOnce(&once, create_cache, 0, cleanup_gScaledImageCache);
SkASSERT(NULL != gScaledImageCache);
// gMutex is always held when this is called, so we don't need to be fancy in here.
if (NULL == gScaledImageCache) {
#ifdef SK_USE_DISCARDABLE_SCALEDIMAGECACHE
gScaledImageCache = SkNEW_ARGS(SkScaledImageCache, (SkDiscardableMemory::Create));
#else
gScaledImageCache = SkNEW_ARGS(SkScaledImageCache, (SK_DEFAULT_IMAGE_CACHE_LIMIT));
#endif
atexit(cleanup_gScaledImageCache);
}
return gScaledImageCache;
}