gfx/skia/trunk/src/gpu/gl/GrGLBufferImpl.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/gpu/gl/GrGLBufferImpl.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,60 @@
     1.4 +/*
     1.5 + * Copyright 2013 Google Inc.
     1.6 + *
     1.7 + * Use of this source code is governed by a BSD-style license that can be
     1.8 + * found in the LICENSE file.
     1.9 + */
    1.10 +
    1.11 +#ifndef GrGLBufferImpl_DEFINED
    1.12 +#define GrGLBufferImpl_DEFINED
    1.13 +
    1.14 +#include "SkTypes.h"
    1.15 +#include "gl/GrGLFunctions.h"
    1.16 +
    1.17 +class GrGpuGL;
    1.18 +
    1.19 +/**
    1.20 + * This class serves as the implementation of GrGL*Buffer classes. It was written to avoid code
    1.21 + * duplication in those classes.
    1.22 + */
    1.23 +class GrGLBufferImpl : public SkNoncopyable {
    1.24 +public:
    1.25 +    struct Desc {
    1.26 +        bool        fIsWrapped;
    1.27 +        GrGLuint    fID;            // set to 0 to indicate buffer is CPU-backed and not a VBO.
    1.28 +        size_t      fSizeInBytes;
    1.29 +        bool        fDynamic;
    1.30 +    };
    1.31 +
    1.32 +    GrGLBufferImpl(GrGpuGL*, const Desc&, GrGLenum bufferType);
    1.33 +    ~GrGLBufferImpl() {
    1.34 +        // either release or abandon should have been called by the owner of this object.
    1.35 +        SkASSERT(0 == fDesc.fID);
    1.36 +    }
    1.37 +
    1.38 +    void abandon();
    1.39 +    void release(GrGpuGL* gpu);
    1.40 +
    1.41 +    GrGLuint bufferID() const { return fDesc.fID; }
    1.42 +    size_t baseOffset() const { return reinterpret_cast<size_t>(fCPUData); }
    1.43 +
    1.44 +    void bind(GrGpuGL* gpu) const;
    1.45 +
    1.46 +    void* lock(GrGpuGL* gpu);
    1.47 +    void* lockPtr() const { return fLockPtr; }
    1.48 +    void unlock(GrGpuGL* gpu);
    1.49 +    bool isLocked() const;
    1.50 +    bool updateData(GrGpuGL* gpu, const void* src, size_t srcSizeInBytes);
    1.51 +
    1.52 +private:
    1.53 +    void validate() const;
    1.54 +
    1.55 +    Desc         fDesc;
    1.56 +    GrGLenum     fBufferType; // GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER
    1.57 +    void*        fCPUData;
    1.58 +    void*        fLockPtr;
    1.59 +
    1.60 +    typedef SkNoncopyable INHERITED;
    1.61 +};
    1.62 +
    1.63 +#endif

mercurial