blob: 396f5d1058027b5673c31c584813ba0ab38868ca [file] [log] [blame]
tomhudson@google.com168e6342012-04-18 17:49:20 +00001/*
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 "GrContext.h"
bsalomon@google.coma469c282012-10-24 18:28:34 +00009#include "GrEffect.h"
tomhudson@google.comdcba4c22012-07-24 21:36:16 +000010#include "GrMemoryPool.h"
11#include "SkTLS.h"
tomhudson@google.com168e6342012-04-18 17:49:20 +000012
bsalomon@google.coma469c282012-10-24 18:28:34 +000013SK_DEFINE_INST_COUNT(GrEffect)
robertphillips@google.com15e9d3e2012-06-21 20:25:03 +000014
bsalomon@google.comd4726202012-08-03 14:34:46 +000015#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
bsalomon@google.coma469c282012-10-24 18:28:34 +000016SkTArray<GrEffectTestFactory*, true>* GrEffectTestFactory::GetFactories() {
17 static SkTArray<GrEffectTestFactory*, true> gFactories;
bsalomon@google.comd4726202012-08-03 14:34:46 +000018 return &gFactories;
19}
20#endif
21
bsalomon@google.com8ea78d82012-10-24 20:11:30 +000022class GrEffect_Globals {
tomhudson@google.comdcba4c22012-07-24 21:36:16 +000023public:
24 static GrMemoryPool* GetTLS() {
25 return (GrMemoryPool*)SkTLS::Get(CreateTLS, DeleteTLS);
26 }
27
28private:
29 static void* CreateTLS() {
30 return SkNEW_ARGS(GrMemoryPool, (4096, 4096));
31 }
32
33 static void DeleteTLS(void* pool) {
34 SkDELETE(reinterpret_cast<GrMemoryPool*>(pool));
35 }
36};
37
bsalomon@google.com021fc732012-10-25 12:47:42 +000038int32_t GrProgramStageFactory::fCurrEffectClassID = GrProgramStageFactory::kIllegalEffectClassID;
tomhudson@google.com168e6342012-04-18 17:49:20 +000039
bsalomon@google.coma469c282012-10-24 18:28:34 +000040GrEffect::GrEffect(int numTextures)
bsalomon@google.come6e62d12012-10-04 14:38:48 +000041 : fNumTextures(numTextures) {
tomhudson@google.com168e6342012-04-18 17:49:20 +000042}
43
bsalomon@google.coma469c282012-10-24 18:28:34 +000044GrEffect::~GrEffect() {
tomhudson@google.com168e6342012-04-18 17:49:20 +000045
46}
47
bsalomon@google.coma469c282012-10-24 18:28:34 +000048bool GrEffect::isOpaque(bool inputTextureIsOpaque) const {
tomhudson@google.com168e6342012-04-18 17:49:20 +000049 return false;
50}
51
bsalomon@google.coma469c282012-10-24 18:28:34 +000052bool GrEffect::isEqual(const GrEffect& s) const {
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000053 if (this->numTextures() != s.numTextures()) {
54 return false;
55 }
bsalomon@google.com6d003d12012-09-11 15:45:20 +000056 for (int i = 0; i < this->numTextures(); ++i) {
bsalomon@google.com1ce49fc2012-09-18 14:14:49 +000057 if (this->textureAccess(i) != s.textureAccess(i)) {
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000058 return false;
59 }
60 }
61 return true;
62}
63
bsalomon@google.coma469c282012-10-24 18:28:34 +000064const GrTextureAccess& GrEffect::textureAccess(int index) const {
bsalomon@google.com6d003d12012-09-11 15:45:20 +000065 GrCrash("We shouldn't be calling this function on the base class.");
66 static GrTextureAccess kDummy;
67 return kDummy;
twiz@google.coma5e65ec2012-08-02 15:15:16 +000068}
69
bsalomon@google.coma469c282012-10-24 18:28:34 +000070void * GrEffect::operator new(size_t size) {
bsalomon@google.com8ea78d82012-10-24 20:11:30 +000071 return GrEffect_Globals::GetTLS()->allocate(size);
tomhudson@google.comdcba4c22012-07-24 21:36:16 +000072}
73
bsalomon@google.coma469c282012-10-24 18:28:34 +000074void GrEffect::operator delete(void* target) {
bsalomon@google.com8ea78d82012-10-24 20:11:30 +000075 GrEffect_Globals::GetTLS()->release(target);
tomhudson@google.comdcba4c22012-07-24 21:36:16 +000076}