Make GrBufferAccess a nested class of GrProcessor

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4978

Change-Id: I08c24e9183108f4dd6068216488fd3ac9b5f3ec2
Reviewed-on: https://skia-review.googlesource.com/4978
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/gn/gpu.gni b/gn/gpu.gni
index 5a7e75c..21206f6 100644
--- a/gn/gpu.gni
+++ b/gn/gpu.gni
@@ -10,7 +10,6 @@
 skia_gpu_sources = [
   "$_include/gpu/GrBlend.h",
   "$_include/gpu/GrBuffer.h",
-  "$_include/gpu/GrBufferAccess.h",
   "$_include/gpu/GrCaps.h",
   "$_include/gpu/GrClip.h",
   "$_include/gpu/GrColor.h",
diff --git a/include/gpu/GrBufferAccess.h b/include/gpu/GrBufferAccess.h
deleted file mode 100644
index a5d8f0a..0000000
--- a/include/gpu/GrBufferAccess.h
+++ /dev/null
@@ -1,55 +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 GrBufferAccess_DEFINED
-#define GrBufferAccess_DEFINED
-
-#include "GrBuffer.h"
-#include "GrGpuResourceRef.h"
-
-/**
- * Used to represent a texel buffer that will be read in a GrProcessor. It holds a GrBuffer along
- * with an associated offset and texel config.
- */
-class GrBufferAccess : public SkNoncopyable {
-public:
-    /**
-     * 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 GrBufferAccess& that) const {
-        return fTexelConfig == that.fTexelConfig &&
-               this->buffer() == that.buffer() &&
-               fVisibility == that.fVisibility;
-    }
-
-    bool operator!=(const GrBufferAccess& 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* getProgramBuffer() const { return &fBuffer;}
-
-private:
-    GrPixelConfig                 fTexelConfig;
-    GrTGpuResourceRef<GrBuffer>   fBuffer;
-    GrShaderFlags                 fVisibility;
-
-    typedef SkNoncopyable INHERITED;
-};
-
-#endif
diff --git a/include/gpu/GrProcessor.h b/include/gpu/GrProcessor.h
index f5f3842..e4f59ea 100644
--- a/include/gpu/GrProcessor.h
+++ b/include/gpu/GrProcessor.h
@@ -9,9 +9,11 @@
 #define GrProcessor_DEFINED
 
 #include "GrColor.h"
+#include "GrBuffer.h"
+#include "GrGpuResourceRef.h"
 #include "GrProcessorUnitTest.h"
 #include "GrProgramElement.h"
-#include "GrBufferAccess.h"
+#include "GrSamplerParams.h"
 #include "SkMath.h"
 #include "SkString.h"
 #include "../private/SkAtomics.h"
@@ -59,14 +61,15 @@
 class GrProcessor : public GrProgramElement {
 public:
     class TextureSampler;
+    class BufferAccess;
 
     virtual ~GrProcessor();
 
-    /** Human-meaningful string to identify this prcoessor; may be embedded
-        in generated shader code. */
+    /** 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 
+    /** Human-readable dump of all information */
     virtual SkString dumpInfo() const {
         SkString str;
         str.appendf("Missing data");
@@ -83,13 +86,9 @@
 
     /** Returns the access pattern for the buffer at index. index must be valid according to
         numBuffers(). */
-    const GrBufferAccess& bufferAccess(int index) const {
-        return *fBufferAccesses[index];
-    }
+    const BufferAccess& bufferAccess(int index) const { return *fBufferAccesses[index]; }
 
-    /**
-     * Platform specific built-in features that a processor can request for the fragment shader.
-     */
+    /** Platform specific built-in features that a processor can request for the fragment shader. */
     enum RequiredFeatures {
         kNone_RequiredFeatures             = 0,
         kFragmentPosition_RequiredFeature  = 1 << 0,
@@ -110,9 +109,7 @@
         ::operator delete(target, placement);
     }
 
-    /**
-      * Helper for down-casting to a GrProcessor subclass
-      */
+    /** 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; }
@@ -123,12 +120,11 @@
     /**
      * 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 and/or GrBufferAccess instances are typically member fields of the
-     * GrProcessor subclass. These must only be called from the constructor because GrProcessors
-     * are immutable.
+     * 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 GrBufferAccess* bufferAccess);
+    void addBufferAccess(const BufferAccess* bufferAccess);
 
     bool hasSameSamplers(const GrProcessor&) const;
 
@@ -170,7 +166,7 @@
 
     RequiredFeatures fRequiredFeatures;
     SkSTArray<4, const TextureSampler*, true>   fTextureSamplers;
-    SkSTArray<2, const GrBufferAccess*, true>   fBufferAccesses;
+    SkSTArray<2, const BufferAccess*, true>     fBufferAccesses;
 
     typedef GrProgramElement INHERITED;
 };
@@ -230,4 +226,45 @@
     typedef SkNoncopyable INHERITED;
 };
 
+/**
+ * Used to represent a texel buffer that will be read in a GrProcessor. It holds a GrBuffer along
+ * with an associated offset and texel config.
+ */
+class GrProcessor::BufferAccess : public SkNoncopyable {
+public:
+    /**
+     * 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* getProgramBuffer() const { return &fBuffer;}
+
+private:
+    GrPixelConfig                 fTexelConfig;
+    GrTGpuResourceRef<GrBuffer>   fBuffer;
+    GrShaderFlags                 fVisibility;
+
+    typedef SkNoncopyable INHERITED;
+};
+
 #endif
diff --git a/src/gpu/GrProcessor.cpp b/src/gpu/GrProcessor.cpp
index 89fc741..1e100e4 100644
--- a/src/gpu/GrProcessor.cpp
+++ b/src/gpu/GrProcessor.cpp
@@ -120,7 +120,7 @@
     this->addGpuResource(access->programTexture());
 }
 
-void GrProcessor::addBufferAccess(const GrBufferAccess* access) {
+void GrProcessor::addBufferAccess(const BufferAccess* access) {
     fBufferAccesses.push_back(access);
     this->addGpuResource(access->getProgramBuffer());
 }
diff --git a/src/gpu/GrProgramDesc.cpp b/src/gpu/GrProgramDesc.cpp
index 0976af9..cdbbc23 100644
--- a/src/gpu/GrProgramDesc.cpp
+++ b/src/gpu/GrProgramDesc.cpp
@@ -50,7 +50,7 @@
                              textureSampler.visibility(), caps);
     }
     for (; i < numSamplers; ++i) {
-        const GrBufferAccess& access = proc.bufferAccess(i - numTextureSamplers);
+        const GrProcessor::BufferAccess& access = proc.bufferAccess(i - numTextureSamplers);
         k16[i] = sampler_key(kBufferSampler_GrSLType, access.texelConfig(),
                              access.visibility(), caps);
     }
diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp
index 50cbdc1..27361e7 100644
--- a/src/gpu/gl/GrGLProgram.cpp
+++ b/src/gpu/gl/GrGLProgram.cpp
@@ -158,7 +158,7 @@
                           allowSRGBInputs, static_cast<GrGLTexture*>(sampler.texture()));
     }
     for (int i = 0; i < processor.numBuffers(); ++i) {
-        const GrBufferAccess& access = processor.bufferAccess(i);
+        const GrProcessor::BufferAccess& access = processor.bufferAccess(i);
         fGpu->bindTexelBuffer((*nextSamplerIdx)++, access.texelConfig(),
                               static_cast<GrGLBuffer*>(access.buffer()));
     }
diff --git a/src/gpu/glsl/GrGLSLFragmentProcessor.h b/src/gpu/glsl/GrGLSLFragmentProcessor.h
index 7add1eb..2189250 100644
--- a/src/gpu/glsl/GrGLSLFragmentProcessor.h
+++ b/src/gpu/glsl/GrGLSLFragmentProcessor.h
@@ -97,9 +97,9 @@
         @param texSamplers       Contains one entry for each TextureSampler  of the GrProcessor.
                                  These can be passed to the builder to emit texture reads in the
                                  generated code.
-        @param bufferSamplers    Contains one entry for each GrBufferAccess of the GrProcessor.
-                                 These can be passed to the builder to emit buffer reads in the
-                                 generated code.
+        @param bufferSamplers    Contains one entry for each BufferAccess of the GrProcessor. These
+                                 can be passed to the builder to emit buffer reads in the generated
+                                 code.
      */
     struct EmitArgs {
         EmitArgs(GrGLSLFPFragmentBuilder* fragBuilder,
diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.cpp b/src/gpu/glsl/GrGLSLProgramBuilder.cpp
index c4c3e68..1e78788 100644
--- a/src/gpu/glsl/GrGLSLProgramBuilder.cpp
+++ b/src/gpu/glsl/GrGLSLProgramBuilder.cpp
@@ -264,7 +264,7 @@
         GrShaderFlags texelBufferVisibility = kNone_GrShaderFlags;
 
         for (int b = 0; b < numBuffers; ++b) {
-            const GrBufferAccess& access = processor.bufferAccess(b);
+            const GrProcessor::BufferAccess& access = processor.bufferAccess(b);
             name.printf("BufferSampler_%d", outBufferSamplers->count());
             this->emitSampler(kBufferSampler_GrSLType, access.texelConfig(), name.c_str(),
                               access.visibility(), outBufferSamplers);
diff --git a/src/gpu/instanced/InstanceProcessor.h b/src/gpu/instanced/InstanceProcessor.h
index 0b3a16d..d54ffcd 100644
--- a/src/gpu/instanced/InstanceProcessor.h
+++ b/src/gpu/instanced/InstanceProcessor.h
@@ -9,7 +9,6 @@
 #define gr_instanced_InstanceProcessor_DEFINED
 
 #include "GrCaps.h"
-#include "GrBufferAccess.h"
 #include "GrGeometryProcessor.h"
 #include "instanced/InstancedRenderingTypes.h"
 
@@ -57,8 +56,8 @@
      */
     static GrCaps::InstancedSupport CheckSupport(const GrGLSLCaps&, const GrCaps&);
 
-    const BatchInfo   fBatchInfo;
-    GrBufferAccess    fParamsAccess;
+    const BatchInfo fBatchInfo;
+    BufferAccess    fParamsAccess;
 
     friend class GLInstancedRendering; // For CheckSupport.