| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrEffect.h" | 8 #include "GrProcessor.h" |
| 9 #include "GrBackendEffectFactory.h" | 9 #include "GrBackendProcessorFactory.h" |
| 10 #include "GrContext.h" | 10 #include "GrContext.h" |
| 11 #include "GrCoordTransform.h" | 11 #include "GrCoordTransform.h" |
| 12 #include "GrMemoryPool.h" | 12 #include "GrMemoryPool.h" |
| 13 #include "SkTLS.h" | 13 #include "SkTLS.h" |
| 14 | 14 |
| 15 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS | 15 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
| 16 SkTArray<GrEffectTestFactory*, true>* GrEffectTestFactory::GetFactories() { | 16 template <> |
| 17 static SkTArray<GrEffectTestFactory*, true> gFactories; | 17 SkTArray<GrProcessorTestFactory<GrGeometryProcessor>*, true>* |
| 18 GrProcessorTestFactory<GrGeometryProcessor>::GetFactories() { |
| 19 static SkTArray<GrProcessorTestFactory<GrGeometryProcessor>*, true> gFactori
es; |
| 20 return &gFactories; |
| 21 } |
| 22 |
| 23 template <> |
| 24 SkTArray<GrProcessorTestFactory<GrFragmentProcessor>*, true>* |
| 25 GrProcessorTestFactory<GrFragmentProcessor>::GetFactories() { |
| 26 static SkTArray<GrProcessorTestFactory<GrFragmentProcessor>*, true> gFactori
es; |
| 18 return &gFactories; | 27 return &gFactories; |
| 19 } | 28 } |
| 20 #endif | 29 #endif |
| 21 | 30 |
| 22 namespace GrEffectUnitTest { | 31 namespace GrProcessorUnitTest { |
| 23 const SkMatrix& TestMatrix(SkRandom* random) { | 32 const SkMatrix& TestMatrix(SkRandom* random) { |
| 24 static SkMatrix gMatrices[5]; | 33 static SkMatrix gMatrices[5]; |
| 25 static bool gOnce; | 34 static bool gOnce; |
| 26 if (!gOnce) { | 35 if (!gOnce) { |
| 27 gMatrices[0].reset(); | 36 gMatrices[0].reset(); |
| 28 gMatrices[1].setTranslate(SkIntToScalar(-100), SkIntToScalar(100)); | 37 gMatrices[1].setTranslate(SkIntToScalar(-100), SkIntToScalar(100)); |
| 29 gMatrices[2].setRotate(SkIntToScalar(17)); | 38 gMatrices[2].setRotate(SkIntToScalar(17)); |
| 30 gMatrices[3].setRotate(SkIntToScalar(185)); | 39 gMatrices[3].setRotate(SkIntToScalar(185)); |
| 31 gMatrices[3].postTranslate(SkIntToScalar(66), SkIntToScalar(-33)); | 40 gMatrices[3].postTranslate(SkIntToScalar(66), SkIntToScalar(-33)); |
| 32 gMatrices[3].postScale(SkIntToScalar(2), SK_ScalarHalf); | 41 gMatrices[3].postScale(SkIntToScalar(2), SK_ScalarHalf); |
| 33 gMatrices[4].setRotate(SkIntToScalar(215)); | 42 gMatrices[4].setRotate(SkIntToScalar(215)); |
| 34 gMatrices[4].set(SkMatrix::kMPersp0, 0.00013f); | 43 gMatrices[4].set(SkMatrix::kMPersp0, 0.00013f); |
| 35 gMatrices[4].set(SkMatrix::kMPersp1, -0.000039f); | 44 gMatrices[4].set(SkMatrix::kMPersp1, -0.000039f); |
| 36 gOnce = true; | 45 gOnce = true; |
| 37 } | 46 } |
| 38 return gMatrices[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(
gMatrices)))]; | 47 return gMatrices[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(
gMatrices)))]; |
| 39 } | 48 } |
| 40 } | 49 } |
| 41 | 50 |
| 42 class GrEffect_Globals { | 51 class GrProcessor_Globals { |
| 43 public: | 52 public: |
| 44 static GrMemoryPool* GetTLS() { | 53 static GrMemoryPool* GetTLS() { |
| 45 return (GrMemoryPool*)SkTLS::Get(CreateTLS, DeleteTLS); | 54 return (GrMemoryPool*)SkTLS::Get(CreateTLS, DeleteTLS); |
| 46 } | 55 } |
| 47 | 56 |
| 48 private: | 57 private: |
| 49 static void* CreateTLS() { | 58 static void* CreateTLS() { |
| 50 return SkNEW_ARGS(GrMemoryPool, (4096, 4096)); | 59 return SkNEW_ARGS(GrMemoryPool, (4096, 4096)); |
| 51 } | 60 } |
| 52 | 61 |
| 53 static void DeleteTLS(void* pool) { | 62 static void DeleteTLS(void* pool) { |
| 54 SkDELETE(reinterpret_cast<GrMemoryPool*>(pool)); | 63 SkDELETE(reinterpret_cast<GrMemoryPool*>(pool)); |
| 55 } | 64 } |
| 56 }; | 65 }; |
| 57 | 66 |
| 58 int32_t GrBackendEffectFactory::fCurrEffectClassID = GrBackendEffectFactory::kIl
legalEffectClassID; | 67 int32_t GrBackendProcessorFactory::fCurrEffectClassID = |
| 68 GrBackendProcessorFactory::kIllegalEffectClassID; |
| 59 | 69 |
| 60 /////////////////////////////////////////////////////////////////////////////// | 70 /////////////////////////////////////////////////////////////////////////////// |
| 61 | 71 |
| 62 GrEffect::~GrEffect() {} | 72 GrProcessor::~GrProcessor() {} |
| 63 | 73 |
| 64 const char* GrEffect::name() const { | 74 const char* GrProcessor::name() const { |
| 65 return this->getFactory().name(); | 75 return this->getFactory().name(); |
| 66 } | 76 } |
| 67 | 77 |
| 68 void GrEffect::addCoordTransform(const GrCoordTransform* transform) { | 78 void GrProcessor::addCoordTransform(const GrCoordTransform* transform) { |
| 69 fCoordTransforms.push_back(transform); | 79 fCoordTransforms.push_back(transform); |
| 70 SkDEBUGCODE(transform->setInEffect();) | 80 SkDEBUGCODE(transform->setInEffect();) |
| 71 } | 81 } |
| 72 | 82 |
| 73 void GrEffect::addTextureAccess(const GrTextureAccess* access) { | 83 void GrProcessor::addTextureAccess(const GrTextureAccess* access) { |
| 74 fTextureAccesses.push_back(access); | 84 fTextureAccesses.push_back(access); |
| 75 this->addGpuResource(access->getProgramTexture()); | 85 this->addGpuResource(access->getProgramTexture()); |
| 76 } | 86 } |
| 77 | 87 |
| 78 void* GrEffect::operator new(size_t size) { | 88 void* GrProcessor::operator new(size_t size) { |
| 79 return GrEffect_Globals::GetTLS()->allocate(size); | 89 return GrProcessor_Globals::GetTLS()->allocate(size); |
| 80 } | 90 } |
| 81 | 91 |
| 82 void GrEffect::operator delete(void* target) { | 92 void GrProcessor::operator delete(void* target) { |
| 83 GrEffect_Globals::GetTLS()->release(target); | 93 GrProcessor_Globals::GetTLS()->release(target); |
| 84 } | 94 } |
| 85 | 95 |
| 86 #ifdef SK_DEBUG | 96 #ifdef SK_DEBUG |
| 87 void GrEffect::assertEquality(const GrEffect& other) const { | 97 void GrProcessor::assertEquality(const GrProcessor& other) const { |
| 88 SkASSERT(this->numTransforms() == other.numTransforms()); | 98 SkASSERT(this->numTransforms() == other.numTransforms()); |
| 89 for (int i = 0; i < this->numTransforms(); ++i) { | 99 for (int i = 0; i < this->numTransforms(); ++i) { |
| 90 SkASSERT(this->coordTransform(i) == other.coordTransform(i)); | 100 SkASSERT(this->coordTransform(i) == other.coordTransform(i)); |
| 91 } | 101 } |
| 92 SkASSERT(this->numTextures() == other.numTextures()); | 102 SkASSERT(this->numTextures() == other.numTextures()); |
| 93 for (int i = 0; i < this->numTextures(); ++i) { | 103 for (int i = 0; i < this->numTextures(); ++i) { |
| 94 SkASSERT(this->textureAccess(i) == other.textureAccess(i)); | 104 SkASSERT(this->textureAccess(i) == other.textureAccess(i)); |
| 95 } | 105 } |
| 96 } | 106 } |
| 97 #endif | 107 #endif |
| OLD | NEW |