Disable flaky EndToEndTest.LargePostSmallBandwidthLargeBuffer
[chromium-blink-merge.git] / android_webview / browser / gpu_memory_buffer_factory_impl.cc
blob8be58c5cdc08aee26eb043dc785d8eda35bafb55
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "android_webview/browser/gpu_memory_buffer_factory_impl.h"
7 #include "android_webview/public/browser/draw_gl.h"
8 #include "base/logging.h"
9 #include "ui/gfx/gpu_memory_buffer.h"
10 #include "ui/gfx/size.h"
11 #include "ui/gl/gl_bindings.h"
13 namespace android_webview {
15 namespace {
17 // Provides hardware rendering functions from the Android glue layer.
18 AwDrawGLFunctionTable* g_gl_draw_functions = NULL;
20 class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer {
21 public:
22 GpuMemoryBufferImpl(long buffer_id, gfx::Size size)
23 : buffer_id_(buffer_id),
24 size_(size),
25 mapped_(false) {
26 DCHECK(buffer_id_);
29 virtual ~GpuMemoryBufferImpl() {
30 g_gl_draw_functions->release_graphic_buffer(buffer_id_);
33 // Overridden from gfx::GpuMemoryBuffer:
34 virtual void* Map() OVERRIDE {
35 void* vaddr = NULL;
36 int err = g_gl_draw_functions->map(buffer_id_, MAP_READ_WRITE, &vaddr);
37 DCHECK(!err);
38 mapped_ = true;
39 return vaddr;
41 virtual void Unmap() OVERRIDE {
42 int err = g_gl_draw_functions->unmap(buffer_id_);
43 DCHECK(!err);
44 mapped_ = false;
46 virtual bool IsMapped() const OVERRIDE { return mapped_; }
47 virtual uint32 GetStride() const OVERRIDE {
48 return g_gl_draw_functions->get_stride(buffer_id_);
50 virtual gfx::GpuMemoryBufferHandle GetHandle() const OVERRIDE {
51 gfx::GpuMemoryBufferHandle handle;
52 handle.type = gfx::ANDROID_NATIVE_BUFFER;
53 handle.native_buffer = g_gl_draw_functions->get_native_buffer(buffer_id_);
54 return handle;
57 private:
58 long buffer_id_;
59 gfx::Size size_;
60 bool mapped_;
62 DISALLOW_COPY_AND_ASSIGN(GpuMemoryBufferImpl);
65 } // namespace
67 GpuMemoryBufferFactoryImpl::GpuMemoryBufferFactoryImpl() {
70 GpuMemoryBufferFactoryImpl::~GpuMemoryBufferFactoryImpl() {
73 gfx::GpuMemoryBuffer* GpuMemoryBufferFactoryImpl::CreateGpuMemoryBuffer(
74 size_t width,
75 size_t height,
76 unsigned internalformat,
77 unsigned usage) {
78 // For Android WebView we assume the |internalformat| will always be
79 // GL_RGBA8_OES.
80 CHECK_EQ(static_cast<GLenum>(GL_RGBA8_OES), internalformat);
81 CHECK(g_gl_draw_functions);
82 long buffer_id = g_gl_draw_functions->create_graphic_buffer(width, height);
83 if (!buffer_id)
84 return NULL;
86 return new GpuMemoryBufferImpl(buffer_id, gfx::Size(width, height));
89 // static
90 void GpuMemoryBufferFactoryImpl::SetAwDrawGLFunctionTable(
91 AwDrawGLFunctionTable* table) {
92 g_gl_draw_functions = table;
95 } // namespace android_webview