store map ptr in GrGeometryBuffer base class

R=robertphillips@google.com

Author: bsalomon@google.com

Review URL: https://codereview.chromium.org/272503009

git-svn-id: http://skia.googlecode.com/svn/trunk@14652 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
commit-bot@chromium.org 2014-05-08 18:13:23 +00:00
parent 54f98fc215
commit e529a61dd4
6 changed files with 49 additions and 53 deletions

View File

@ -45,42 +45,58 @@ public:
* Currently only one map at a time is supported (no nesting of
* map/unmap).
*
* Note that buffer mapping does not go through GrContext and therefore is
* not serialized with other operations.
*
* @return a pointer to the data or NULL if the map fails.
*/
virtual void* map() = 0;
/**
* Returns the same ptr that map() returned at time of map or NULL if the
* is not mapped.
*
* @return ptr to mapped buffer data or undefined if buffer is not mapped.
*/
virtual void* mapPtr() const = 0;
void* map() { return (fMapPtr = this->onMap()); }
/**
* Unmaps the buffer.
*
* The pointer returned by the previous map call will no longer be valid.
*/
virtual void unmap() = 0;
void unmap() {
SkASSERT(NULL != fMapPtr);
this->onUnmap();
fMapPtr = NULL;
}
/**
* Returns the same ptr that map() returned at time of map or NULL if the
* is not mapped.
*
* @return ptr to mapped buffer data or NULL if buffer is not mapped.
*/
void* mapPtr() const { return fMapPtr; }
/**
Queries whether the buffer has been mapped.
@return true if the buffer is mapped, false otherwise.
*/
virtual bool isMapped() const = 0;
bool isMapped() const { return NULL != fMapPtr; }
/**
* Updates the buffer data.
*
* The size of the buffer will be preserved. The src data will be
* placed at the beginning of the buffer and any remaining contents will
* be undefined.
* be undefined. srcSizeInBytes must be <= to the buffer size.
*
* The buffer must not be mapped.
*
* Note that buffer updates do not go through GrContext and therefore are
* not serialized with other operations.
*
* @return returns true if the update succeeds, false otherwise.
*/
virtual bool updateData(const void* src, size_t srcSizeInBytes) = 0;
bool updateData(const void* src, size_t srcSizeInBytes) {
SkASSERT(!this->isMapped());
SkASSERT(srcSizeInBytes <= fGpuMemorySize);
return this->onUpdateData(src, srcSizeInBytes);
}
// GrGpuObject overrides
virtual size_t gpuMemorySize() const { return fGpuMemorySize; }
@ -88,11 +104,17 @@ public:
protected:
GrGeometryBuffer(GrGpu* gpu, bool isWrapped, size_t gpuMemorySize, bool dynamic, bool cpuBacked)
: INHERITED(gpu, isWrapped)
, fMapPtr(NULL)
, fGpuMemorySize(gpuMemorySize)
, fDynamic(dynamic)
, fCPUBacked(cpuBacked) {}
private:
virtual void* onMap() = 0;
virtual void onUnmap() = 0;
virtual bool onUpdateData(const void* src, size_t srcSizeInBytes) = 0;
void* fMapPtr;
size_t fGpuMemorySize;
bool fDynamic;
bool fCPUBacked;

View File

@ -41,7 +41,6 @@ public:
void bind(GrGpuGL* gpu) const;
void* map(GrGpuGL* gpu);
void* mapPtr() const { return fMapPtr; }
void unmap(GrGpuGL* gpu);
bool isMapped() const;
bool updateData(GrGpuGL* gpu, const void* src, size_t srcSizeInBytes);

View File

@ -26,7 +26,7 @@ void GrGLIndexBuffer::onAbandon() {
INHERITED::onAbandon();
}
void* GrGLIndexBuffer::map() {
void* GrGLIndexBuffer::onMap() {
if (!this->wasDestroyed()) {
return fImpl.map(this->getGpuGL());
} else {
@ -34,21 +34,13 @@ void* GrGLIndexBuffer::map() {
}
}
void* GrGLIndexBuffer::mapPtr() const {
return fImpl.mapPtr();
}
void GrGLIndexBuffer::unmap() {
void GrGLIndexBuffer::onUnmap() {
if (!this->wasDestroyed()) {
fImpl.unmap(this->getGpuGL());
}
}
bool GrGLIndexBuffer::isMapped() const {
return fImpl.isMapped();
}
bool GrGLIndexBuffer::updateData(const void* src, size_t srcSizeInBytes) {
bool GrGLIndexBuffer::onUpdateData(const void* src, size_t srcSizeInBytes) {
if (!this->wasDestroyed()) {
return fImpl.updateData(this->getGpuGL(), src, srcSizeInBytes);
} else {

View File

@ -31,19 +31,15 @@ public:
}
}
// overrides of GrIndexBuffer
virtual void* map() SK_OVERRIDE;
virtual void* mapPtr() const SK_OVERRIDE;
virtual void unmap() SK_OVERRIDE;
virtual bool isMapped() const SK_OVERRIDE;
virtual bool updateData(const void* src, size_t srcSizeInBytes);
protected:
// overrides of GrResource
virtual void onAbandon() SK_OVERRIDE;
virtual void onRelease() SK_OVERRIDE;
private:
virtual void* onMap() SK_OVERRIDE;
virtual void onUnmap() SK_OVERRIDE;
virtual bool onUpdateData(const void* src, size_t srcSizeInBytes) SK_OVERRIDE;
GrGpuGL* getGpuGL() const {
SkASSERT(!this->wasDestroyed());
return (GrGpuGL*)(this->getGpu());

View File

@ -21,13 +21,12 @@ void GrGLVertexBuffer::onRelease() {
INHERITED::onRelease();
}
void GrGLVertexBuffer::onAbandon() {
fImpl.abandon();
INHERITED::onAbandon();
}
void* GrGLVertexBuffer::map() {
void* GrGLVertexBuffer::onMap() {
if (!this->wasDestroyed()) {
return fImpl.map(this->getGpuGL());
} else {
@ -35,21 +34,13 @@ void* GrGLVertexBuffer::map() {
}
}
void* GrGLVertexBuffer::mapPtr() const {
return fImpl.mapPtr();
}
void GrGLVertexBuffer::unmap() {
void GrGLVertexBuffer::onUnmap() {
if (!this->wasDestroyed()) {
fImpl.unmap(this->getGpuGL());
}
}
bool GrGLVertexBuffer::isMapped() const {
return fImpl.isMapped();
}
bool GrGLVertexBuffer::updateData(const void* src, size_t srcSizeInBytes) {
bool GrGLVertexBuffer::onUpdateData(const void* src, size_t srcSizeInBytes) {
if (!this->wasDestroyed()) {
return fImpl.updateData(this->getGpuGL(), src, srcSizeInBytes);
} else {

View File

@ -31,19 +31,15 @@ public:
}
}
// overrides of GrVertexBuffer
virtual void* map() SK_OVERRIDE;
virtual void* mapPtr() const SK_OVERRIDE;
virtual void unmap() SK_OVERRIDE;
virtual bool isMapped() const SK_OVERRIDE;
virtual bool updateData(const void* src, size_t srcSizeInBytes);
protected:
// overrides of GrResource
virtual void onAbandon() SK_OVERRIDE;
virtual void onRelease() SK_OVERRIDE;
private:
virtual void* onMap() SK_OVERRIDE;
virtual void onUnmap() SK_OVERRIDE;
virtual bool onUpdateData(const void* src, size_t srcSizeInBytes) SK_OVERRIDE;
GrGpuGL* getGpuGL() const {
SkASSERT(!this->wasDestroyed());
return (GrGpuGL*)(this->getGpu());