From f7dcd76c552a4e93a75a3808289de69a997da169 Mon Sep 17 00:00:00 2001 From: Brian Salomon Date: Mon, 30 Jul 2018 14:48:15 -0400 Subject: Remove array of TextureSampler pointers from GrIOResourceProcessor. Instead store sampler count on base class and subclasses implement a virtual to get the ith sampler. Change-Id: I13e2447a6467a09761d8615acb4aa360b87b1476 Reviewed-on: https://skia-review.googlesource.com/141563 Commit-Queue: Brian Salomon Reviewed-by: Robert Phillips --- src/gpu/GrProcessor.h | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) (limited to 'src/gpu/GrProcessor.h') diff --git a/src/gpu/GrProcessor.h b/src/gpu/GrProcessor.h index 5d83ce3ddb..586f6d25b9 100644 --- a/src/gpu/GrProcessor.h +++ b/src/gpu/GrProcessor.h @@ -23,8 +23,6 @@ #include "SkString.h" class GrContext; -class GrCoordTransform; -class GrInvariantOutput; class GrResourceProvider; /** @@ -203,24 +201,31 @@ class GrResourceIOProcessor : public GrProcessor { public: class TextureSampler; - int numTextureSamplers() const { return fTextureSamplers.count(); } + int numTextureSamplers() const { return fNumTextureSamplers; } - /** Returns the access pattern for the texture at index. index must be valid according to - numTextureSamplers(). */ - const TextureSampler& textureSampler(int index) const { return *fTextureSamplers[index]; } + /** Gets a TextureSampler which is a combination of a GrTextureProxy and how it is sampled. + * index must be valid according to numTextureSamplers(). */ + const TextureSampler& textureSampler(int index) const { + SkASSERT(index >= 0 && index < fNumTextureSamplers); + return this->onTextureSampler(index); + } bool instantiate(GrResourceProvider* resourceProvider) const; protected: + template + static const TextureSampler& IthTextureSampler(int i, const TextureSampler& samp0, + const Args&... samps) { + return (0 == i) ? samp0 : IthTextureSampler(i - 1, samps...); + } + inline static const TextureSampler& IthTextureSampler(int i); + GrResourceIOProcessor(ClassID classID) : INHERITED(classID) {} - /** - * Subclasses call these from their constructor to register sampler sources. The processor - * subclass manages the lifetime of the objects (these functions only store pointers). The - * TextureSampler instances are typically member fields of the GrProcessor subclass. These must - * only be called from the constructor because GrProcessors are immutable. - */ - void addTextureSampler(const TextureSampler*); + void setTextureSamplerCnt(int numTextureSamplers) { + SkASSERT(numTextureSamplers >= 0); + fNumTextureSamplers = numTextureSamplers; + } bool hasSameSamplers(const GrResourceIOProcessor&) const; @@ -230,8 +235,9 @@ protected: void pendingIOComplete() const; private: - SkSTArray<4, const TextureSampler*, true> fTextureSamplers; + virtual const TextureSampler& onTextureSampler(int index) const { return IthTextureSampler(0); } + int fNumTextureSamplers = 0; typedef GrProcessor INHERITED; }; @@ -306,4 +312,10 @@ private: GrShaderFlags fVisibility; }; +const GrResourceIOProcessor::TextureSampler& GrResourceIOProcessor::IthTextureSampler(int i) { + SK_ABORT("Illegal texture sampler index"); + static const TextureSampler kBogus; + return kBogus; +} + #endif -- cgit v1.2.3