blob: 7997fb05e03ad77566d9555cde5089c64d24fca4 [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
tomhudson@google.comdcba4c22012-07-24 21:36:16 +000022class GrCustomStage_Globals {
23public:
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.comae4f96a2012-05-18 19:54:48 +000038int32_t GrProgramStageFactory::fCurrStageClassID =
39 GrProgramStageFactory::kIllegalStageClassID;
tomhudson@google.com168e6342012-04-18 17:49:20 +000040
bsalomon@google.coma469c282012-10-24 18:28:34 +000041GrEffect::GrEffect(int numTextures)
bsalomon@google.come6e62d12012-10-04 14:38:48 +000042 : fNumTextures(numTextures) {
tomhudson@google.com168e6342012-04-18 17:49:20 +000043}
44
bsalomon@google.coma469c282012-10-24 18:28:34 +000045GrEffect::~GrEffect() {
tomhudson@google.com168e6342012-04-18 17:49:20 +000046
47}
48
bsalomon@google.coma469c282012-10-24 18:28:34 +000049bool GrEffect::isOpaque(bool inputTextureIsOpaque) const {
tomhudson@google.com168e6342012-04-18 17:49:20 +000050 return false;
51}
52
bsalomon@google.coma469c282012-10-24 18:28:34 +000053bool GrEffect::isEqual(const GrEffect& s) const {
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000054 if (this->numTextures() != s.numTextures()) {
55 return false;
56 }
bsalomon@google.com6d003d12012-09-11 15:45:20 +000057 for (int i = 0; i < this->numTextures(); ++i) {
bsalomon@google.com1ce49fc2012-09-18 14:14:49 +000058 if (this->textureAccess(i) != s.textureAccess(i)) {
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000059 return false;
60 }
61 }
62 return true;
63}
64
bsalomon@google.coma469c282012-10-24 18:28:34 +000065const GrTextureAccess& GrEffect::textureAccess(int index) const {
bsalomon@google.com6d003d12012-09-11 15:45:20 +000066 GrCrash("We shouldn't be calling this function on the base class.");
67 static GrTextureAccess kDummy;
68 return kDummy;
twiz@google.coma5e65ec2012-08-02 15:15:16 +000069}
70
bsalomon@google.coma469c282012-10-24 18:28:34 +000071void * GrEffect::operator new(size_t size) {
tomhudson@google.comdcba4c22012-07-24 21:36:16 +000072 return GrCustomStage_Globals::GetTLS()->allocate(size);
73}
74
bsalomon@google.coma469c282012-10-24 18:28:34 +000075void GrEffect::operator delete(void* target) {
tomhudson@google.comdcba4c22012-07-24 21:36:16 +000076 GrCustomStage_Globals::GetTLS()->release(target);
77}