michael@0: /* michael@0: * Copyright 2013 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #ifndef GrGLBufferImpl_DEFINED michael@0: #define GrGLBufferImpl_DEFINED michael@0: michael@0: #include "SkTypes.h" michael@0: #include "gl/GrGLFunctions.h" michael@0: michael@0: class GrGpuGL; michael@0: michael@0: /** michael@0: * This class serves as the implementation of GrGL*Buffer classes. It was written to avoid code michael@0: * duplication in those classes. michael@0: */ michael@0: class GrGLBufferImpl : public SkNoncopyable { michael@0: public: michael@0: struct Desc { michael@0: bool fIsWrapped; michael@0: GrGLuint fID; // set to 0 to indicate buffer is CPU-backed and not a VBO. michael@0: size_t fSizeInBytes; michael@0: bool fDynamic; michael@0: }; michael@0: michael@0: GrGLBufferImpl(GrGpuGL*, const Desc&, GrGLenum bufferType); michael@0: ~GrGLBufferImpl() { michael@0: // either release or abandon should have been called by the owner of this object. michael@0: SkASSERT(0 == fDesc.fID); michael@0: } michael@0: michael@0: void abandon(); michael@0: void release(GrGpuGL* gpu); michael@0: michael@0: GrGLuint bufferID() const { return fDesc.fID; } michael@0: size_t baseOffset() const { return reinterpret_cast(fCPUData); } michael@0: michael@0: void bind(GrGpuGL* gpu) const; michael@0: michael@0: void* lock(GrGpuGL* gpu); michael@0: void* lockPtr() const { return fLockPtr; } michael@0: void unlock(GrGpuGL* gpu); michael@0: bool isLocked() const; michael@0: bool updateData(GrGpuGL* gpu, const void* src, size_t srcSizeInBytes); michael@0: michael@0: private: michael@0: void validate() const; michael@0: michael@0: Desc fDesc; michael@0: GrGLenum fBufferType; // GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER michael@0: void* fCPUData; michael@0: void* fLockPtr; michael@0: michael@0: typedef SkNoncopyable INHERITED; michael@0: }; michael@0: michael@0: #endif