1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/gpu/GrGeometryBuffer.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,103 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2011 Google Inc. 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license that can be 1.9 + * found in the LICENSE file. 1.10 + */ 1.11 + 1.12 + 1.13 +#ifndef GrGeometryBuffer_DEFINED 1.14 +#define GrGeometryBuffer_DEFINED 1.15 + 1.16 +#include "GrResource.h" 1.17 + 1.18 +class GrGpu; 1.19 + 1.20 +/** 1.21 + * Parent class for vertex and index buffers 1.22 + */ 1.23 +class GrGeometryBuffer : public GrResource { 1.24 +public: 1.25 + SK_DECLARE_INST_COUNT(GrGeometryBuffer); 1.26 + 1.27 + /** 1.28 + *Retrieves whether the buffer was created with the dynamic flag 1.29 + * 1.30 + * @return true if the buffer was created with the dynamic flag 1.31 + */ 1.32 + bool dynamic() const { return fDynamic; } 1.33 + 1.34 + /** 1.35 + * Returns true if the buffer is a wrapper around a CPU array. If true it 1.36 + * indicates that lock will always succeed and will be free. 1.37 + */ 1.38 + bool isCPUBacked() const { return fCPUBacked; } 1.39 + 1.40 + /** 1.41 + * Locks the buffer to be written by the CPU. 1.42 + * 1.43 + * The previous content of the buffer is invalidated. It is an error 1.44 + * to draw from the buffer while it is locked. It is an error to call lock 1.45 + * on an already locked buffer. It may fail if the backend doesn't support 1.46 + * locking the buffer. If the buffer is CPU backed then it will always 1.47 + * succeed and is a free operation. Must be matched by an unlock() call. 1.48 + * Currently only one lock at a time is supported (no nesting of 1.49 + * lock/unlock). 1.50 + * 1.51 + * @return a pointer to the data or NULL if the lock fails. 1.52 + */ 1.53 + virtual void* lock() = 0; 1.54 + 1.55 + /** 1.56 + * Returns the same ptr that lock() returned at time of lock or NULL if the 1.57 + * is not locked. 1.58 + * 1.59 + * @return ptr to locked buffer data or undefined if buffer is not locked. 1.60 + */ 1.61 + virtual void* lockPtr() const = 0; 1.62 + 1.63 + /** 1.64 + * Unlocks the buffer. 1.65 + * 1.66 + * The pointer returned by the previous lock call will no longer be valid. 1.67 + */ 1.68 + virtual void unlock() = 0; 1.69 + 1.70 + /** 1.71 + Queries whether the buffer has been locked. 1.72 + 1.73 + @return true if the buffer is locked, false otherwise. 1.74 + */ 1.75 + virtual bool isLocked() const = 0; 1.76 + 1.77 + /** 1.78 + * Updates the buffer data. 1.79 + * 1.80 + * The size of the buffer will be preserved. The src data will be 1.81 + * placed at the beginning of the buffer and any remaining contents will 1.82 + * be undefined. 1.83 + * 1.84 + * @return returns true if the update succeeds, false otherwise. 1.85 + */ 1.86 + virtual bool updateData(const void* src, size_t srcSizeInBytes) = 0; 1.87 + 1.88 + // GrResource overrides 1.89 + virtual size_t sizeInBytes() const { return fSizeInBytes; } 1.90 + 1.91 +protected: 1.92 + GrGeometryBuffer(GrGpu* gpu, bool isWrapped, size_t sizeInBytes, bool dynamic, bool cpuBacked) 1.93 + : INHERITED(gpu, isWrapped) 1.94 + , fSizeInBytes(sizeInBytes) 1.95 + , fDynamic(dynamic) 1.96 + , fCPUBacked(cpuBacked) {} 1.97 + 1.98 +private: 1.99 + size_t fSizeInBytes; 1.100 + bool fDynamic; 1.101 + bool fCPUBacked; 1.102 + 1.103 + typedef GrResource INHERITED; 1.104 +}; 1.105 + 1.106 +#endif