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

Side by Side Diff: chrome/browser/android/vr_shell/vr_shell_command_buffer_gl.cc

Issue 2729523002: Re-land^2 WebVR compositor bypass via BrowserMain context + mailbox (Closed)
Patch Set: Further cleanups Created 3 years, 9 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
OLDNEW
(Empty)
1 // Copyright 2017 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 "chrome/browser/android/vr_shell/vr_shell_command_buffer_gl.h"
6
7 #include "chrome/browser/android/vr_shell/vr_shell_gpu_renderer.h"
8 #include "gpu/command_buffer/client/gles2_interface.h"
9 #include "gpu/command_buffer/common/mailbox.h"
10 #include "gpu/ipc/common/gpu_surface_tracker.h"
11 #include "services/ui/public/cpp/gpu/context_provider_command_buffer.h"
12 #include "ui/android/context_provider_factory.h"
13 #include "ui/gl/android/surface_texture.h"
14
15 #if defined(OS_ANDROID)
mthiesse 2017/03/02 15:55:16 nit: Remove this for now? We're still in the Andro
klausw 2017/03/07 02:55:54 Done.
16 #include <android/native_window_jni.h>
17 #endif
18 namespace vr_shell {
19
20 VrShellCommandBufferGl::VrShellCommandBufferGl() :
21 weak_ptr_factory_(this) {}
22
23 VrShellCommandBufferGl::~VrShellCommandBufferGl() {}
24
25 void VrShellCommandBufferGl::OnGpuChannelEstablished(
26 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host,
27 ui::ContextProviderFactory::GpuChannelHostResult result) {
28
29 VLOG(1) << __FUNCTION__ << ";;;";
30 switch (result) {
31 // Don't retry if we are shutting down.
mthiesse 2017/03/02 15:55:16 Also don't retry if initialization fails?
klausw 2017/03/07 02:55:55 Moot, the switch no longer exists.
32 case ui::ContextProviderFactory::GpuChannelHostResult::
33 FAILURE_FACTORY_SHUTDOWN:
34 break;
35 case ui::ContextProviderFactory::GpuChannelHostResult::
36 FAILURE_GPU_PROCESS_INITIALIZATION_FAILED:
37 break;
38 case ui::ContextProviderFactory::GpuChannelHostResult::SUCCESS:
39 VLOG(1) << __FUNCTION__ << ";;; Success!";
40
41 const size_t full_screen_texture_size_in_bytes = 4000 * 3000 * 4;
mthiesse 2017/03/02 15:55:16 Lots of magic numbers, where do these come from?
klausw 2017/03/07 02:55:54 Replaced with gpu::SharedMemoryLimits::ForMailboxC
42 gpu::SharedMemoryLimits limits;
43 limits.command_buffer_size = 64 * 1024;
44 limits.start_transfer_buffer_size = 64 * 1024;
45 limits.min_transfer_buffer_size = 64 * 1024;
46 limits.max_transfer_buffer_size = full_screen_texture_size_in_bytes;
47 limits.mapped_memory_reclaim_limit = full_screen_texture_size_in_bytes;
48
49 gpu::gles2::ContextCreationAttribHelper attributes;
50 attributes.alpha_size = 0;
51 attributes.stencil_size = 0;
52 attributes.depth_size = 0;
53 attributes.samples = 0;
54 attributes.sample_buffers = 0;
55 attributes.bind_generates_resource = false;
56
57 bool automatic_flushes = false;
58 bool support_locking = false;
59 constexpr ui::ContextProviderCommandBuffer* shared_context_provider =
60 nullptr;
61 context_provider_command_buffer_ = make_scoped_refptr(
62 new ui::ContextProviderCommandBuffer(
63 std::move(gpu_channel_host), gpu::GPU_STREAM_DEFAULT,
64 gpu::GpuStreamPriority::NORMAL, surface_handle_,
65 GURL("chrome://gpu/MusContextFactory"), automatic_flushes,
66 support_locking, limits, attributes,
67 shared_context_provider,
68 ui::command_buffer_metrics::MUS_CLIENT_CONTEXT));
69
70 VLOG(1) << __FUNCTION__ << ";;; context_provider_command_buffer=" <<
71 context_provider_command_buffer_;
72 if (!context_provider_command_buffer_->BindToCurrentThread()) {
73 LOG(ERROR) << __FUNCTION__ << ";;; failed to init ContextProvider";
74 break;
75 }
76 VLOG(1) << __FUNCTION__ << ";;; bind succeeded";
77
78 gl_ = context_provider_command_buffer_->ContextGL();
79 VLOG(1) << __FUNCTION__ << ";;; gl_=" << gl_;
80
81 break;
82 }
83 }
84
85 void VrShellCommandBufferGl::CreateContext(
86 scoped_refptr<gl::SurfaceTexture> surface_texture) {
87 ANativeWindow* window = surface_texture->CreateSurface();
88 gpu::GpuSurfaceTracker* tracker = gpu::GpuSurfaceTracker::Get();
89 ANativeWindow_acquire(window);
90 // setBuffersGeometry seems optional, it uses the SurfaceTexture's
91 // default size by default?
92 // ANativeWindow_setBuffersGeometry(
93 // window, 2048, 1024, WINDOW_FORMAT_RGBA_8888); // FIXME!
94 surface_handle_ = tracker->AddSurfaceForNativeWidget(window);
95 VLOG(1) << __FUNCTION__ << ";;;: surface_handle_=" << surface_handle_;
96
97 auto surface = base::MakeUnique<gl::ScopedJavaSurface>(surface_texture.get());
98 tracker->RegisterViewSurface(
99 surface_handle_, surface->j_surface().obj());
100 // When should this be released? Does registering it keep it alive?
mthiesse 2017/03/02 15:55:16 Is this relevant? https://codereview.chromium.org/
klausw 2017/03/07 02:55:54 It is indeed, added unregistration to destructor.
101 ANativeWindow_release(window);
102
103 VLOG(1) << __FUNCTION__ << ";;; RequestGpuChannelHost start";
104 ui::ContextProviderFactory::GetInstance()->RequestGpuChannelHost(base::Bind(
105 &VrShellCommandBufferGl::OnGpuChannelEstablished,
106 weak_ptr_factory_.GetWeakPtr()));
107 VLOG(1) << __FUNCTION__ << ";;; RequestGpuChannelHost end";
108 }
109
110 bool VrShellCommandBufferGl::CopyFrameToSurface(
111 int frame_index, const gpu::Mailbox& mailbox, bool discard) {
112 auto gl = GetContext();;
113 if (!gl) {
114 VLOG(1) << __FUNCTION__ << ";;; drop, no GL context";
115 return false;
116 }
117 VLOG(1) << __FUNCTION__ << ";;; frame=" << frame_index << " gl=" << gl;
118
119 // Default viewport size seems ok, don't set one here and leave it
120 // alone elsewhere.
121 // gl->Viewport(0, 0, 2560, 1440); // FIXME!
122
123 // TODO(klausw): make this a proper member
124 static GpuRenderer* copyRenderer = nullptr;
125 if (!copyRenderer) {
126 copyRenderer = new GpuRenderer(gl);
127 }
128
129 VLOG(1) << __FUNCTION__ << ";;; got mailbox, name=" <<
130 static_cast<int>(mailbox.name[0]) << "," <<
131 static_cast<int>(mailbox.name[1]) << "," <<
132 static_cast<int>(mailbox.name[2]) << "," <<
133 static_cast<int>(mailbox.name[3]) << "," <<
134 static_cast<int>(mailbox.name[4]) << "," <<
135 static_cast<int>(mailbox.name[5]) << "," <<
136 static_cast<int>(mailbox.name[6]) << "," <<
137 static_cast<int>(mailbox.name[7]) << "," <<
138 static_cast<int>(mailbox.name[8]) << "," <<
139 static_cast<int>(mailbox.name[9]) << "," <<
140 static_cast<int>(mailbox.name[10]) << "," <<
141 static_cast<int>(mailbox.name[11]) << "," <<
142 static_cast<int>(mailbox.name[12]) << "," <<
143 static_cast<int>(mailbox.name[13]) << "," <<
144 static_cast<int>(mailbox.name[14]) << "," <<
145 static_cast<int>(mailbox.name[15]);
146 GLuint vrSourceTexture = gl->CreateAndConsumeTextureCHROMIUM(
147 GL_TEXTURE_2D, mailbox.name);
148 VLOG(1) << __FUNCTION__ << ";;; vrSourceTexture=" << vrSourceTexture;
149
150 bool skip_this_frame = false;
151
152 if (discard) {
153 // We've consumed the texture, but we can't draw it to the surface, the
154 // previous one hasn't been consumed yet. Swapping twice loses frames.
155 // This should be rare, it's a waste of resources and can suppress useful
156 // frames.
157 VLOG(1) << __FUNCTION__ << ";;; Dropping frame, got one queued already.";
158 skip_this_frame = true;
159 }
160
161 VLOG(1) << __FUNCTION__ << ";;; Draw start";
162 copyRenderer->DrawQuad(gl, vrSourceTexture);
163 VLOG(1) << __FUNCTION__ << ";;; Draw done";
164
165 if (skip_this_frame) {
166 VLOG(1) << __FUNCTION__ << ";;; drop frame=" << frame_index;
167 return false;
168 }
169
170 // This is a load-bearing glFlush(). Removing it breaks rendering. WTF.
171 // FIXME: check if this is still true.
172 gl->Flush();
173 gl->SwapBuffers();
174 gl->Flush();
175 VLOG(1) << __FUNCTION__ << ";;; Swap/flush done";
176 return true;
177 }
178
179 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698