2 * Copyright 2012 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
9 #include "GrBackendEffectFactory.h"
10 #include "GrContext.h"
11 #include "GrCoordTransform.h"
12 #include "GrMemoryPool.h"
15 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
16 SkTArray<GrEffectTestFactory*, true>* GrEffectTestFactory::GetFactories() {
17 static SkTArray<GrEffectTestFactory*, true> gFactories;
22 namespace GrEffectUnitTest {
23 const SkMatrix& TestMatrix(SkRandom* random) {
24 static SkMatrix gMatrices[5];
28 gMatrices[1].setTranslate(SkIntToScalar(-100), SkIntToScalar(100));
29 gMatrices[2].setRotate(SkIntToScalar(17));
30 gMatrices[3].setRotate(SkIntToScalar(185));
31 gMatrices[3].postTranslate(SkIntToScalar(66), SkIntToScalar(-33));
32 gMatrices[3].postScale(SkIntToScalar(2), SK_ScalarHalf);
33 gMatrices[4].setRotate(SkIntToScalar(215));
34 gMatrices[4].set(SkMatrix::kMPersp0, 0.00013f);
35 gMatrices[4].set(SkMatrix::kMPersp1, -0.000039f);
38 return gMatrices[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gMatrices)))];
42 class GrEffect_Globals {
44 static GrMemoryPool* GetTLS() {
45 return (GrMemoryPool*)SkTLS::Get(CreateTLS, DeleteTLS);
49 static void* CreateTLS() {
50 return SkNEW_ARGS(GrMemoryPool, (4096, 4096));
53 static void DeleteTLS(void* pool) {
54 SkDELETE(reinterpret_cast<GrMemoryPool*>(pool));
58 int32_t GrBackendEffectFactory::fCurrEffectClassID = GrBackendEffectFactory::kIllegalEffectClassID;
60 ///////////////////////////////////////////////////////////////////////////////
62 GrEffect::~GrEffect() {}
64 const char* GrEffect::name() const {
65 return this->getFactory().name();
68 void GrEffect::addCoordTransform(const GrCoordTransform* transform) {
69 fCoordTransforms.push_back(transform);
70 SkDEBUGCODE(transform->setInEffect();)
73 void GrEffect::addTextureAccess(const GrTextureAccess* access) {
74 fTextureAccesses.push_back(access);
77 void* GrEffect::operator new(size_t size) {
78 return GrEffect_Globals::GetTLS()->allocate(size);
81 void GrEffect::operator delete(void* target) {
82 GrEffect_Globals::GetTLS()->release(target);
86 void GrEffect::assertEquality(const GrEffect& other) const {
87 SkASSERT(this->numTransforms() == other.numTransforms());
88 for (int i = 0; i < this->numTransforms(); ++i) {
89 SkASSERT(this->coordTransform(i) == other.coordTransform(i));
91 SkASSERT(this->numTextures() == other.numTextures());
92 for (int i = 0; i < this->numTextures(); ++i) {
93 SkASSERT(this->textureAccess(i) == other.textureAccess(i));