OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
kaanb
2013/07/24 03:31:23
I think joth@ already pointed this out. I think if
reveman
2013/07/24 05:47:12
I used "git mv" but the changes are too great for
| |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "android_webview/browser/gpu_memory_buffer_factory_impl.h" | |
6 | |
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" | |
12 | |
13 namespace android_webview { | |
14 | |
15 namespace { | |
16 | |
17 // Provides hardware rendering functions from the Android glue layer. | |
18 AwDrawGLFunctionTable* g_gl_draw_functions = NULL; | |
19 | |
20 class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { | |
21 public: | |
22 GpuMemoryBufferImpl(int buffer_id, gfx::Size size) | |
23 : buffer_id_(buffer_id), | |
24 size_(size), | |
25 mapped_(false) { | |
26 DCHECK(buffer_id_); | |
27 } | |
28 | |
29 virtual ~GpuMemoryBufferImpl() { | |
30 g_gl_draw_functions->release_graphic_buffer(buffer_id_); | |
31 } | |
32 | |
33 // Overridden from gfx::GpuMemoryBuffer: | |
34 virtual void Map(gfx::GpuMemoryBuffer::AccessMode mode, | |
35 void** vaddr) OVERRIDE { | |
36 AwMapMode map_mode = MAP_READ_ONLY; | |
37 switch (mode) { | |
38 case GpuMemoryBuffer::READ_ONLY: | |
39 map_mode = MAP_READ_ONLY; | |
40 break; | |
41 case GpuMemoryBuffer::WRITE_ONLY: | |
42 map_mode = MAP_WRITE_ONLY; | |
43 break; | |
44 case GpuMemoryBuffer::READ_WRITE: | |
45 map_mode = MAP_READ_WRITE; | |
46 break; | |
47 default: | |
48 LOG(DFATAL) << "Unknown map mode: " << mode; | |
49 } | |
50 int err = g_gl_draw_functions->map(buffer_id_, map_mode, vaddr); | |
51 DCHECK(!err); | |
52 mapped_ = true; | |
53 } | |
54 virtual void Unmap() OVERRIDE { | |
55 int err = g_gl_draw_functions->unmap(buffer_id_); | |
56 DCHECK(!err); | |
57 mapped_ = false; | |
58 } | |
59 virtual bool IsMapped() const OVERRIDE { return mapped_; } | |
60 virtual uint32 GetStride() const OVERRIDE { | |
61 return g_gl_draw_functions->get_stride(buffer_id_); | |
62 } | |
63 virtual gfx::GpuMemoryBufferHandle GetHandle() const OVERRIDE { | |
64 gfx::GpuMemoryBufferHandle handle; | |
65 handle.type = gfx::EGL_CLIENT_BUFFER; | |
66 handle.native_buffer = g_gl_draw_functions->get_native_buffer(buffer_id_); | |
67 return handle; | |
68 } | |
69 | |
70 private: | |
71 int buffer_id_; | |
72 gfx::Size size_; | |
73 bool mapped_; | |
74 | |
75 DISALLOW_COPY_AND_ASSIGN(GpuMemoryBufferImpl); | |
76 }; | |
77 | |
78 } // namespace | |
79 | |
80 GpuMemoryBufferFactoryImpl::GpuMemoryBufferFactoryImpl() { | |
81 } | |
82 | |
83 GpuMemoryBufferFactoryImpl::~GpuMemoryBufferFactoryImpl() { | |
84 } | |
85 | |
86 gfx::GpuMemoryBuffer* GpuMemoryBufferFactoryImpl::CreateGpuMemoryBuffer( | |
87 size_t width, | |
88 size_t height, | |
89 unsigned internalformat) { | |
90 // For Android WebView we assume the |internalformat| will always be | |
91 // GL_RGBA8_OES. | |
92 DCHECK_EQ(static_cast<GLenum>(GL_RGBA8_OES), internalformat); | |
93 if (internalformat != static_cast<unsigned>(GL_RGBA8_OES)) | |
94 return NULL; | |
95 | |
96 CHECK(g_gl_draw_functions); | |
97 int buffer_id = g_gl_draw_functions->create_graphic_buffer(width, height); | |
98 if (!buffer_id) | |
99 return NULL; | |
100 | |
101 return new GpuMemoryBufferImpl(buffer_id, gfx::Size(width, height)); | |
102 } | |
103 | |
104 // static | |
105 void GpuMemoryBufferFactoryImpl::SetAwDrawGLFunctionTable( | |
106 AwDrawGLFunctionTable* table) { | |
107 g_gl_draw_functions = table; | |
108 } | |
109 | |
110 } // namespace android_webview | |
OLD | NEW |