bsalomon@google.com | e49ad45 | 2013-02-20 19:33:20 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 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 GrGLBufferImpl_DEFINED |
| 9 | #define GrGLBufferImpl_DEFINED |
| 10 | |
| 11 | #include "GrNoncopyable.h" |
| 12 | #include "gl/GrGLFunctions.h" |
| 13 | |
| 14 | class GrGpuGL; |
| 15 | |
| 16 | /** |
| 17 | * This class serves as the implementation of GrGL*Buffer classes. It was written to avoid code |
| 18 | * duplication in those classes. |
| 19 | */ |
| 20 | class GrGLBufferImpl : public GrNoncopyable { |
| 21 | public: |
| 22 | struct Desc { |
| 23 | bool fIsWrapped; |
bsalomon@google.com | ee3bc3b | 2013-02-21 14:33:46 +0000 | [diff] [blame] | 24 | GrGLuint fID; // set to 0 to indicate buffer is CPU-backed and not a VBO. |
bsalomon@google.com | e49ad45 | 2013-02-20 19:33:20 +0000 | [diff] [blame] | 25 | size_t fSizeInBytes; |
| 26 | bool fDynamic; |
| 27 | }; |
| 28 | |
| 29 | GrGLBufferImpl(GrGpuGL*, const Desc&, GrGLenum bufferType); |
| 30 | ~GrGLBufferImpl() { |
| 31 | // either release or abandon should have been called by the owner of this object. |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame^] | 32 | SkASSERT(0 == fDesc.fID); |
bsalomon@google.com | e49ad45 | 2013-02-20 19:33:20 +0000 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | void abandon(); |
| 36 | void release(GrGpuGL* gpu); |
| 37 | |
| 38 | GrGLuint bufferID() const { return fDesc.fID; } |
bsalomon@google.com | ee3bc3b | 2013-02-21 14:33:46 +0000 | [diff] [blame] | 39 | size_t baseOffset() const { return reinterpret_cast<size_t>(fCPUData); } |
bsalomon@google.com | e49ad45 | 2013-02-20 19:33:20 +0000 | [diff] [blame] | 40 | |
| 41 | void bind(GrGpuGL* gpu) const; |
| 42 | |
| 43 | void* lock(GrGpuGL* gpu); |
| 44 | void* lockPtr() const { return fLockPtr; } |
| 45 | void unlock(GrGpuGL* gpu); |
| 46 | bool isLocked() const; |
| 47 | bool updateData(GrGpuGL* gpu, const void* src, size_t srcSizeInBytes); |
| 48 | |
| 49 | private: |
bsalomon@google.com | ee3bc3b | 2013-02-21 14:33:46 +0000 | [diff] [blame] | 50 | void validate() const; |
| 51 | |
bsalomon@google.com | e49ad45 | 2013-02-20 19:33:20 +0000 | [diff] [blame] | 52 | Desc fDesc; |
| 53 | GrGLenum fBufferType; // GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER |
bsalomon@google.com | ee3bc3b | 2013-02-21 14:33:46 +0000 | [diff] [blame] | 54 | void* fCPUData; |
bsalomon@google.com | e49ad45 | 2013-02-20 19:33:20 +0000 | [diff] [blame] | 55 | void* fLockPtr; |
| 56 | |
| 57 | typedef GrNoncopyable INHERITED; |
| 58 | }; |
| 59 | |
| 60 | #endif |