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