• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2012 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "GrEffect.h"
9 #include "GrBackendEffectFactory.h"
10 #include "GrContext.h"
11 #include "GrMemoryPool.h"
12 #include "SkTLS.h"
13 
SK_DEFINE_INST_COUNT(GrEffect)14 SK_DEFINE_INST_COUNT(GrEffect)
15 
16 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
17 SkTArray<GrEffectTestFactory*, true>* GrEffectTestFactory::GetFactories() {
18     static SkTArray<GrEffectTestFactory*, true> gFactories;
19     return &gFactories;
20 }
21 #endif
22 
23 namespace GrEffectUnitTest {
TestMatrix(SkRandom * random)24 const SkMatrix& TestMatrix(SkRandom* random) {
25     static SkMatrix gMatrices[5];
26     static bool gOnce;
27     if (!gOnce) {
28         gMatrices[0].reset();
29         gMatrices[1].setTranslate(SkIntToScalar(-100), SkIntToScalar(100));
30         gMatrices[2].setRotate(SkIntToScalar(17));
31         gMatrices[3].setRotate(SkIntToScalar(185));
32         gMatrices[3].postTranslate(SkIntToScalar(66), SkIntToScalar(-33));
33         gMatrices[3].postScale(SkIntToScalar(2), SK_ScalarHalf);
34         gMatrices[4].setRotate(SkIntToScalar(215));
35         gMatrices[4].set(SkMatrix::kMPersp0, SkFloatToScalar(0.00013f));
36         gMatrices[4].set(SkMatrix::kMPersp1, SkFloatToScalar(-0.000039f));
37         gOnce = true;
38     }
39     return gMatrices[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gMatrices)))];
40 }
41 }
42 
43 class GrEffect_Globals {
44 public:
GetTLS()45     static GrMemoryPool* GetTLS() {
46         return (GrMemoryPool*)SkTLS::Get(CreateTLS, DeleteTLS);
47     }
48 
49 private:
CreateTLS()50     static void* CreateTLS() {
51         return SkNEW_ARGS(GrMemoryPool, (4096, 4096));
52     }
53 
DeleteTLS(void * pool)54     static void DeleteTLS(void* pool) {
55         SkDELETE(reinterpret_cast<GrMemoryPool*>(pool));
56     }
57 };
58 
59 int32_t GrBackendEffectFactory::fCurrEffectClassID = GrBackendEffectFactory::kIllegalEffectClassID;
60 
61 ///////////////////////////////////////////////////////////////////////////////
62 
SK_DEFINE_INST_COUNT(GrEffectRef)63 SK_DEFINE_INST_COUNT(GrEffectRef)
64 
65 GrEffectRef::~GrEffectRef() {
66     GrAssert(1 == this->getRefCnt());
67     fEffect->EffectRefDestroyed();
68     fEffect->unref();
69 }
70 
operator new(size_t size)71 void* GrEffectRef::operator new(size_t size) {
72     return GrEffect_Globals::GetTLS()->allocate(size);
73 }
74 
operator delete(void * target)75 void GrEffectRef::operator delete(void* target) {
76     GrEffect_Globals::GetTLS()->release(target);
77 }
78 
79 ///////////////////////////////////////////////////////////////////////////////
80 
~GrEffect()81 GrEffect::~GrEffect() {
82     GrAssert(NULL == fEffectRef);
83 }
84 
name() const85 const char* GrEffect::name() const {
86     return this->getFactory().name();
87 }
88 
addTextureAccess(const GrTextureAccess * access)89 void GrEffect::addTextureAccess(const GrTextureAccess* access) {
90     fTextureAccesses.push_back(access);
91 }
92 
operator new(size_t size)93 void* GrEffect::operator new(size_t size) {
94     return GrEffect_Globals::GetTLS()->allocate(size);
95 }
96 
operator delete(void * target)97 void GrEffect::operator delete(void* target) {
98     GrEffect_Globals::GetTLS()->release(target);
99 }
100