blob: 45298b522d3ef9e1bf367c19ea8989a8b02f900e [file] [log] [blame]
tomhudson@google.com168e6342012-04-18 17:49:20 +00001/*
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
joshualittb0a8a372014-09-23 09:50:21 -07008#include "GrProcessor.h"
9#include "GrBackendProcessorFactory.h"
bsalomon@google.com2eaaefd2012-10-29 19:51:22 +000010#include "GrContext.h"
bsalomon@google.com77af6802013-10-02 13:04:56 +000011#include "GrCoordTransform.h"
tomhudson@google.comdcba4c22012-07-24 21:36:16 +000012#include "GrMemoryPool.h"
13#include "SkTLS.h"
tomhudson@google.com168e6342012-04-18 17:49:20 +000014
joshualittb0a8a372014-09-23 09:50:21 -070015namespace GrProcessorUnitTest {
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +000016const SkMatrix& TestMatrix(SkRandom* random) {
bsalomon@google.comd8b5fac2012-11-01 17:02:46 +000017 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.org4b413c82013-11-25 19:44:07 +000027 gMatrices[4].set(SkMatrix::kMPersp0, 0.00013f);
28 gMatrices[4].set(SkMatrix::kMPersp1, -0.000039f);
bsalomon@google.comd8b5fac2012-11-01 17:02:46 +000029 gOnce = true;
30 }
31 return gMatrices[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gMatrices)))];
32}
33}
34
joshualittb0a8a372014-09-23 09:50:21 -070035class GrProcessor_Globals {
tomhudson@google.comdcba4c22012-07-24 21:36:16 +000036public:
37 static GrMemoryPool* GetTLS() {
38 return (GrMemoryPool*)SkTLS::Get(CreateTLS, DeleteTLS);
39 }
40
41private:
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
joshualittb0a8a372014-09-23 09:50:21 -070051int32_t GrBackendProcessorFactory::fCurrEffectClassID =
52 GrBackendProcessorFactory::kIllegalEffectClassID;
tomhudson@google.com168e6342012-04-18 17:49:20 +000053
bsalomon@google.com0ac6af42013-01-16 15:16:18 +000054///////////////////////////////////////////////////////////////////////////////
55
joshualittb0a8a372014-09-23 09:50:21 -070056GrProcessor::~GrProcessor() {}
tomhudson@google.com168e6342012-04-18 17:49:20 +000057
joshualittb0a8a372014-09-23 09:50:21 -070058const char* GrProcessor::name() const {
bsalomon@google.com2eaaefd2012-10-29 19:51:22 +000059 return this->getFactory().name();
60}
61
joshualittb0a8a372014-09-23 09:50:21 -070062void GrProcessor::addCoordTransform(const GrCoordTransform* transform) {
bsalomon@google.com77af6802013-10-02 13:04:56 +000063 fCoordTransforms.push_back(transform);
commit-bot@chromium.org5fd7d5c2013-10-04 01:20:09 +000064 SkDEBUGCODE(transform->setInEffect();)
bsalomon@google.com77af6802013-10-02 13:04:56 +000065}
66
joshualittb0a8a372014-09-23 09:50:21 -070067void GrProcessor::addTextureAccess(const GrTextureAccess* access) {
bsalomon@google.com50db75c2013-01-11 13:54:30 +000068 fTextureAccesses.push_back(access);
bsalomonf96ba022014-09-17 08:05:40 -070069 this->addGpuResource(access->getProgramTexture());
twiz@google.coma5e65ec2012-08-02 15:15:16 +000070}
71
joshualittb0a8a372014-09-23 09:50:21 -070072void* GrProcessor::operator new(size_t size) {
73 return GrProcessor_Globals::GetTLS()->allocate(size);
tomhudson@google.comdcba4c22012-07-24 21:36:16 +000074}
75
joshualittb0a8a372014-09-23 09:50:21 -070076void GrProcessor::operator delete(void* target) {
77 GrProcessor_Globals::GetTLS()->release(target);
tomhudson@google.comdcba4c22012-07-24 21:36:16 +000078}
bsalomon@google.com77af6802013-10-02 13:04:56 +000079
80#ifdef SK_DEBUG
joshualittb0a8a372014-09-23 09:50:21 -070081void GrProcessor::assertEquality(const GrProcessor& other) const {
bsalomon@google.com77af6802013-10-02 13:04:56 +000082 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