gfx/skia/trunk/src/gpu/GrEffect.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/gpu/GrEffect.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,114 @@
     1.4 +/*
     1.5 + * Copyright 2012 Google Inc.
     1.6 + *
     1.7 + * Use of this source code is governed by a BSD-style license that can be
     1.8 + * found in the LICENSE file.
     1.9 + */
    1.10 +
    1.11 +#include "GrEffect.h"
    1.12 +#include "GrBackendEffectFactory.h"
    1.13 +#include "GrContext.h"
    1.14 +#include "GrCoordTransform.h"
    1.15 +#include "GrMemoryPool.h"
    1.16 +#include "SkTLS.h"
    1.17 +
    1.18 +#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
    1.19 +SkTArray<GrEffectTestFactory*, true>* GrEffectTestFactory::GetFactories() {
    1.20 +    static SkTArray<GrEffectTestFactory*, true> gFactories;
    1.21 +    return &gFactories;
    1.22 +}
    1.23 +#endif
    1.24 +
    1.25 +namespace GrEffectUnitTest {
    1.26 +const SkMatrix& TestMatrix(SkRandom* random) {
    1.27 +    static SkMatrix gMatrices[5];
    1.28 +    static bool gOnce;
    1.29 +    if (!gOnce) {
    1.30 +        gMatrices[0].reset();
    1.31 +        gMatrices[1].setTranslate(SkIntToScalar(-100), SkIntToScalar(100));
    1.32 +        gMatrices[2].setRotate(SkIntToScalar(17));
    1.33 +        gMatrices[3].setRotate(SkIntToScalar(185));
    1.34 +        gMatrices[3].postTranslate(SkIntToScalar(66), SkIntToScalar(-33));
    1.35 +        gMatrices[3].postScale(SkIntToScalar(2), SK_ScalarHalf);
    1.36 +        gMatrices[4].setRotate(SkIntToScalar(215));
    1.37 +        gMatrices[4].set(SkMatrix::kMPersp0, 0.00013f);
    1.38 +        gMatrices[4].set(SkMatrix::kMPersp1, -0.000039f);
    1.39 +        gOnce = true;
    1.40 +    }
    1.41 +    return gMatrices[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gMatrices)))];
    1.42 +}
    1.43 +}
    1.44 +
    1.45 +class GrEffect_Globals {
    1.46 +public:
    1.47 +    static GrMemoryPool* GetTLS() {
    1.48 +        return (GrMemoryPool*)SkTLS::Get(CreateTLS, DeleteTLS);
    1.49 +    }
    1.50 +
    1.51 +private:
    1.52 +    static void* CreateTLS() {
    1.53 +        return SkNEW_ARGS(GrMemoryPool, (4096, 4096));
    1.54 +    }
    1.55 +
    1.56 +    static void DeleteTLS(void* pool) {
    1.57 +        SkDELETE(reinterpret_cast<GrMemoryPool*>(pool));
    1.58 +    }
    1.59 +};
    1.60 +
    1.61 +int32_t GrBackendEffectFactory::fCurrEffectClassID = GrBackendEffectFactory::kIllegalEffectClassID;
    1.62 +
    1.63 +///////////////////////////////////////////////////////////////////////////////
    1.64 +
    1.65 +GrEffectRef::~GrEffectRef() {
    1.66 +    SkASSERT(this->unique());
    1.67 +    fEffect->EffectRefDestroyed();
    1.68 +    fEffect->unref();
    1.69 +}
    1.70 +
    1.71 +void* GrEffectRef::operator new(size_t size) {
    1.72 +    return GrEffect_Globals::GetTLS()->allocate(size);
    1.73 +}
    1.74 +
    1.75 +void GrEffectRef::operator delete(void* target) {
    1.76 +    GrEffect_Globals::GetTLS()->release(target);
    1.77 +}
    1.78 +
    1.79 +///////////////////////////////////////////////////////////////////////////////
    1.80 +
    1.81 +GrEffect::~GrEffect() {
    1.82 +    SkASSERT(NULL == fEffectRef);
    1.83 +}
    1.84 +
    1.85 +const char* GrEffect::name() const {
    1.86 +    return this->getFactory().name();
    1.87 +}
    1.88 +
    1.89 +void GrEffect::addCoordTransform(const GrCoordTransform* transform) {
    1.90 +    fCoordTransforms.push_back(transform);
    1.91 +    SkDEBUGCODE(transform->setInEffect();)
    1.92 +}
    1.93 +
    1.94 +void GrEffect::addTextureAccess(const GrTextureAccess* access) {
    1.95 +    fTextureAccesses.push_back(access);
    1.96 +}
    1.97 +
    1.98 +void* GrEffect::operator new(size_t size) {
    1.99 +    return GrEffect_Globals::GetTLS()->allocate(size);
   1.100 +}
   1.101 +
   1.102 +void GrEffect::operator delete(void* target) {
   1.103 +    GrEffect_Globals::GetTLS()->release(target);
   1.104 +}
   1.105 +
   1.106 +#ifdef SK_DEBUG
   1.107 +void GrEffect::assertEquality(const GrEffect& other) const {
   1.108 +    SkASSERT(this->numTransforms() == other.numTransforms());
   1.109 +    for (int i = 0; i < this->numTransforms(); ++i) {
   1.110 +        SkASSERT(this->coordTransform(i) == other.coordTransform(i));
   1.111 +    }
   1.112 +    SkASSERT(this->numTextures() == other.numTextures());
   1.113 +    for (int i = 0; i < this->numTextures(); ++i) {
   1.114 +        SkASSERT(this->textureAccess(i) == other.textureAccess(i));
   1.115 +    }
   1.116 +}
   1.117 +#endif

mercurial