blob: 09032bf0f920e77051bc172e36882903544cb1fa [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
bsalomon@google.coma469c282012-10-24 18:28:34 +00008#include "GrEffect.h"
bsalomon@google.com2eaaefd2012-10-29 19:51:22 +00009#include "GrBackendEffectFactory.h"
10#include "GrContext.h"
tomhudson@google.comdcba4c22012-07-24 21:36:16 +000011#include "GrMemoryPool.h"
12#include "SkTLS.h"
tomhudson@google.com168e6342012-04-18 17:49:20 +000013
bsalomon@google.coma469c282012-10-24 18:28:34 +000014SK_DEFINE_INST_COUNT(GrEffect)
robertphillips@google.com15e9d3e2012-06-21 20:25:03 +000015
bsalomon@google.comd4726202012-08-03 14:34:46 +000016#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
bsalomon@google.coma469c282012-10-24 18:28:34 +000017SkTArray<GrEffectTestFactory*, true>* GrEffectTestFactory::GetFactories() {
18 static SkTArray<GrEffectTestFactory*, true> gFactories;
bsalomon@google.comd4726202012-08-03 14:34:46 +000019 return &gFactories;
20}
21#endif
22
bsalomon@google.com8ea78d82012-10-24 20:11:30 +000023class GrEffect_Globals {
tomhudson@google.comdcba4c22012-07-24 21:36:16 +000024public:
25 static GrMemoryPool* GetTLS() {
26 return (GrMemoryPool*)SkTLS::Get(CreateTLS, DeleteTLS);
27 }
28
29private:
30 static void* CreateTLS() {
31 return SkNEW_ARGS(GrMemoryPool, (4096, 4096));
32 }
33
34 static void DeleteTLS(void* pool) {
35 SkDELETE(reinterpret_cast<GrMemoryPool*>(pool));
36 }
37};
38
bsalomon@google.com396e61f2012-10-25 19:00:29 +000039int32_t GrBackendEffectFactory::fCurrEffectClassID = GrBackendEffectFactory::kIllegalEffectClassID;
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.com2eaaefd2012-10-29 19:51:22 +000053const char* GrEffect::name() const {
54 return this->getFactory().name();
55}
56
57
bsalomon@google.coma469c282012-10-24 18:28:34 +000058bool GrEffect::isEqual(const GrEffect& s) const {
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000059 if (this->numTextures() != s.numTextures()) {
60 return false;
61 }
bsalomon@google.com6d003d12012-09-11 15:45:20 +000062 for (int i = 0; i < this->numTextures(); ++i) {
bsalomon@google.com1ce49fc2012-09-18 14:14:49 +000063 if (this->textureAccess(i) != s.textureAccess(i)) {
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000064 return false;
65 }
66 }
67 return true;
68}
69
bsalomon@google.coma469c282012-10-24 18:28:34 +000070const GrTextureAccess& GrEffect::textureAccess(int index) const {
bsalomon@google.com6d003d12012-09-11 15:45:20 +000071 GrCrash("We shouldn't be calling this function on the base class.");
72 static GrTextureAccess kDummy;
73 return kDummy;
twiz@google.coma5e65ec2012-08-02 15:15:16 +000074}
75
bsalomon@google.coma469c282012-10-24 18:28:34 +000076void * GrEffect::operator new(size_t size) {
bsalomon@google.com8ea78d82012-10-24 20:11:30 +000077 return GrEffect_Globals::GetTLS()->allocate(size);
tomhudson@google.comdcba4c22012-07-24 21:36:16 +000078}
79
bsalomon@google.coma469c282012-10-24 18:28:34 +000080void GrEffect::operator delete(void* target) {
bsalomon@google.com8ea78d82012-10-24 20:11:30 +000081 GrEffect_Globals::GetTLS()->release(target);
tomhudson@google.comdcba4c22012-07-24 21:36:16 +000082}