tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 1 | /* |
| 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.com | a469c28 | 2012-10-24 18:28:34 +0000 | [diff] [blame] | 8 | #include "GrEffect.h" |
bsalomon@google.com | 2eaaefd | 2012-10-29 19:51:22 +0000 | [diff] [blame^] | 9 | #include "GrBackendEffectFactory.h" |
| 10 | #include "GrContext.h" |
tomhudson@google.com | dcba4c2 | 2012-07-24 21:36:16 +0000 | [diff] [blame] | 11 | #include "GrMemoryPool.h" |
| 12 | #include "SkTLS.h" |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 13 | |
bsalomon@google.com | a469c28 | 2012-10-24 18:28:34 +0000 | [diff] [blame] | 14 | SK_DEFINE_INST_COUNT(GrEffect) |
robertphillips@google.com | 15e9d3e | 2012-06-21 20:25:03 +0000 | [diff] [blame] | 15 | |
bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 16 | #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
bsalomon@google.com | a469c28 | 2012-10-24 18:28:34 +0000 | [diff] [blame] | 17 | SkTArray<GrEffectTestFactory*, true>* GrEffectTestFactory::GetFactories() { |
| 18 | static SkTArray<GrEffectTestFactory*, true> gFactories; |
bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 19 | return &gFactories; |
| 20 | } |
| 21 | #endif |
| 22 | |
bsalomon@google.com | 8ea78d8 | 2012-10-24 20:11:30 +0000 | [diff] [blame] | 23 | class GrEffect_Globals { |
tomhudson@google.com | dcba4c2 | 2012-07-24 21:36:16 +0000 | [diff] [blame] | 24 | public: |
| 25 | static GrMemoryPool* GetTLS() { |
| 26 | return (GrMemoryPool*)SkTLS::Get(CreateTLS, DeleteTLS); |
| 27 | } |
| 28 | |
| 29 | private: |
| 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.com | 396e61f | 2012-10-25 19:00:29 +0000 | [diff] [blame] | 39 | int32_t GrBackendEffectFactory::fCurrEffectClassID = GrBackendEffectFactory::kIllegalEffectClassID; |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 40 | |
bsalomon@google.com | a469c28 | 2012-10-24 18:28:34 +0000 | [diff] [blame] | 41 | GrEffect::GrEffect(int numTextures) |
bsalomon@google.com | e6e62d1 | 2012-10-04 14:38:48 +0000 | [diff] [blame] | 42 | : fNumTextures(numTextures) { |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 43 | } |
| 44 | |
bsalomon@google.com | a469c28 | 2012-10-24 18:28:34 +0000 | [diff] [blame] | 45 | GrEffect::~GrEffect() { |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 46 | |
| 47 | } |
| 48 | |
bsalomon@google.com | a469c28 | 2012-10-24 18:28:34 +0000 | [diff] [blame] | 49 | bool GrEffect::isOpaque(bool inputTextureIsOpaque) const { |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 50 | return false; |
| 51 | } |
| 52 | |
bsalomon@google.com | 2eaaefd | 2012-10-29 19:51:22 +0000 | [diff] [blame^] | 53 | const char* GrEffect::name() const { |
| 54 | return this->getFactory().name(); |
| 55 | } |
| 56 | |
| 57 | |
bsalomon@google.com | a469c28 | 2012-10-24 18:28:34 +0000 | [diff] [blame] | 58 | bool GrEffect::isEqual(const GrEffect& s) const { |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 59 | if (this->numTextures() != s.numTextures()) { |
| 60 | return false; |
| 61 | } |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame] | 62 | for (int i = 0; i < this->numTextures(); ++i) { |
bsalomon@google.com | 1ce49fc | 2012-09-18 14:14:49 +0000 | [diff] [blame] | 63 | if (this->textureAccess(i) != s.textureAccess(i)) { |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 64 | return false; |
| 65 | } |
| 66 | } |
| 67 | return true; |
| 68 | } |
| 69 | |
bsalomon@google.com | a469c28 | 2012-10-24 18:28:34 +0000 | [diff] [blame] | 70 | const GrTextureAccess& GrEffect::textureAccess(int index) const { |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame] | 71 | GrCrash("We shouldn't be calling this function on the base class."); |
| 72 | static GrTextureAccess kDummy; |
| 73 | return kDummy; |
twiz@google.com | a5e65ec | 2012-08-02 15:15:16 +0000 | [diff] [blame] | 74 | } |
| 75 | |
bsalomon@google.com | a469c28 | 2012-10-24 18:28:34 +0000 | [diff] [blame] | 76 | void * GrEffect::operator new(size_t size) { |
bsalomon@google.com | 8ea78d8 | 2012-10-24 20:11:30 +0000 | [diff] [blame] | 77 | return GrEffect_Globals::GetTLS()->allocate(size); |
tomhudson@google.com | dcba4c2 | 2012-07-24 21:36:16 +0000 | [diff] [blame] | 78 | } |
| 79 | |
bsalomon@google.com | a469c28 | 2012-10-24 18:28:34 +0000 | [diff] [blame] | 80 | void GrEffect::operator delete(void* target) { |
bsalomon@google.com | 8ea78d8 | 2012-10-24 20:11:30 +0000 | [diff] [blame] | 81 | GrEffect_Globals::GetTLS()->release(target); |
tomhudson@google.com | dcba4c2 | 2012-07-24 21:36:16 +0000 | [diff] [blame] | 82 | } |