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 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame^] | 8 | #include "GrProcessor.h" |
| 9 | #include "GrBackendProcessorFactory.h" |
bsalomon@google.com | 2eaaefd | 2012-10-29 19:51:22 +0000 | [diff] [blame] | 10 | #include "GrContext.h" |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 11 | #include "GrCoordTransform.h" |
tomhudson@google.com | dcba4c2 | 2012-07-24 21:36:16 +0000 | [diff] [blame] | 12 | #include "GrMemoryPool.h" |
| 13 | #include "SkTLS.h" |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 14 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame^] | 15 | namespace GrProcessorUnitTest { |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 16 | const SkMatrix& TestMatrix(SkRandom* random) { |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 17 | static SkMatrix gMatrices[5]; |
| 18 | static bool gOnce; |
| 19 | if (!gOnce) { |
| 20 | gMatrices[0].reset(); |
| 21 | gMatrices[1].setTranslate(SkIntToScalar(-100), SkIntToScalar(100)); |
| 22 | gMatrices[2].setRotate(SkIntToScalar(17)); |
| 23 | gMatrices[3].setRotate(SkIntToScalar(185)); |
| 24 | gMatrices[3].postTranslate(SkIntToScalar(66), SkIntToScalar(-33)); |
| 25 | gMatrices[3].postScale(SkIntToScalar(2), SK_ScalarHalf); |
| 26 | gMatrices[4].setRotate(SkIntToScalar(215)); |
commit-bot@chromium.org | 4b413c8 | 2013-11-25 19:44:07 +0000 | [diff] [blame] | 27 | gMatrices[4].set(SkMatrix::kMPersp0, 0.00013f); |
| 28 | gMatrices[4].set(SkMatrix::kMPersp1, -0.000039f); |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 29 | gOnce = true; |
| 30 | } |
| 31 | return gMatrices[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gMatrices)))]; |
| 32 | } |
| 33 | } |
| 34 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame^] | 35 | class GrProcessor_Globals { |
tomhudson@google.com | dcba4c2 | 2012-07-24 21:36:16 +0000 | [diff] [blame] | 36 | public: |
| 37 | static GrMemoryPool* GetTLS() { |
| 38 | return (GrMemoryPool*)SkTLS::Get(CreateTLS, DeleteTLS); |
| 39 | } |
| 40 | |
| 41 | private: |
| 42 | static void* CreateTLS() { |
| 43 | return SkNEW_ARGS(GrMemoryPool, (4096, 4096)); |
| 44 | } |
| 45 | |
| 46 | static void DeleteTLS(void* pool) { |
| 47 | SkDELETE(reinterpret_cast<GrMemoryPool*>(pool)); |
| 48 | } |
| 49 | }; |
| 50 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame^] | 51 | int32_t GrBackendProcessorFactory::fCurrEffectClassID = |
| 52 | GrBackendProcessorFactory::kIllegalEffectClassID; |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 53 | |
bsalomon@google.com | 0ac6af4 | 2013-01-16 15:16:18 +0000 | [diff] [blame] | 54 | /////////////////////////////////////////////////////////////////////////////// |
| 55 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame^] | 56 | GrProcessor::~GrProcessor() {} |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 57 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame^] | 58 | const char* GrProcessor::name() const { |
bsalomon@google.com | 2eaaefd | 2012-10-29 19:51:22 +0000 | [diff] [blame] | 59 | return this->getFactory().name(); |
| 60 | } |
| 61 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame^] | 62 | void GrProcessor::addCoordTransform(const GrCoordTransform* transform) { |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 63 | fCoordTransforms.push_back(transform); |
commit-bot@chromium.org | 5fd7d5c | 2013-10-04 01:20:09 +0000 | [diff] [blame] | 64 | SkDEBUGCODE(transform->setInEffect();) |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 65 | } |
| 66 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame^] | 67 | void GrProcessor::addTextureAccess(const GrTextureAccess* access) { |
bsalomon@google.com | 50db75c | 2013-01-11 13:54:30 +0000 | [diff] [blame] | 68 | fTextureAccesses.push_back(access); |
bsalomon | f96ba02 | 2014-09-17 08:05:40 -0700 | [diff] [blame] | 69 | this->addGpuResource(access->getProgramTexture()); |
twiz@google.com | a5e65ec | 2012-08-02 15:15:16 +0000 | [diff] [blame] | 70 | } |
| 71 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame^] | 72 | void* GrProcessor::operator new(size_t size) { |
| 73 | return GrProcessor_Globals::GetTLS()->allocate(size); |
tomhudson@google.com | dcba4c2 | 2012-07-24 21:36:16 +0000 | [diff] [blame] | 74 | } |
| 75 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame^] | 76 | void GrProcessor::operator delete(void* target) { |
| 77 | GrProcessor_Globals::GetTLS()->release(target); |
tomhudson@google.com | dcba4c2 | 2012-07-24 21:36:16 +0000 | [diff] [blame] | 78 | } |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 79 | |
| 80 | #ifdef SK_DEBUG |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame^] | 81 | void GrProcessor::assertEquality(const GrProcessor& other) const { |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 82 | SkASSERT(this->numTransforms() == other.numTransforms()); |
| 83 | for (int i = 0; i < this->numTransforms(); ++i) { |
| 84 | SkASSERT(this->coordTransform(i) == other.coordTransform(i)); |
| 85 | } |
| 86 | SkASSERT(this->numTextures() == other.numTextures()); |
| 87 | for (int i = 0; i < this->numTextures(); ++i) { |
| 88 | SkASSERT(this->textureAccess(i) == other.textureAccess(i)); |
| 89 | } |
| 90 | } |
| 91 | #endif |