DEF_TEST(SkOnce_MiscFeatures, r) { // Tests that we support functors and explicit SkOnceFlags. int x = 0; SkOnceFlag once = SK_ONCE_INIT; SkOnce(&once, AddFour(), &x); SkOnce(&once, AddFour(), &x); SkOnce(&once, AddFour(), &x); REPORTER_ASSERT(r, 4 == x); }
DEF_TEST(SkOnce_Singlethreaded, r) { int x = 0; // No matter how many times we do this, x will be 5. SkOnce(&st_once, add_five, &x); SkOnce(&st_once, add_five, &x); SkOnce(&st_once, add_five, &x); SkOnce(&st_once, add_five, &x); SkOnce(&st_once, add_five, &x); REPORTER_ASSERT(r, 5 == x); }
DEF_TEST(SkOnce_Singlethreaded, r) { int x = 0; SK_DECLARE_STATIC_ONCE(once); // No matter how many times we do this, x will be 5. SkOnce(&once, add_five, &x); SkOnce(&once, add_five, &x); SkOnce(&once, add_five, &x); SkOnce(&once, add_five, &x); SkOnce(&once, add_five, &x); REPORTER_ASSERT(r, 5 == x); }
void SkFontMgr_Indirect::onGetFamilyName(int index, SkString* familyName) const { SkOnce(&fFamilyNamesInited, &fFamilyNamesMutex, SkFontMgr_Indirect::set_up_family_names, this); if (index >= fFamilyNames->count()) { familyName->reset(); return; } familyName->set(fFamilyNames->atStr(index)); }
DEF_TEST(SkOnce_Multithreaded, r) { int x = 0; // Run a bunch of tasks to be the first to add six to x. SkTaskGroup().batch(1021, [&](int) { void(*add_six)(int*) = [](int* p) { *p += 6; }; SkOnce(&mt_once, add_six, &x); }); // Only one should have done the +=. REPORTER_ASSERT(r, 6 == x); }
void SkColorCubeFilter::ColorCubeProcesingCache::getProcessingLuts( const int* (*colorToIndex)[2], const SkScalar* (*colorToFactors)[2], const SkScalar** colorToScalar) { SkOnce(&fLutsInited, &fLutsMutex, SkColorCubeFilter::ColorCubeProcesingCache::initProcessingLuts, this); SkASSERT((fColorToIndex[0] != NULL) && (fColorToIndex[1] != NULL) && (fColorToFactors[0] != NULL) && (fColorToFactors[1] != NULL) && (fColorToScalar != NULL)); (*colorToIndex)[0] = fColorToIndex[0]; (*colorToIndex)[1] = fColorToIndex[1]; (*colorToFactors)[0] = fColorToFactors[0]; (*colorToFactors)[1] = fColorToFactors[1]; (*colorToScalar) = fColorToScalar; }
SkEventTracer* SkEventTracer::GetInstance() { SK_DECLARE_STATIC_ONCE(once); SkOnce(&once, intialize_default_tracer, SkEventTracer::gInstance); SkASSERT(NULL != SkEventTracer::gInstance); return SkEventTracer::gInstance; }
void SkFlattenable::InitializeFlattenablesIfNeeded() { SK_DECLARE_STATIC_ONCE(once); SkOnce(&once, SkPrivateEffectInitializer::Init); }
void LoadCommandBufferOnce() { SkOnce(&loadCommandBufferOnce, load_command_buffer_functions); }
void SkFlattenable::InitializeFlattenablesIfNeeded() { int dummy; SK_DECLARE_STATIC_ONCE(once); SkOnce(&once, InitializeFlattenables, &dummy); }
void SkFlattenable::InitializeFlattenablesIfNeeded() { SkOnce(&once, SkPrivateEffectInitializer::Init); }
int sk_num_cores() { static int num_cores = 0; SkOnce(&g_query_num_cores_once, query_num_cores, &num_cores); SkASSERT(num_cores > 0); return num_cores; }
DEF_TEST(SkOnce_NoArg, r) { SkOnce(&noarg_once, inc_gX); SkOnce(&noarg_once, inc_gX); SkOnce(&noarg_once, inc_gX); REPORTER_ASSERT(r, 1 == gX); }
void SkFlattenable::InitializeFlattenablesIfNeeded() { SkOnce(&once, SkFlattenable::PrivateInitializer::InitCore); }
void Init() { SkOnce(&gInitOnce, init); }
int SkFontMgr_Indirect::onCountFamilies() const { SkOnce(&fFamilyNamesInited, &fFamilyNamesMutex, SkFontMgr_Indirect::set_up_family_names, this); return fFamilyNames->count(); }