1 /* 2 * Copyright 2016 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 8 #ifndef GrBufferAccess_DEFINED 9 #define GrBufferAccess_DEFINED 10 11 #include "GrBuffer.h" 12 #include "GrGpuResourceRef.h" 13 14 /** 15 * Used to represent a texel buffer that will be read in a GrProcessor. It holds a GrBuffer along 16 * with an associated offset and texel config. 17 */ 18 class GrBufferAccess : public SkNoncopyable { 19 public: 20 /** 21 * Must be initialized before adding to a GrProcessor's buffer access list. 22 */ 23 void reset(GrPixelConfig texelConfig, GrBuffer* buffer, 24 GrShaderFlags visibility = kFragment_GrShaderFlag) { 25 fTexelConfig = texelConfig; 26 fBuffer.set(SkRef(buffer), kRead_GrIOType); 27 fVisibility = visibility; 28 } 29 30 bool operator==(const GrBufferAccess& that) const { 31 return fTexelConfig == that.fTexelConfig && 32 this->buffer() == that.buffer() && 33 fVisibility == that.fVisibility; 34 } 35 36 bool operator!=(const GrBufferAccess& that) const { return !(*this == that); } 37 texelConfig()38 GrPixelConfig texelConfig() const { return fTexelConfig; } buffer()39 GrBuffer* buffer() const { return fBuffer.get(); } visibility()40 GrShaderFlags visibility() const { return fVisibility; } 41 42 /** 43 * For internal use by GrProcessor. 44 */ getProgramBuffer()45 const GrGpuResourceRef* getProgramBuffer() const { return &fBuffer;} 46 47 private: 48 GrPixelConfig fTexelConfig; 49 GrTGpuResourceRef<GrBuffer> fBuffer; 50 GrShaderFlags fVisibility; 51 52 typedef SkNoncopyable INHERITED; 53 }; 54 55 #endif 56