aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2017-04-21 12:24:00 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-04-21 17:12:17 +0000
commit9f5d4679e107ab83de635392798b3ddd62f48a12 (patch)
tree59c25bac71401ce32219d1e8c4362004a3d889a6 /include
parent09419508669d203421f739b3105596655b7f0dcb (diff)
Remove more headers from include/gpu
TBR=bsalomon@google.com Change-Id: I93b28cfcb4d7b50c12e24ea81faab680bccce9ef Reviewed-on: https://skia-review.googlesource.com/14036 Commit-Queue: Robert Phillips <robertphillips@google.com> Reviewed-by: Brian Osman <brianosman@google.com>
Diffstat (limited to 'include')
-rw-r--r--include/gpu/GrBuffer.h136
-rw-r--r--include/gpu/GrColorSpaceXform.h45
-rw-r--r--include/gpu/GrCoordTransform.h128
-rw-r--r--include/gpu/GrFragmentProcessor.h353
-rw-r--r--include/gpu/GrProcessor.h350
-rw-r--r--include/gpu/GrProcessorUnitTest.h201
-rw-r--r--include/gpu/GrProgramElement.h128
-rw-r--r--include/gpu/GrTestUtils.h150
8 files changed, 0 insertions, 1491 deletions
diff --git a/include/gpu/GrBuffer.h b/include/gpu/GrBuffer.h
deleted file mode 100644
index b2201a140f..0000000000
--- a/include/gpu/GrBuffer.h
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * Copyright 2016 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef GrBuffer_DEFINED
-#define GrBuffer_DEFINED
-
-#include "GrGpuResource.h"
-
-class GrGpu;
-
-class GrBuffer : public GrGpuResource {
-public:
- /**
- * Creates a client-side buffer.
- */
- static SK_WARN_UNUSED_RESULT GrBuffer* CreateCPUBacked(GrGpu*, size_t sizeInBytes, GrBufferType,
- const void* data = nullptr);
-
- /**
- * Computes a scratch key for a GPU-side buffer with a "dynamic" access pattern. (Buffers with
- * "static" and "stream" patterns are disqualified by nature from being cached and reused.)
- */
- static void ComputeScratchKeyForDynamicVBO(size_t size, GrBufferType, GrScratchKey*);
-
- GrAccessPattern accessPattern() const { return fAccessPattern; }
- size_t sizeInBytes() const { return fSizeInBytes; }
-
- /**
- * Returns true if the buffer is a wrapper around a CPU array. If true it
- * indicates that map will always succeed and will be free.
- */
- bool isCPUBacked() const { return SkToBool(fCPUData); }
- size_t baseOffset() const { return reinterpret_cast<size_t>(fCPUData); }
-
- /**
- * Maps the buffer to be written by the CPU.
- *
- * The previous content of the buffer is invalidated. It is an error
- * to draw from the buffer while it is mapped. It may fail if the backend
- * doesn't support mapping the buffer. If the buffer is CPU backed then
- * it will always succeed and is a free operation. Once a buffer is mapped,
- * subsequent calls to map() are ignored.
- *
- * Note that buffer mapping does not go through GrContext and therefore is
- * not serialized with other operations.
- *
- * @return a pointer to the data or nullptr if the map fails.
- */
- void* map() {
- if (!fMapPtr) {
- this->onMap();
- }
- return fMapPtr;
- }
-
- /**
- * Unmaps the buffer.
- *
- * The pointer returned by the previous map call will no longer be valid.
- */
- void unmap() {
- SkASSERT(fMapPtr);
- this->onUnmap();
- fMapPtr = nullptr;
- }
-
- /**
- * Returns the same ptr that map() returned at time of map or nullptr if the
- * is not mapped.
- *
- * @return ptr to mapped buffer data or nullptr if buffer is not mapped.
- */
- void* mapPtr() const { return fMapPtr; }
-
- /**
- Queries whether the buffer has been mapped.
-
- @return true if the buffer is mapped, false otherwise.
- */
- bool isMapped() const { return SkToBool(fMapPtr); }
-
- /**
- * Updates the buffer data.
- *
- * The size of the buffer will be preserved. The src data will be
- * placed at the beginning of the buffer and any remaining contents will
- * be undefined. srcSizeInBytes must be <= to the buffer size.
- *
- * The buffer must not be mapped.
- *
- * Note that buffer updates do not go through GrContext and therefore are
- * not serialized with other operations.
- *
- * @return returns true if the update succeeds, false otherwise.
- */
- bool updateData(const void* src, size_t srcSizeInBytes) {
- SkASSERT(!this->isMapped());
- SkASSERT(srcSizeInBytes <= fSizeInBytes);
- return this->onUpdateData(src, srcSizeInBytes);
- }
-
- ~GrBuffer() override {
- sk_free(fCPUData);
- }
-
-protected:
- GrBuffer(GrGpu*, size_t sizeInBytes, GrBufferType, GrAccessPattern);
-
- void* fMapPtr;
-
-private:
- /**
- * Internal constructor to make a CPU-backed buffer.
- */
- GrBuffer(GrGpu*, size_t sizeInBytes, GrBufferType, void* cpuData);
-
- virtual void onMap() { SkASSERT(this->isCPUBacked()); fMapPtr = fCPUData; }
- virtual void onUnmap() { SkASSERT(this->isCPUBacked()); }
- virtual bool onUpdateData(const void* src, size_t srcSizeInBytes);
-
- size_t onGpuMemorySize() const override { return fSizeInBytes; } // TODO: zero for cpu backed?
- void computeScratchKey(GrScratchKey* key) const override;
-
- size_t fSizeInBytes;
- GrAccessPattern fAccessPattern;
- void* fCPUData;
- GrBufferType fIntendedType;
-
- typedef GrGpuResource INHERITED;
-};
-
-#endif
diff --git a/include/gpu/GrColorSpaceXform.h b/include/gpu/GrColorSpaceXform.h
deleted file mode 100644
index 68cd3b0563..0000000000
--- a/include/gpu/GrColorSpaceXform.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright 2016 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef GrColorSpaceXform_DEFINED
-#define GrColorSpaceXform_DEFINED
-
-#include "GrColor.h"
-#include "SkMatrix44.h"
-#include "SkRefCnt.h"
-
-class SkColorSpace;
-
- /**
- * Represents a color gamut transformation (as a 4x4 color matrix)
- */
-class GrColorSpaceXform : public SkRefCnt {
-public:
- GrColorSpaceXform(const SkMatrix44& srcToDst);
-
- static sk_sp<GrColorSpaceXform> Make(const SkColorSpace* src, const SkColorSpace* dst);
-
- const SkMatrix44& srcToDst() const { return fSrcToDst; }
-
- /**
- * GrGLSLFragmentProcessor::GenKey() must call this and include the returned value in its
- * computed key.
- */
- static uint32_t XformKey(const GrColorSpaceXform* xform) {
- // Code generation changes if there is an xform, but it otherwise constant
- return SkToBool(xform) ? 1 : 0;
- }
-
- static bool Equals(const GrColorSpaceXform* a, const GrColorSpaceXform* b);
-
- GrColor4f apply(const GrColor4f& srcColor);
-
-private:
- SkMatrix44 fSrcToDst;
-};
-
-#endif
diff --git a/include/gpu/GrCoordTransform.h b/include/gpu/GrCoordTransform.h
deleted file mode 100644
index 54c21b7472..0000000000
--- a/include/gpu/GrCoordTransform.h
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Copyright 2013 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef GrCoordTransform_DEFINED
-#define GrCoordTransform_DEFINED
-
-#include "SkMatrix.h"
-#include "GrTexture.h"
-
-class GrResourceProvider;
-class GrTextureProxy;
-
-/**
- * A class representing a linear transformation of local coordinates. GrFragnentProcessors
- * these transformations, and the GrGeometryProcessor implements the transformation.
- */
-class GrCoordTransform : SkNoncopyable {
-public:
- GrCoordTransform()
- : fTexture(nullptr)
- , fNormalize(false)
- , fReverseY(false) {
- SkDEBUGCODE(fInProcessor = false);
- }
-
- /**
- * Create a transformation that maps [0, 1] to a proxy's boundaries. The proxy origin also
- * implies whether a y-reversal should be performed.
- */
- GrCoordTransform(GrResourceProvider* resourceProvider, GrTextureProxy* proxy) {
- SkASSERT(proxy);
- SkDEBUGCODE(fInProcessor = false);
- this->reset(resourceProvider, SkMatrix::I(), proxy);
- }
-
- /**
- * Create a transformation from a matrix. The proxy origin also implies whether a y-reversal
- * should be performed.
- */
- GrCoordTransform(GrResourceProvider* resourceProvider, const SkMatrix& m,
- GrTextureProxy* proxy) {
- SkASSERT(proxy);
- SkDEBUGCODE(fInProcessor = false);
- this->reset(resourceProvider, m, proxy);
- }
-
- /**
- * Create a transformation that applies the matrix to a coord set.
- */
- GrCoordTransform(const SkMatrix& m) {
- SkDEBUGCODE(fInProcessor = false);
- this->reset(m);
- }
-
- void reset(GrResourceProvider*, const SkMatrix&, GrTextureProxy*, bool normalize = true);
-
- void reset(const SkMatrix& m) {
- SkASSERT(!fInProcessor);
- fMatrix = m;
- fTexture = nullptr;
- fNormalize = false;
- fReverseY = false;
- }
-
- GrCoordTransform& operator= (const GrCoordTransform& that) {
- SkASSERT(!fInProcessor);
- fMatrix = that.fMatrix;
- fTexture = that.fTexture;
- fNormalize = that.fNormalize;
- fReverseY = that.fReverseY;
- return *this;
- }
-
- /**
- * Access the matrix for editing. Note, this must be done before adding the transform to an
- * effect, since effects are immutable.
- */
- SkMatrix* accessMatrix() {
- SkASSERT(!fInProcessor);
- return &fMatrix;
- }
-
- bool hasSameEffectAs(const GrCoordTransform& that) const {
- if (fNormalize != that.fNormalize ||
- fReverseY != that.fReverseY ||
- !fMatrix.cheapEqualTo(that.fMatrix)) {
- return false;
- }
-
- if (fNormalize) {
- SkASSERT(fTexture && that.fTexture);
- return fTexture->width() == that.fTexture->width() &&
- fTexture->height() == that.fTexture->height();
- }
-
- return true;
- }
-
- const SkMatrix& getMatrix() const { return fMatrix; }
- const GrTexture* texture() const { return fTexture; }
- bool normalize() const { return fNormalize; }
- bool reverseY() const { return fReverseY; }
-
-private:
- // The textures' effect is to optionally normalize the final matrix, so a blind
- // equality check could be misleading
- bool operator==(const GrCoordTransform& that) const;
- bool operator!=(const GrCoordTransform& that) const;
-
- SkMatrix fMatrix;
- const GrTexture* fTexture;
- bool fNormalize;
- bool fReverseY;
- typedef SkNoncopyable INHERITED;
-
-#ifdef SK_DEBUG
-public:
- void setInProcessor() const { fInProcessor = true; }
-private:
- mutable bool fInProcessor;
-#endif
-};
-
-#endif
diff --git a/include/gpu/GrFragmentProcessor.h b/include/gpu/GrFragmentProcessor.h
deleted file mode 100644
index 00f2dbd9d8..0000000000
--- a/include/gpu/GrFragmentProcessor.h
+++ /dev/null
@@ -1,353 +0,0 @@
-/*
- * Copyright 2014 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef GrFragmentProcessor_DEFINED
-#define GrFragmentProcessor_DEFINED
-
-#include "GrProcessor.h"
-
-class GrCoordTransform;
-class GrGLSLFragmentProcessor;
-class GrInvariantOutput;
-class GrPipeline;
-class GrProcessorKeyBuilder;
-class GrShaderCaps;
-class GrSwizzle;
-
-/** Provides custom fragment shader code. Fragment processors receive an input color (vec4f) and
- produce an output color. They may reference textures and uniforms. They may use
- GrCoordTransforms to receive a transformation of the local coordinates that map from local space
- to the fragment being processed.
- */
-class GrFragmentProcessor : public GrResourceIOProcessor, public GrProgramElement {
-public:
- /**
- * In many instances (e.g. SkShader::asFragmentProcessor() implementations) it is desirable to
- * only consider the input color's alpha. However, there is a competing desire to have reusable
- * GrFragmentProcessor subclasses that can be used in other scenarios where the entire input
- * color is considered. This function exists to filter the input color and pass it to a FP. It
- * does so by returning a parent FP that multiplies the passed in FPs output by the parent's
- * input alpha. The passed in FP will not receive an input color.
- */
- static sk_sp<GrFragmentProcessor> MulOutputByInputAlpha(sk_sp<GrFragmentProcessor>);
-
- /**
- * This assumes that the input color to the returned processor will be unpremul and that the
- * passed processor (which becomes the returned processor's child) produces a premul output.
- * The result of the returned processor is a premul of its input color modulated by the child
- * processor's premul output.
- */
- static sk_sp<GrFragmentProcessor> MakeInputPremulAndMulByOutput(sk_sp<GrFragmentProcessor>);
-
- /**
- * Returns a parent fragment processor that adopts the passed fragment processor as a child.
- * The parent will ignore its input color and instead feed the passed in color as input to the
- * child.
- */
- static sk_sp<GrFragmentProcessor> OverrideInput(sk_sp<GrFragmentProcessor>, GrColor4f);
-
- /**
- * Returns a fragment processor that premuls the input before calling the passed in fragment
- * processor.
- */
- static sk_sp<GrFragmentProcessor> PremulInput(sk_sp<GrFragmentProcessor>);
-
- /**
- * Returns a fragment processor that calls the passed in fragment processor, and then premuls
- * the output.
- */
- static sk_sp<GrFragmentProcessor> PremulOutput(sk_sp<GrFragmentProcessor>);
-
- /**
- * Returns a fragment processor that calls the passed in fragment processor, and then unpremuls
- * the output.
- */
- static sk_sp<GrFragmentProcessor> UnpremulOutput(sk_sp<GrFragmentProcessor>);
-
- /**
- * Returns a fragment processor that calls the passed in fragment processor, and then swizzles
- * the output.
- */
- static sk_sp<GrFragmentProcessor> SwizzleOutput(sk_sp<GrFragmentProcessor>, const GrSwizzle&);
-
- /**
- * Returns a fragment processor that runs the passed in array of fragment processors in a
- * series. The original input is passed to the first, the first's output is passed to the
- * second, etc. The output of the returned processor is the output of the last processor of the
- * series.
- *
- * The array elements with be moved.
- */
- static sk_sp<GrFragmentProcessor> RunInSeries(sk_sp<GrFragmentProcessor>*, int cnt);
-
- ~GrFragmentProcessor() override;
-
- GrGLSLFragmentProcessor* createGLSLInstance() const;
-
- void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const {
- this->onGetGLSLProcessorKey(caps, b);
- for (int i = 0; i < fChildProcessors.count(); ++i) {
- fChildProcessors[i]->getGLSLProcessorKey(caps, b);
- }
- }
-
- int numCoordTransforms() const { return fCoordTransforms.count(); }
-
- /** Returns the coordinate transformation at index. index must be valid according to
- numTransforms(). */
- const GrCoordTransform& coordTransform(int index) const { return *fCoordTransforms[index]; }
-
- const SkTArray<const GrCoordTransform*, true>& coordTransforms() const {
- return fCoordTransforms;
- }
-
- int numChildProcessors() const { return fChildProcessors.count(); }
-
- const GrFragmentProcessor& childProcessor(int index) const { return *fChildProcessors[index]; }
-
- /** Do any of the coordtransforms for this processor require local coords? */
- bool usesLocalCoords() const { return SkToBool(fFlags & kUsesLocalCoords_Flag); }
-
- /** Does this FP need a vector to the nearest edge? */
- bool usesDistanceVectorField() const {
- return SkToBool(fFlags & kUsesDistanceVectorField_Flag);
- }
-
- /**
- * A GrDrawOp may premultiply its antialiasing coverage into its GrGeometryProcessor's color
- * output under the following scenario:
- * * all the color fragment processors report true to this query,
- * * all the coverage fragment processors report true to this query,
- * * the blend mode arithmetic allows for it it.
- * To be compatible a fragment processor's output must be a modulation of its input color or
- * alpha with a computed premultiplied color or alpha that is in 0..1 range. The computed color
- * or alpha that is modulated against the input cannot depend on the input's alpha. The computed
- * value cannot depend on the input's color channels unless it unpremultiplies the input color
- * channels by the input alpha.
- */
- bool compatibleWithCoverageAsAlpha() const {
- return SkToBool(fFlags & kCompatibleWithCoverageAsAlpha_OptimizationFlag);
- }
-
- /**
- * If this is true then all opaque input colors to the processor produce opaque output colors.
- */
- bool preservesOpaqueInput() const {
- return SkToBool(fFlags & kPreservesOpaqueInput_OptimizationFlag);
- }
-
- /**
- * Tests whether given a constant input color the processor produces a constant output color
- * (for all fragments). If true outputColor will contain the constant color produces for
- * inputColor.
- */
- bool hasConstantOutputForConstantInput(GrColor4f inputColor, GrColor4f* outputColor) const {
- if (fFlags & kConstantOutputForConstantInput_OptimizationFlag) {
- *outputColor = this->constantOutputForConstantInput(inputColor);
- return true;
- }
- return false;
- }
- bool hasConstantOutputForConstantInput() const {
- return SkToBool(fFlags & kConstantOutputForConstantInput_OptimizationFlag);
- }
-
- /** Returns true if this and other processor conservatively draw identically. It can only return
- true when the two processor are of the same subclass (i.e. they return the same object from
- from getFactory()).
-
- A return value of true from isEqual() should not be used to test whether the processor would
- generate the same shader code. To test for identical code generation use getGLSLProcessorKey
- */
- bool isEqual(const GrFragmentProcessor& that) const;
-
- /**
- * Pre-order traversal of a FP hierarchy, or of the forest of FPs in a GrPipeline. In the latter
- * case the tree rooted at each FP in the GrPipeline is visited successively.
- */
- class Iter : public SkNoncopyable {
- public:
- explicit Iter(const GrFragmentProcessor* fp) { fFPStack.push_back(fp); }
- explicit Iter(const GrPipeline& pipeline);
- const GrFragmentProcessor* next();
-
- private:
- SkSTArray<4, const GrFragmentProcessor*, true> fFPStack;
- };
-
- /**
- * Iterates over all the Ts owned by a GrFragmentProcessor and its children or over all the Ts
- * owned by the forest of GrFragmentProcessors in a GrPipeline. FPs are visited in the same
- * order as Iter and each of an FP's Ts are visited in order.
- */
- template <typename T, typename BASE,
- int (BASE::*COUNT)() const,
- const T& (BASE::*GET)(int) const>
- class FPItemIter : public SkNoncopyable {
- public:
- explicit FPItemIter(const GrFragmentProcessor* fp)
- : fCurrFP(nullptr)
- , fCTIdx(0)
- , fFPIter(fp) {
- fCurrFP = fFPIter.next();
- }
- explicit FPItemIter(const GrPipeline& pipeline)
- : fCurrFP(nullptr)
- , fCTIdx(0)
- , fFPIter(pipeline) {
- fCurrFP = fFPIter.next();
- }
-
- const T* next() {
- if (!fCurrFP) {
- return nullptr;
- }
- while (fCTIdx == (fCurrFP->*COUNT)()) {
- fCTIdx = 0;
- fCurrFP = fFPIter.next();
- if (!fCurrFP) {
- return nullptr;
- }
- }
- return &(fCurrFP->*GET)(fCTIdx++);
- }
-
- private:
- const GrFragmentProcessor* fCurrFP;
- int fCTIdx;
- GrFragmentProcessor::Iter fFPIter;
- };
-
- using CoordTransformIter = FPItemIter<GrCoordTransform,
- GrFragmentProcessor,
- &GrFragmentProcessor::numCoordTransforms,
- &GrFragmentProcessor::coordTransform>;
-
- using TextureAccessIter = FPItemIter<TextureSampler,
- GrResourceIOProcessor,
- &GrResourceIOProcessor::numTextureSamplers,
- &GrResourceIOProcessor::textureSampler>;
-
-protected:
- enum OptimizationFlags : uint32_t {
- kNone_OptimizationFlags,
- kCompatibleWithCoverageAsAlpha_OptimizationFlag = 0x1,
- kPreservesOpaqueInput_OptimizationFlag = 0x2,
- kConstantOutputForConstantInput_OptimizationFlag = 0x4,
- kAll_OptimizationFlags = kCompatibleWithCoverageAsAlpha_OptimizationFlag |
- kPreservesOpaqueInput_OptimizationFlag |
- kConstantOutputForConstantInput_OptimizationFlag
- };
- GR_DECL_BITFIELD_OPS_FRIENDS(OptimizationFlags)
-
- GrFragmentProcessor(OptimizationFlags optimizationFlags) : fFlags(optimizationFlags) {
- SkASSERT((fFlags & ~kAll_OptimizationFlags) == 0);
- }
-
- OptimizationFlags optimizationFlags() const {
- return static_cast<OptimizationFlags>(kAll_OptimizationFlags & fFlags);
- }
-
- /**
- * This allows one subclass to access another subclass's implementation of
- * constantOutputForConstantInput. It must only be called when
- * hasConstantOutputForConstantInput() is known to be true.
- */
- static GrColor4f ConstantOutputForConstantInput(const GrFragmentProcessor& fp,
- GrColor4f input) {
- SkASSERT(fp.hasConstantOutputForConstantInput());
- return fp.constantOutputForConstantInput(input);
- }
-
- /**
- * Fragment Processor subclasses call this from their constructor to register coordinate
- * transformations. Coord transforms provide a mechanism for a processor to receive coordinates
- * in their FS code. The matrix expresses a transformation from local space. For a given
- * fragment the matrix will be applied to the local coordinate that maps to the fragment.
- *
- * When the transformation has perspective, the transformed coordinates will have
- * 3 components. Otherwise they'll have 2.
- *
- * This must only be called from the constructor because GrProcessors are immutable. The
- * processor subclass manages the lifetime of the transformations (this function only stores a
- * pointer). The GrCoordTransform is typically a member field of the GrProcessor subclass.
- *
- * A processor subclass that has multiple methods of construction should always add its coord
- * transforms in a consistent order. The non-virtual implementation of isEqual() automatically
- * compares transforms and will assume they line up across the two processor instances.
- */
- void addCoordTransform(const GrCoordTransform*);
-
- /**
- * FragmentProcessor subclasses call this from their constructor to register any child
- * FragmentProcessors they have. This must be called AFTER all texture accesses and coord
- * transforms have been added.
- * This is for processors whose shader code will be composed of nested processors whose output
- * colors will be combined somehow to produce its output color. Registering these child
- * processors will allow the ProgramBuilder to automatically handle their transformed coords and
- * texture accesses and mangle their uniform and output color names.
- */
- int registerChildProcessor(sk_sp<GrFragmentProcessor> child);
-
- /**
- * Sub-classes should call this in their constructors if they need access to a distance
- * vector field to the nearest edge
- */
- void setWillUseDistanceVectorField() { fFlags |= kUsesDistanceVectorField_Flag; }
-
-private:
- void addPendingIOs() const override { GrResourceIOProcessor::addPendingIOs(); }
- void removeRefs() const override { GrResourceIOProcessor::removeRefs(); }
- void pendingIOComplete() const override { GrResourceIOProcessor::pendingIOComplete(); }
-
- void notifyRefCntIsZero() const final;
-
- virtual GrColor4f constantOutputForConstantInput(GrColor4f /* inputColor */) const {
- SkFAIL("Subclass must override this if advertising this optimization.");
- return GrColor4f::TransparentBlack();
- }
-
- /** Returns a new instance of the appropriate *GL* implementation class
- for the given GrFragmentProcessor; caller is responsible for deleting
- the object. */
- virtual GrGLSLFragmentProcessor* onCreateGLSLInstance() const = 0;
-
- /** Implemented using GLFragmentProcessor::GenKey as described in this class's comment. */
- virtual void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const = 0;
-
- /**
- * Subclass implements this to support isEqual(). It will only be called if it is known that
- * the two processors are of the same subclass (i.e. they return the same object from
- * getFactory()). The processor subclass should not compare its coord transforms as that will
- * be performed automatically in the non-virtual isEqual().
- */
- virtual bool onIsEqual(const GrFragmentProcessor&) const = 0;
-
- bool hasSameTransforms(const GrFragmentProcessor&) const;
-
- enum PrivateFlags {
- kFirstPrivateFlag = kAll_OptimizationFlags + 1,
- kUsesLocalCoords_Flag = kFirstPrivateFlag,
- kUsesDistanceVectorField_Flag = kFirstPrivateFlag << 1,
- };
-
- mutable uint32_t fFlags = 0;
-
- SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms;
-
- /**
- * This is not SkSTArray<1, sk_sp<GrFragmentProcessor>> because this class holds strong
- * references until notifyRefCntIsZero and then it holds pending executions.
- */
- SkSTArray<1, GrFragmentProcessor*, true> fChildProcessors;
-
- typedef GrProcessor INHERITED;
-};
-
-GR_MAKE_BITFIELD_OPS(GrFragmentProcessor::OptimizationFlags)
-
-#endif
diff --git a/include/gpu/GrProcessor.h b/include/gpu/GrProcessor.h
deleted file mode 100644
index 1816db2ea5..0000000000
--- a/include/gpu/GrProcessor.h
+++ /dev/null
@@ -1,350 +0,0 @@
-/*
- * Copyright 2012 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef GrProcessor_DEFINED
-#define GrProcessor_DEFINED
-
-#include "GrColor.h"
-#include "GrBuffer.h"
-#include "GrGpuResourceRef.h"
-#include "GrProcessorUnitTest.h"
-#include "GrProgramElement.h"
-#include "GrSamplerParams.h"
-#include "GrShaderVar.h"
-#include "SkMath.h"
-#include "SkString.h"
-#include "../private/SkAtomics.h"
-
-class GrContext;
-class GrCoordTransform;
-class GrInvariantOutput;
-class GrResourceProvider;
-class GrTextureProxy;
-
-/**
- * Used by processors to build their keys. It incorporates each per-processor key into a larger
- * shader key.
- */
-class GrProcessorKeyBuilder {
-public:
- GrProcessorKeyBuilder(SkTArray<unsigned char, true>* data) : fData(data), fCount(0) {
- SkASSERT(0 == fData->count() % sizeof(uint32_t));
- }
-
- void add32(uint32_t v) {
- ++fCount;
- fData->push_back_n(4, reinterpret_cast<uint8_t*>(&v));
- }
-
- /** Inserts count uint32_ts into the key. The returned pointer is only valid until the next
- add*() call. */
- uint32_t* SK_WARN_UNUSED_RESULT add32n(int count) {
- SkASSERT(count > 0);
- fCount += count;
- return reinterpret_cast<uint32_t*>(fData->push_back_n(4 * count));
- }
-
- size_t size() const { return sizeof(uint32_t) * fCount; }
-
-private:
- SkTArray<uint8_t, true>* fData; // unowned ptr to the larger key.
- int fCount; // number of uint32_ts added to fData by the processor.
-};
-
-/** Provides custom shader code to the Ganesh shading pipeline. GrProcessor objects *must* be
- immutable: after being constructed, their fields may not change.
-
- Dynamically allocated GrProcessors are managed by a per-thread memory pool. The ref count of an
- processor must reach 0 before the thread terminates and the pool is destroyed.
- */
-class GrProcessor {
-public:
- virtual ~GrProcessor() = default;
-
- /** Human-meaningful string to identify this prcoessor; may be embedded in generated shader
- code. */
- virtual const char* name() const = 0;
-
- /** Human-readable dump of all information */
- virtual SkString dumpInfo() const {
- SkString str;
- str.appendf("Missing data");
- return str;
- }
-
- /**
- * Platform specific built-in features that a processor can request for the fragment shader.
- */
- enum RequiredFeatures {
- kNone_RequiredFeatures = 0,
- kSampleLocations_RequiredFeature = 1 << 0
- };
-
- GR_DECL_BITFIELD_OPS_FRIENDS(RequiredFeatures);
-
- RequiredFeatures requiredFeatures() const { return fRequiredFeatures; }
-
- void* operator new(size_t size);
- void operator delete(void* target);
-
- void* operator new(size_t size, void* placement) {
- return ::operator new(size, placement);
- }
- void operator delete(void* target, void* placement) {
- ::operator delete(target, placement);
- }
-
- /** Helper for down-casting to a GrProcessor subclass */
- template <typename T> const T& cast() const { return *static_cast<const T*>(this); }
-
- uint32_t classID() const { SkASSERT(kIllegalProcessorClassID != fClassID); return fClassID; }
-
-protected:
- GrProcessor() : fClassID(kIllegalProcessorClassID), fRequiredFeatures(kNone_RequiredFeatures) {}
-
- /**
- * If the prcoessor will generate code that uses platform specific built-in features, then it
- * must call these methods from its constructor. Otherwise, requests to use these features will
- * be denied.
- */
- void setWillUseSampleLocations() { fRequiredFeatures |= kSampleLocations_RequiredFeature; }
-
- void combineRequiredFeatures(const GrProcessor& other) {
- fRequiredFeatures |= other.fRequiredFeatures;
- }
-
- template <typename PROC_SUBCLASS> void initClassID() {
- static uint32_t kClassID = GenClassID();
- fClassID = kClassID;
- }
-
-private:
- GrProcessor(const GrProcessor&) = delete;
- GrProcessor& operator=(const GrProcessor&) = delete;
-
- static uint32_t GenClassID() {
- // fCurrProcessorClassID has been initialized to kIllegalProcessorClassID. The
- // atomic inc returns the old value not the incremented value. So we add
- // 1 to the returned value.
- uint32_t id = static_cast<uint32_t>(sk_atomic_inc(&gCurrProcessorClassID)) + 1;
- if (!id) {
- SkFAIL("This should never wrap as it should only be called once for each GrProcessor "
- "subclass.");
- }
- return id;
- }
-
- enum {
- kIllegalProcessorClassID = 0,
- };
- static int32_t gCurrProcessorClassID;
-
- uint32_t fClassID;
- RequiredFeatures fRequiredFeatures;
-};
-
-GR_MAKE_BITFIELD_OPS(GrProcessor::RequiredFeatures);
-
-/** A GrProcessor with the ability to access textures, buffers, and image storages. */
-class GrResourceIOProcessor : public GrProcessor {
-public:
- class TextureSampler;
- class BufferAccess;
- class ImageStorageAccess;
-
- int numTextureSamplers() const { return fTextureSamplers.count(); }
-
- /** 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]; }
-
- int numBuffers() const { return fBufferAccesses.count(); }
-
- /** Returns the access pattern for the buffer at index. index must be valid according to
- numBuffers(). */
- const BufferAccess& bufferAccess(int index) const { return *fBufferAccesses[index]; }
-
- int numImageStorages() const { return fImageStorageAccesses.count(); }
-
- /** Returns the access object for the image at index. index must be valid according to
- numImages(). */
- const ImageStorageAccess& imageStorageAccess(int index) const {
- return *fImageStorageAccesses[index];
- }
-
-protected:
- GrResourceIOProcessor() = default;
-
- /**
- * Subclasses call these from their constructor to register sampler/image sources. The processor
- * subclass manages the lifetime of the objects (these functions only store pointers). The
- * TextureSampler and/or BufferAccess 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 addBufferAccess(const BufferAccess*);
- void addImageStorageAccess(const ImageStorageAccess*);
-
- bool hasSameSamplersAndAccesses(const GrResourceIOProcessor&) const;
-
- // These methods can be used by derived classes that also derive from GrProgramElement.
- void addPendingIOs() const;
- void removeRefs() const;
- void pendingIOComplete() const;
-
-private:
- SkSTArray<4, const TextureSampler*, true> fTextureSamplers;
- SkSTArray<1, const BufferAccess*, true> fBufferAccesses;
- SkSTArray<1, const ImageStorageAccess*, true> fImageStorageAccesses;
-
- typedef GrProcessor INHERITED;
-};
-
-/**
- * Used to represent a texture that is required by a GrResourceIOProcessor. It holds a GrTexture
- * along with an associated GrSamplerParams. TextureSamplers don't perform any coord manipulation to
- * account for texture origin.
- */
-class GrResourceIOProcessor::TextureSampler : public SkNoncopyable {
-public:
- /**
- * Must be initialized before adding to a GrProcessor's texture access list.
- */
- TextureSampler();
-
- // MDB TODO: this is the last GrTexture-based reset call!
- void reset(GrTexture*,
- GrSamplerParams::FilterMode = GrSamplerParams::kNone_FilterMode,
- SkShader::TileMode tileXAndY = SkShader::kClamp_TileMode,
- GrShaderFlags visibility = kFragment_GrShaderFlag);
-
- // MDB TODO: ultimately we shouldn't need the resource provider parameter
- TextureSampler(GrResourceProvider*, sk_sp<GrTextureProxy>, const GrSamplerParams&);
- explicit TextureSampler(GrResourceProvider*, sk_sp<GrTextureProxy>,
- GrSamplerParams::FilterMode = GrSamplerParams::kNone_FilterMode,
- SkShader::TileMode tileXAndY = SkShader::kClamp_TileMode,
- GrShaderFlags visibility = kFragment_GrShaderFlag);
- void reset(GrResourceProvider*, sk_sp<GrTextureProxy>, const GrSamplerParams&,
- GrShaderFlags visibility = kFragment_GrShaderFlag);
- void reset(GrResourceProvider*, sk_sp<GrTextureProxy>,
- GrSamplerParams::FilterMode = GrSamplerParams::kNone_FilterMode,
- SkShader::TileMode tileXAndY = SkShader::kClamp_TileMode,
- GrShaderFlags visibility = kFragment_GrShaderFlag);
-
- bool operator==(const TextureSampler& that) const {
- return this->texture() == that.texture() &&
- fParams == that.fParams &&
- fVisibility == that.fVisibility;
- }
-
- bool operator!=(const TextureSampler& other) const { return !(*this == other); }
-
- GrTexture* texture() const { return fTexture.get(); }
- GrShaderFlags visibility() const { return fVisibility; }
- const GrSamplerParams& params() const { return fParams; }
-
- /**
- * For internal use by GrProcessor.
- */
- const GrGpuResourceRef* programTexture() const { return &fTexture; }
-
-private:
-
- typedef GrTGpuResourceRef<GrTexture> ProgramTexture;
-
- ProgramTexture fTexture;
- GrSamplerParams fParams;
- GrShaderFlags fVisibility;
-
- typedef SkNoncopyable INHERITED;
-};
-
-/**
- * Used to represent a texel buffer that will be read in a GrResourceIOProcessor. It holds a
- * GrBuffer along with an associated offset and texel config.
- */
-class GrResourceIOProcessor::BufferAccess : public SkNoncopyable {
-public:
- BufferAccess() = default;
- BufferAccess(GrPixelConfig texelConfig, GrBuffer* buffer,
- GrShaderFlags visibility = kFragment_GrShaderFlag) {
- this->reset(texelConfig, buffer, visibility);
- }
- /**
- * Must be initialized before adding to a GrProcessor's buffer access list.
- */
- void reset(GrPixelConfig texelConfig, GrBuffer* buffer,
- GrShaderFlags visibility = kFragment_GrShaderFlag) {
- fTexelConfig = texelConfig;
- fBuffer.set(SkRef(buffer), kRead_GrIOType);
- fVisibility = visibility;
- }
-
- bool operator==(const BufferAccess& that) const {
- return fTexelConfig == that.fTexelConfig &&
- this->buffer() == that.buffer() &&
- fVisibility == that.fVisibility;
- }
-
- bool operator!=(const BufferAccess& that) const { return !(*this == that); }
-
- GrPixelConfig texelConfig() const { return fTexelConfig; }
- GrBuffer* buffer() const { return fBuffer.get(); }
- GrShaderFlags visibility() const { return fVisibility; }
-
- /**
- * For internal use by GrProcessor.
- */
- const GrGpuResourceRef* programBuffer() const { return &fBuffer;}
-
-private:
- GrPixelConfig fTexelConfig;
- GrTGpuResourceRef<GrBuffer> fBuffer;
- GrShaderFlags fVisibility;
-
- typedef SkNoncopyable INHERITED;
-};
-
-/**
- * This is used by a GrProcessor to access a texture using image load/store in its shader code.
- * ImageStorageAccesses don't perform any coord manipulation to account for texture origin.
- * Currently the format of the load/store data in the shader is inferred from the texture config,
- * though it could be made explicit.
- */
-class GrResourceIOProcessor::ImageStorageAccess : public SkNoncopyable {
-public:
- ImageStorageAccess(sk_sp<GrTexture> texture, GrIOType ioType, GrSLMemoryModel, GrSLRestrict,
- GrShaderFlags visibility = kFragment_GrShaderFlag);
-
- bool operator==(const ImageStorageAccess& that) const {
- return this->texture() == that.texture() && fVisibility == that.fVisibility;
- }
-
- bool operator!=(const ImageStorageAccess& that) const { return !(*this == that); }
-
- GrTexture* texture() const { return fTexture.get(); }
- GrShaderFlags visibility() const { return fVisibility; }
- GrIOType ioType() const { return fTexture.ioType(); }
- GrImageStorageFormat format() const { return fFormat; }
- GrSLMemoryModel memoryModel() const { return fMemoryModel; }
- GrSLRestrict restrict() const { return fRestrict; }
-
- /**
- * For internal use by GrProcessor.
- */
- const GrGpuResourceRef* programTexture() const { return &fTexture; }
-
-private:
- GrTGpuResourceRef<GrTexture> fTexture;
- GrShaderFlags fVisibility;
- GrImageStorageFormat fFormat;
- GrSLMemoryModel fMemoryModel;
- GrSLRestrict fRestrict;
- typedef SkNoncopyable INHERITED;
-};
-
-#endif
diff --git a/include/gpu/GrProcessorUnitTest.h b/include/gpu/GrProcessorUnitTest.h
deleted file mode 100644
index d6269c85bd..0000000000
--- a/include/gpu/GrProcessorUnitTest.h
+++ /dev/null
@@ -1,201 +0,0 @@
-/*
- * Copyright 2012 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef GrProcessorUnitTest_DEFINED
-#define GrProcessorUnitTest_DEFINED
-
-#include "SkTypes.h"
-
-#if GR_TEST_UTILS
-
-#include "../private/GrTextureProxy.h"
-#include "../private/SkTArray.h"
-#include "GrTestUtils.h"
-
-class SkMatrix;
-class GrCaps;
-class GrContext;
-class GrRenderTargetContext;
-struct GrProcessorTestData;
-class GrTexture;
-class GrXPFactory;
-
-namespace GrProcessorUnitTest {
-
-// Used to access the dummy textures in TestCreate procs.
-enum {
- kSkiaPMTextureIdx = 0,
- kAlphaTextureIdx = 1,
-};
-
-/** This allows parent FPs to implement a test create with known leaf children in order to avoid
-creating an unbounded FP tree which may overflow various shader limits. */
-sk_sp<GrFragmentProcessor> MakeChildFP(GrProcessorTestData*);
-
-}
-
-/*
- * GrProcessorTestData is an argument struct to TestCreate functions
- * fTextures are valid textures that can optionally be used to construct
- * TextureSampler. The first texture has config kSkia8888_GrPixelConfig and the second has
- * kAlpha_8_GrPixelConfig. TestCreate functions are also free to create additional textures using
- * the GrContext.
- */
-struct GrProcessorTestData {
- GrProcessorTestData(SkRandom* random,
- GrContext* context,
- const GrRenderTargetContext* renderTargetContext,
- sk_sp<GrTextureProxy> proxies[2])
- : fRandom(random)
- , fRenderTargetContext(renderTargetContext)
- , fContext(context) {
- fProxies[0] = proxies[0];
- fProxies[1] = proxies[1];
- }
- SkRandom* fRandom;
- const GrRenderTargetContext* fRenderTargetContext;
-
- GrContext* context() { return fContext; }
- GrResourceProvider* resourceProvider();
- const GrCaps* caps();
- sk_sp<GrTextureProxy> textureProxy(int index) { return fProxies[index]; }
-
-private:
- GrContext* fContext;
- sk_sp<GrTextureProxy> fProxies[2];
-};
-
-#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
-
-class GrProcessor;
-class GrTexture;
-
-template <class Processor> class GrProcessorTestFactory : private SkNoncopyable {
-public:
- typedef sk_sp<Processor> (*MakeProc)(GrProcessorTestData*);
-
- GrProcessorTestFactory(MakeProc makeProc) {
- fMakeProc = makeProc;
- GetFactories()->push_back(this);
- }
-
- /** Pick a random factory function and create a processor. */
- static sk_sp<Processor> Make(GrProcessorTestData* data) {
- VerifyFactoryCount();
- SkASSERT(GetFactories()->count());
- uint32_t idx = data->fRandom->nextRangeU(0, GetFactories()->count() - 1);
- return MakeIdx(idx, data);
- }
-
- /** Number of registered factory functions */
- static int Count() { return GetFactories()->count(); }
-
- /** Use factory function at Index idx to create a processor. */
- static sk_sp<Processor> MakeIdx(int idx, GrProcessorTestData* data) {
- GrProcessorTestFactory<Processor>* factory = (*GetFactories())[idx];
- sk_sp<Processor> processor = factory->fMakeProc(data);
- SkASSERT(processor);
- return processor;
- }
-
-private:
- /**
- * A test function which verifies the count of factories.
- */
- static void VerifyFactoryCount();
-
- MakeProc fMakeProc;
-
- static SkTArray<GrProcessorTestFactory<Processor>*, true>* GetFactories();
-};
-
-class GrXPFactoryTestFactory : private SkNoncopyable {
-public:
- using GetFn = const GrXPFactory*(GrProcessorTestData*);
-
- GrXPFactoryTestFactory(GetFn* getProc) : fGetProc(getProc) { GetFactories()->push_back(this); }
-
- static const GrXPFactory* Get(GrProcessorTestData* data) {
- VerifyFactoryCount();
- SkASSERT(GetFactories()->count());
- uint32_t idx = data->fRandom->nextRangeU(0, GetFactories()->count() - 1);
- const GrXPFactory* xpf = (*GetFactories())[idx]->fGetProc(data);
- SkASSERT(xpf);
- return xpf;
- }
-
-private:
- static void VerifyFactoryCount();
-
- GetFn* fGetProc;
- static SkTArray<GrXPFactoryTestFactory*, true>* GetFactories();
-};
-
-/** GrProcessor subclasses should insert this macro in their declaration to be included in the
- * program generation unit test.
- */
-#define GR_DECLARE_GEOMETRY_PROCESSOR_TEST \
- static GrProcessorTestFactory<GrGeometryProcessor> gTestFactory SK_UNUSED; \
- static sk_sp<GrGeometryProcessor> TestCreate(GrProcessorTestData*)
-
-#define GR_DECLARE_FRAGMENT_PROCESSOR_TEST \
- static GrProcessorTestFactory<GrFragmentProcessor> gTestFactory SK_UNUSED; \
- static sk_sp<GrFragmentProcessor> TestCreate(GrProcessorTestData*)
-
-#define GR_DECLARE_XP_FACTORY_TEST \
- static GrXPFactoryTestFactory gTestFactory SK_UNUSED; \
- static const GrXPFactory* TestGet(GrProcessorTestData*)
-
-/** GrProcessor subclasses should insert this macro in their implementation file. They must then
- * also implement this static function:
- * GrProcessor* TestCreate(GrProcessorTestData*);
- */
-#define GR_DEFINE_FRAGMENT_PROCESSOR_TEST(Effect) \
- GrProcessorTestFactory<GrFragmentProcessor> Effect::gTestFactory(Effect::TestCreate)
-
-#define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(Effect) \
- GrProcessorTestFactory<GrGeometryProcessor> Effect::gTestFactory(Effect::TestCreate)
-
-#define GR_DEFINE_XP_FACTORY_TEST(Factory) \
- GrXPFactoryTestFactory Factory::gTestFactory(Factory::TestGet)
-
-#else // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
-
-// The unit test relies on static initializers. Just declare the TestCreate function so that
-// its definitions will compile.
-#define GR_DECLARE_FRAGMENT_PROCESSOR_TEST \
- static sk_sp<GrFragmentProcessor> TestCreate(GrProcessorTestData*)
-#define GR_DEFINE_FRAGMENT_PROCESSOR_TEST(X)
-
-// The unit test relies on static initializers. Just declare the TestCreate function so that
-// its definitions will compile.
-#define GR_DECLARE_GEOMETRY_PROCESSOR_TEST \
- static sk_sp<GrGeometryProcessor> TestCreate(GrProcessorTestData*)
-#define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(X)
-
-// The unit test relies on static initializers. Just declare the TestGet function so that
-// its definitions will compile.
-#define GR_DECLARE_XP_FACTORY_TEST \
- const GrXPFactory* TestGet(GrProcessorTestData*)
-#define GR_DEFINE_XP_FACTORY_TEST(X)
-
-#endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
-#else // GR_TEST_UTILS
- #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST
- #define GR_DECLARE_FRAGMENT_PROCESSOR_TEST
- #define GR_DECLARE_XP_FACTORY_TEST
- #define GR_DEFINE_FRAGMENT_PROCESSOR_TEST(...)
- #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(...)
- #define GR_DEFINE_XP_FACTORY_TEST(...)
- #define GR_DECLARE_FRAGMENT_PROCESSOR_TEST
- #define GR_DEFINE_FRAGMENT_PROCESSOR_TEST(...)
- #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST
- #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(...)
- #define GR_DECLARE_XP_FACTORY_TEST
- #define GR_DEFINE_XP_FACTORY_TEST(...)
-#endif // GR_TEST_UTILS
-#endif // GrProcessorUnitTest_DEFINED
diff --git a/include/gpu/GrProgramElement.h b/include/gpu/GrProgramElement.h
deleted file mode 100644
index 425f57a59d..0000000000
--- a/include/gpu/GrProgramElement.h
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Copyright 2014 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef GrProgramElement_DEFINED
-#define GrProgramElement_DEFINED
-
-#include "../private/SkTArray.h"
-#include "SkRefCnt.h"
-
-class GrGpuResourceRef;
-
-/**
- * Note: We are converting GrProcessor from ref counting to a single owner model using move
- * semantics. This class will be removed.
- *
- * This is used to track "refs" for two separate types GrProcessor ownership. A regular ref is owned
- * by any client that may continue to issue draws that use the GrProgramElement. A recorded op or
- * GrPipeline uses "pending executions" instead of refs. A pending execution is cleared after the
- * draw is executed (or aborted).
- *
- * While a GrProgramElement is ref'ed any resources it owns are also ref'ed. However, once it gets
- * into the state where it has pending executions AND no refs then it converts its ownership of
- * its GrGpuResources from refs to pending IOs. The pending IOs allow the cache to track when it is
- * safe to recycle a resource even though we still have buffered GrOps that read or write to the
- * the resource.
- *
- * To make this work the subclass GrProcessor implements addPendingIOs, removeRefs, and
- * pendingIOComplete. addPendingIOs adds pending reads/writes to GrGpuResources owned by the
- * processor as appropriate when the processor is recorded in a GrOpList. removeRefs is called when
- * the ref count reaches 0 and the GrProcessor is only owned by "pending executions".
- * pendingIOComplete occurs if the resource is still owned by a ref but all recorded draws have been
- * completed. Whenever pending executions and refs reach zero the processor is deleted.
- *
- * The GrProcessor may also implement notifyRefCntIsZero in order to change its ownership of child
- * processors from ref to pending execution when the processor is first owned exclusively in pending
- * execution mode.
- */
-class GrProgramElement : public SkNoncopyable {
-public:
- virtual ~GrProgramElement() {
- // fRefCnt can be one when an effect is created statically using GR_CREATE_STATIC_EFFECT
- SkASSERT((0 == fRefCnt || 1 == fRefCnt) && 0 == fPendingExecutions);
- // Set to invalid values.
- SkDEBUGCODE(fRefCnt = fPendingExecutions = -10;)
- }
-
- void ref() const {
- this->validate();
- // Once the ref cnt reaches zero it should never be ref'ed again.
- SkASSERT(fRefCnt > 0);
- ++fRefCnt;
- this->validate();
- }
-
- void unref() const {
- this->validate();
- --fRefCnt;
- if (0 == fRefCnt) {
- this->notifyRefCntIsZero();
- if (0 == fPendingExecutions) {
- delete this;
- return;
- } else {
- this->removeRefs();
- }
- }
- this->validate();
- }
-
- void validate() const {
-#ifdef SK_DEBUG
- SkASSERT(fRefCnt >= 0);
- SkASSERT(fPendingExecutions >= 0);
- SkASSERT(fRefCnt + fPendingExecutions > 0);
-#endif
- }
-
-protected:
- GrProgramElement() : fRefCnt(1), fPendingExecutions(0) {}
-
- void addPendingExecution() const {
- this->validate();
- if (0 == fPendingExecutions) {
- this->addPendingIOs();
- }
- ++fPendingExecutions;
- this->validate();
- }
-
- void completedExecution() const {
- this->validate();
- --fPendingExecutions;
- if (0 == fPendingExecutions) {
- if (0 == fRefCnt) {
- delete this;
- return;
- } else {
- this->pendingIOComplete();
- }
- }
- this->validate();
- }
-
-private:
- virtual void addPendingIOs() const = 0;
- virtual void removeRefs() const = 0;
- virtual void pendingIOComplete() const = 0;
-
- /** This will be called when the ref cnt is zero. The object may or may not have pending
- executions. */
- virtual void notifyRefCntIsZero() const = 0;
-
- mutable int32_t fRefCnt;
- // Count of deferred executions not yet issued to the 3D API.
- mutable int32_t fPendingExecutions;
-
- // Only these classes can access addPendingExecution() and completedExecution().
- template <typename T> friend class GrPendingProgramElement;
- friend class GrProcessorSet;
-
- typedef SkNoncopyable INHERITED;
-};
-
-#endif
diff --git a/include/gpu/GrTestUtils.h b/include/gpu/GrTestUtils.h
deleted file mode 100644
index 5bb1cc1738..0000000000
--- a/include/gpu/GrTestUtils.h
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * Copyright 2015 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef GrTestUtils_DEFINED
-#define GrTestUtils_DEFINED
-
-#include "SkTypes.h"
-
-#if GR_TEST_UTILS
-
-#include "GrColor.h"
-#include "GrColorSpaceXform.h"
-#include "SkPathEffect.h"
-#include "SkRandom.h"
-#include "SkShader.h"
-#include "SkStrokeRec.h"
-#include "../private/SkTemplates.h"
-
-struct GrProcessorTestData;
-class GrStyle;
-class SkMatrix;
-class SkPath;
-class SkRRect;
-struct SkRect;
-
-namespace GrTest {
-/**
- * Helpers for use in Test functions.
- */
-const SkMatrix& TestMatrix(SkRandom*);
-const SkMatrix& TestMatrixPreservesRightAngles(SkRandom*);
-const SkMatrix& TestMatrixRectStaysRect(SkRandom*);
-const SkMatrix& TestMatrixInvertible(SkRandom*);
-const SkMatrix& TestMatrixPerspective(SkRandom*);
-const SkRect& TestRect(SkRandom*);
-const SkRect& TestSquare(SkRandom*);
-const SkRRect& TestRRectSimple(SkRandom*);
-const SkPath& TestPath(SkRandom*);
-const SkPath& TestPathConvex(SkRandom*);
-SkStrokeRec TestStrokeRec(SkRandom*);
-/** Creates styles with dash path effects and null path effects */
-void TestStyle(SkRandom*, GrStyle*);
-sk_sp<SkColorSpace> TestColorSpace(SkRandom*);
-sk_sp<GrColorSpaceXform> TestColorXform(SkRandom*);
-
-class TestAsFPArgs {
-public:
- TestAsFPArgs(GrProcessorTestData*);
- const SkShader::AsFPArgs& args() const { return fArgs; }
-
-private:
- SkShader::AsFPArgs fArgs;
- SkMatrix fViewMatrixStorage;
- sk_sp<SkColorSpace> fColorSpaceStorage;
-};
-
-// We have a simplified dash path effect here to avoid relying on SkDashPathEffect which
-// is in the optional build target effects.
-class TestDashPathEffect : public SkPathEffect {
-public:
- static sk_sp<SkPathEffect> Make(const SkScalar* intervals, int count, SkScalar phase) {
- return sk_sp<SkPathEffect>(new TestDashPathEffect(intervals, count, phase));
- }
-
- bool filterPath(SkPath* dst, const SkPath&, SkStrokeRec* , const SkRect*) const override;
- DashType asADash(DashInfo* info) const override;
- Factory getFactory() const override { return nullptr; }
- void toString(SkString*) const override {}
-
-private:
- TestDashPathEffect(const SkScalar* intervals, int count, SkScalar phase);
-
- int fCount;
- SkAutoTArray<SkScalar> fIntervals;
- SkScalar fPhase;
- SkScalar fInitialDashLength;
- int fInitialDashIndex;
- SkScalar fIntervalLength;
-};
-
-} // namespace GrTest
-
-static inline GrColor GrRandomColor(SkRandom* random) {
- // There are only a few cases of random colors which interest us
- enum ColorMode {
- kAllOnes_ColorMode,
- kAllZeros_ColorMode,
- kAlphaOne_ColorMode,
- kRandom_ColorMode,
- kLast_ColorMode = kRandom_ColorMode
- };
-
- ColorMode colorMode = ColorMode(random->nextULessThan(kLast_ColorMode + 1));
- GrColor color SK_INIT_TO_AVOID_WARNING;
- switch (colorMode) {
- case kAllOnes_ColorMode:
- color = GrColorPackRGBA(0xFF, 0xFF, 0xFF, 0xFF);
- break;
- case kAllZeros_ColorMode:
- color = GrColorPackRGBA(0, 0, 0, 0);
- break;
- case kAlphaOne_ColorMode:
- color = GrColorPackRGBA(random->nextULessThan(256),
- random->nextULessThan(256),
- random->nextULessThan(256),
- 0xFF);
- break;
- case kRandom_ColorMode: {
- uint8_t alpha = random->nextULessThan(256);
- color = GrColorPackRGBA(random->nextRangeU(0, alpha),
- random->nextRangeU(0, alpha),
- random->nextRangeU(0, alpha),
- alpha);
- break;
- }
- }
- GrColorIsPMAssert(color);
- return color;
-}
-
-static inline uint8_t GrRandomCoverage(SkRandom* random) {
- enum CoverageMode {
- kZero_CoverageMode,
- kAllOnes_CoverageMode,
- kRandom_CoverageMode,
- kLast_CoverageMode = kRandom_CoverageMode
- };
-
- CoverageMode colorMode = CoverageMode(random->nextULessThan(kLast_CoverageMode + 1));
- uint8_t coverage SK_INIT_TO_AVOID_WARNING;
- switch (colorMode) {
- case kZero_CoverageMode:
- coverage = 0;
- break;
- case kAllOnes_CoverageMode:
- coverage = 0xff;
- break;
- case kRandom_CoverageMode:
- coverage = random->nextULessThan(256);
- break;
- }
- return coverage;
-}
-
-#endif
-#endif