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 | |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 11 | #include "SkTypes.h" |
bsalomon@google.com | e49ad45 | 2013-02-20 19:33:20 +0000 | [diff] [blame] | 12 | #include "gl/GrGLFunctions.h" |
| 13 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 14 | class GrGLGpu; |
bsalomon@google.com | e49ad45 | 2013-02-20 19:33:20 +0000 | [diff] [blame] | 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 | */ |
commit-bot@chromium.org | e3beb6b | 2014-04-07 19:34:38 +0000 | [diff] [blame] | 20 | class GrGLBufferImpl : SkNoncopyable { |
bsalomon@google.com | e49ad45 | 2013-02-20 19:33:20 +0000 | [diff] [blame] | 21 | public: |
| 22 | struct Desc { |
bsalomon@google.com | ee3bc3b | 2013-02-21 14:33:46 +0000 | [diff] [blame] | 23 | 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] | 24 | size_t fSizeInBytes; |
| 25 | bool fDynamic; |
| 26 | }; |
| 27 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 28 | GrGLBufferImpl(GrGLGpu*, const Desc&, GrGLenum bufferType); |
bsalomon@google.com | e49ad45 | 2013-02-20 19:33:20 +0000 | [diff] [blame] | 29 | ~GrGLBufferImpl() { |
| 30 | // 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] | 31 | SkASSERT(0 == fDesc.fID); |
bsalomon@google.com | e49ad45 | 2013-02-20 19:33:20 +0000 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | void abandon(); |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 35 | void release(GrGLGpu* gpu); |
bsalomon@google.com | e49ad45 | 2013-02-20 19:33:20 +0000 | [diff] [blame] | 36 | |
| 37 | GrGLuint bufferID() const { return fDesc.fID; } |
bsalomon@google.com | ee3bc3b | 2013-02-21 14:33:46 +0000 | [diff] [blame] | 38 | size_t baseOffset() const { return reinterpret_cast<size_t>(fCPUData); } |
bsalomon@google.com | e49ad45 | 2013-02-20 19:33:20 +0000 | [diff] [blame] | 39 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 40 | void bind(GrGLGpu* gpu) const; |
bsalomon@google.com | e49ad45 | 2013-02-20 19:33:20 +0000 | [diff] [blame] | 41 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 42 | void* map(GrGLGpu* gpu); |
| 43 | void unmap(GrGLGpu* gpu); |
commit-bot@chromium.org | 8341eb7 | 2014-05-07 20:51:05 +0000 | [diff] [blame] | 44 | bool isMapped() const; |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 45 | bool updateData(GrGLGpu* gpu, const void* src, size_t srcSizeInBytes); |
bsalomon@google.com | e49ad45 | 2013-02-20 19:33:20 +0000 | [diff] [blame] | 46 | |
| 47 | private: |
bsalomon@google.com | ee3bc3b | 2013-02-21 14:33:46 +0000 | [diff] [blame] | 48 | void validate() const; |
| 49 | |
bsalomon@google.com | e49ad45 | 2013-02-20 19:33:20 +0000 | [diff] [blame] | 50 | Desc fDesc; |
| 51 | GrGLenum fBufferType; // GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER |
bsalomon@google.com | ee3bc3b | 2013-02-21 14:33:46 +0000 | [diff] [blame] | 52 | void* fCPUData; |
commit-bot@chromium.org | 8341eb7 | 2014-05-07 20:51:05 +0000 | [diff] [blame] | 53 | void* fMapPtr; |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 54 | size_t fGLSizeInBytes; // In certain cases we make the size of the GL buffer object |
| 55 | // smaller or larger than the size in fDesc. |
bsalomon@google.com | e49ad45 | 2013-02-20 19:33:20 +0000 | [diff] [blame] | 56 | |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 57 | typedef SkNoncopyable INHERITED; |
bsalomon@google.com | e49ad45 | 2013-02-20 19:33:20 +0000 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | #endif |