This source file includes following definitions.
- mapped_
- Map
- Unmap
- IsMapped
- GetStride
- GetHandle
- CreateGpuMemoryBuffer
- SetAwDrawGLFunctionTable
#include "android_webview/browser/gpu_memory_buffer_factory_impl.h"
#include "android_webview/public/browser/draw_gl.h"
#include "base/logging.h"
#include "ui/gfx/gpu_memory_buffer.h"
#include "ui/gfx/size.h"
#include "ui/gl/gl_bindings.h"
namespace android_webview {
namespace {
AwDrawGLFunctionTable* g_gl_draw_functions = NULL;
class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer {
public:
GpuMemoryBufferImpl(long buffer_id, gfx::Size size)
: buffer_id_(buffer_id),
size_(size),
mapped_(false) {
DCHECK(buffer_id_);
}
virtual ~GpuMemoryBufferImpl() {
g_gl_draw_functions->release_graphic_buffer(buffer_id_);
}
virtual void* Map(gfx::GpuMemoryBuffer::AccessMode mode) OVERRIDE {
AwMapMode map_mode = MAP_READ_ONLY;
switch (mode) {
case GpuMemoryBuffer::READ_ONLY:
map_mode = MAP_READ_ONLY;
break;
case GpuMemoryBuffer::WRITE_ONLY:
map_mode = MAP_WRITE_ONLY;
break;
case GpuMemoryBuffer::READ_WRITE:
map_mode = MAP_READ_WRITE;
break;
default:
LOG(DFATAL) << "Unknown map mode: " << mode;
}
void* vaddr = NULL;
int err = g_gl_draw_functions->map(buffer_id_, map_mode, &vaddr);
DCHECK(!err);
mapped_ = true;
return vaddr;
}
virtual void Unmap() OVERRIDE {
int err = g_gl_draw_functions->unmap(buffer_id_);
DCHECK(!err);
mapped_ = false;
}
virtual bool IsMapped() const OVERRIDE { return mapped_; }
virtual uint32 GetStride() const OVERRIDE {
return g_gl_draw_functions->get_stride(buffer_id_);
}
virtual gfx::GpuMemoryBufferHandle GetHandle() const OVERRIDE {
gfx::GpuMemoryBufferHandle handle;
handle.type = gfx::ANDROID_NATIVE_BUFFER;
handle.native_buffer = g_gl_draw_functions->get_native_buffer(buffer_id_);
return handle;
}
private:
long buffer_id_;
gfx::Size size_;
bool mapped_;
DISALLOW_COPY_AND_ASSIGN(GpuMemoryBufferImpl);
};
}
GpuMemoryBufferFactoryImpl::GpuMemoryBufferFactoryImpl() {
}
GpuMemoryBufferFactoryImpl::~GpuMemoryBufferFactoryImpl() {
}
gfx::GpuMemoryBuffer* GpuMemoryBufferFactoryImpl::CreateGpuMemoryBuffer(
size_t width,
size_t height,
unsigned internalformat) {
CHECK_EQ(static_cast<GLenum>(GL_RGBA8_OES), internalformat);
CHECK(g_gl_draw_functions);
long buffer_id = g_gl_draw_functions->create_graphic_buffer(width, height);
if (!buffer_id)
return NULL;
return new GpuMemoryBufferImpl(buffer_id, gfx::Size(width, height));
}
void GpuMemoryBufferFactoryImpl::SetAwDrawGLFunctionTable(
AwDrawGLFunctionTable* table) {
g_gl_draw_functions = table;
}
}