Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: android_webview/browser/gpu_memory_buffer_impl.cc

Issue 20017005: gpu: Refactor GpuMemoryBuffer framework for multi-process support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "android_webview/browser/gpu_memory_buffer_impl.h"
6
7 #include "android_webview/public/browser/draw_gl.h"
8 #include "base/bind.h"
9 #include "base/logging.h"
10 #include "gpu/command_buffer/client/gl_in_process_context.h"
11 #include "gpu/command_buffer/client/gpu_memory_buffer.h"
12 #include "ui/gfx/size.h"
13
14 namespace android_webview {
15
16 // Provides hardware rendering functions from the Android glue layer.
17 AwDrawGLFunctionTable* g_gl_draw_functions = NULL;
18
19 GpuMemoryBufferImpl::GpuMemoryBufferImpl(gfx::Size size)
20 : buffer_id_(g_gl_draw_functions->create_graphic_buffer(
21 size.width(), size.height())),
22 size_(size),
23 mapped_(false) {
24 }
25
26 GpuMemoryBufferImpl::~GpuMemoryBufferImpl() {
27 g_gl_draw_functions->release_graphic_buffer(buffer_id_);
28 }
29
30 void GpuMemoryBufferImpl::Map(gpu::GpuMemoryBuffer::AccessMode mode,
31 void** vaddr) {
32 DCHECK(buffer_id_ != 0);
33 AwMapMode map_mode = MAP_READ_ONLY;
34 switch (mode) {
35 case GpuMemoryBuffer::READ_ONLY:
36 map_mode = MAP_READ_ONLY;
37 break;
38 case GpuMemoryBuffer::WRITE_ONLY:
39 map_mode = MAP_WRITE_ONLY;
40 break;
41 case GpuMemoryBuffer::READ_WRITE:
42 map_mode = MAP_READ_WRITE;
43 break;
44 default:
45 LOG(DFATAL) << "Unknown map mode: " << mode;
46 }
47 int err = g_gl_draw_functions->map(buffer_id_, map_mode, vaddr);
48 DCHECK(err == 0);
49 mapped_ = true;
50 }
51
52 void GpuMemoryBufferImpl::Unmap() {
53 DCHECK(buffer_id_ != 0);
54 int err = g_gl_draw_functions->unmap(buffer_id_);
55 DCHECK(err == 0);
56 mapped_ = false;
57 }
58
59 void* GpuMemoryBufferImpl::GetNativeBuffer() {
60 DCHECK(buffer_id_ != 0);
61 return g_gl_draw_functions->get_native_buffer(buffer_id_);
62 }
63
64 uint32 GpuMemoryBufferImpl::GetStride() {
65 DCHECK(buffer_id_ != 0);
66 return g_gl_draw_functions->get_stride(buffer_id_);
67 }
68
69 bool GpuMemoryBufferImpl::IsMapped() {
70 return mapped_;
71 }
72
73 bool GpuMemoryBufferImpl::InitCheck() {
74 return buffer_id_ != 0;
75 }
76
77 // static
78 scoped_ptr<gpu::GpuMemoryBuffer> GpuMemoryBufferImpl::CreateGpuMemoryBuffer(
79 int width, int height) {
80 DCHECK(width > 0);
81 DCHECK(height > 0);
82 scoped_ptr<GpuMemoryBufferImpl> result(new GpuMemoryBufferImpl(
83 gfx::Size(width, height)));
84
85 // Check if the buffer allocation succeeded.
86 if (!result->InitCheck())
87 return scoped_ptr<GpuMemoryBuffer>();
88
89 return result.PassAs<gpu::GpuMemoryBuffer>();
90 }
91
92 // static
93 void GpuMemoryBufferImpl::SetAwDrawGLFunctionTable(
94 AwDrawGLFunctionTable* table) {
95 g_gl_draw_functions = table;
96 gpu::GLInProcessContext::SetGpuMemoryBufferCreator(&CreateGpuMemoryBuffer);
97 }
98
99 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698