Home | History | Annotate | Download | only in gpu
      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 "GrProcessor.h"
      9 #include "GrBackendProcessorFactory.h"
     10 #include "GrContext.h"
     11 #include "GrCoordTransform.h"
     12 #include "GrMemoryPool.h"
     13 #include "SkTLS.h"
     14 
     15 namespace GrProcessorUnitTest {
     16 const SkMatrix& TestMatrix(SkRandom* random) {
     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));
     27         gMatrices[4].set(SkMatrix::kMPersp0, 0.00013f);
     28         gMatrices[4].set(SkMatrix::kMPersp1, -0.000039f);
     29         gOnce = true;
     30     }
     31     return gMatrices[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gMatrices)))];
     32 }
     33 }
     34 
     35 class GrProcessor_Globals {
     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 
     51 int32_t GrBackendProcessorFactory::fCurrEffectClassID =
     52         GrBackendProcessorFactory::kIllegalEffectClassID;
     53 
     54 ///////////////////////////////////////////////////////////////////////////////
     55 
     56 GrProcessor::~GrProcessor() {}
     57 
     58 const char* GrProcessor::name() const {
     59     return this->getFactory().name();
     60 }
     61 
     62 void GrProcessor::addCoordTransform(const GrCoordTransform* transform) {
     63     fCoordTransforms.push_back(transform);
     64     SkDEBUGCODE(transform->setInEffect();)
     65 }
     66 
     67 void GrProcessor::addTextureAccess(const GrTextureAccess* access) {
     68     fTextureAccesses.push_back(access);
     69     this->addGpuResource(access->getProgramTexture());
     70 }
     71 
     72 void* GrProcessor::operator new(size_t size) {
     73     return GrProcessor_Globals::GetTLS()->allocate(size);
     74 }
     75 
     76 void GrProcessor::operator delete(void* target) {
     77     GrProcessor_Globals::GetTLS()->release(target);
     78 }
     79 
     80 #ifdef SK_DEBUG
     81 void GrProcessor::assertEquality(const GrProcessor& other) const {
     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
     92