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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_android.cc

Issue 1805343005: android: Hide the WebGraphicsContext3D in GLHelperHolder (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@wgc3d-unused
Patch Set: wgc3d-rwhva: removedsetcontext Created 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/renderer_host/render_widget_host_view_android.h" 5 #include "content/browser/renderer_host/render_widget_host_view_android.h"
6 6
7 #include <android/bitmap.h> 7 #include <android/bitmap.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/android/build_info.h" 10 #include "base/android/build_info.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 LOG(ERROR) << "Attempting to require callback on nonexistent surface"; 109 LOG(ERROR) << "Attempting to require callback on nonexistent surface";
110 return; 110 return;
111 } 111 }
112 surface->AddDestructionDependency(sequence); 112 surface->AddDestructionDependency(sequence);
113 } 113 }
114 114
115 const int kUndefinedOutputSurfaceId = -1; 115 const int kUndefinedOutputSurfaceId = -1;
116 116
117 static const char kAsyncReadBackString[] = "Compositing.CopyFromSurfaceTime"; 117 static const char kAsyncReadBackString[] = "Compositing.CopyFromSurfaceTime";
118 118
119 class GLHelperHolder 119 class GLHelperHolder {
120 : public blink::WebGraphicsContext3D::WebGraphicsContextLostCallback {
121 public: 120 public:
122 static GLHelperHolder* Create(); 121 static GLHelperHolder* Create();
123 ~GLHelperHolder() override;
124 122
125 void Initialize(); 123 GLHelper* gl_helper() { return gl_helper_.get(); }
126
127 // WebGraphicsContextLostCallback implementation.
128 void onContextLost() override;
129
130 GLHelper* GetGLHelper() { return gl_helper_.get(); }
131 bool IsLost() { 124 bool IsLost() {
132 return !context_ || 125 if (!gl_helper_)
133 context_->GetGLInterface()->GetGraphicsResetStatusKHR() != 126 return true;
134 GL_NO_ERROR; 127 return provider_->ContextGL()->GetGraphicsResetStatusKHR() != GL_NO_ERROR;
135 } 128 }
136 129
137 private: 130 private:
138 GLHelperHolder(); 131 GLHelperHolder() = default;
139 static scoped_ptr<WebGraphicsContext3DCommandBufferImpl> CreateContext3D(); 132 void Initialize();
133 void OnContextLost();
140 134
141 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context_; 135 scoped_refptr<ContextProviderCommandBuffer> provider_;
142 scoped_ptr<GLHelper> gl_helper_; 136 scoped_ptr<GLHelper> gl_helper_;
143 137
144 DISALLOW_COPY_AND_ASSIGN(GLHelperHolder); 138 DISALLOW_COPY_AND_ASSIGN(GLHelperHolder);
145 }; 139 };
146 140
147 GLHelperHolder* GLHelperHolder::Create() { 141 GLHelperHolder* GLHelperHolder::Create() {
148 GLHelperHolder* holder = new GLHelperHolder; 142 GLHelperHolder* holder = new GLHelperHolder;
149 holder->Initialize(); 143 holder->Initialize();
150
151 return holder; 144 return holder;
152 } 145 }
153 146
154 GLHelperHolder::GLHelperHolder() { 147 void GLHelperHolder::Initialize() {
155 } 148 auto* factory = BrowserGpuChannelHostFactory::instance();
149 scoped_refptr<GpuChannelHost> gpu_channel_host(factory->GetGpuChannel());
156 150
157 GLHelperHolder::~GLHelperHolder() { 151 // The Browser Compositor is in charge of reestablishing the channel if its
158 } 152 // missing.
159 153 if (!gpu_channel_host)
160 void GLHelperHolder::Initialize() { 154 return;
161 context_ = CreateContext3D();
162 if (context_) {
163 context_->setContextLostCallback(this);
164 gl_helper_.reset(new GLHelper(context_->GetImplementation(),
165 context_->GetContextSupport()));
166 }
167 }
168
169 void GLHelperHolder::onContextLost() {
170 // Need to post a task because the command buffer client cannot be deleted
171 // from within this callback.
172 LOG(ERROR) << "Context lost.";
173 base::MessageLoop::current()->PostTask(
174 FROM_HERE,
175 base::Bind(&RenderWidgetHostViewAndroid::OnContextLost));
176 }
177
178 scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
179 GLHelperHolder::CreateContext3D() {
180 BrowserGpuChannelHostFactory* factory =
181 BrowserGpuChannelHostFactory::instance();
182 scoped_refptr<GpuChannelHost> gpu_channel_host(factory->GetGpuChannel());
183 // GLHelper can only be used in asynchronous APIs for postprocessing after
184 // Browser Compositor operations (i.e. readback).
185 if (!gpu_channel_host.get()) {
186 // The Browser Compositor is in charge of reestablishing the channel.
187 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
188 }
189 155
190 blink::WebGraphicsContext3D::Attributes attrs; 156 blink::WebGraphicsContext3D::Attributes attrs;
191 attrs.shareResources = true; 157 attrs.shareResources = true;
192 GURL url("chrome://gpu/RenderWidgetHostViewAndroid"); 158 GURL url("chrome://gpu/RenderWidgetHostViewAndroid");
193 static const size_t kBytesPerPixel = 4; 159 static const size_t kBytesPerPixel = 4;
194 gfx::DeviceDisplayInfo display_info; 160 gfx::DeviceDisplayInfo display_info;
195 size_t full_screen_texture_size_in_bytes = display_info.GetDisplayHeight() * 161 size_t full_screen_texture_size_in_bytes = display_info.GetDisplayHeight() *
196 display_info.GetDisplayWidth() * 162 display_info.GetDisplayWidth() *
197 kBytesPerPixel; 163 kBytesPerPixel;
198 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits; 164 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits;
199 limits.command_buffer_size = 64 * 1024; 165 limits.command_buffer_size = 64 * 1024;
200 limits.start_transfer_buffer_size = 64 * 1024; 166 limits.start_transfer_buffer_size = 64 * 1024;
201 limits.min_transfer_buffer_size = 64 * 1024; 167 limits.min_transfer_buffer_size = 64 * 1024;
202 limits.max_transfer_buffer_size = std::min( 168 limits.max_transfer_buffer_size = std::min(
203 3 * full_screen_texture_size_in_bytes, kDefaultMaxTransferBufferSize); 169 3 * full_screen_texture_size_in_bytes, kDefaultMaxTransferBufferSize);
204 limits.mapped_memory_reclaim_limit = 170 limits.mapped_memory_reclaim_limit =
205 WebGraphicsContext3DCommandBufferImpl::kNoLimit; 171 WebGraphicsContext3DCommandBufferImpl::kNoLimit;
206 bool lose_context_when_out_of_memory = false; 172 bool lose_context_when_out_of_memory = false;
207 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( 173 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
208 new WebGraphicsContext3DCommandBufferImpl( 174 new WebGraphicsContext3DCommandBufferImpl(
209 gpu::kNullSurfaceHandle, // offscreen 175 gpu::kNullSurfaceHandle, // offscreen
210 url, gpu_channel_host.get(), attrs, lose_context_when_out_of_memory, 176 url, gpu_channel_host.get(), attrs, lose_context_when_out_of_memory,
211 limits, nullptr)); 177 limits, nullptr));
212 context->SetContextType(BROWSER_OFFSCREEN_MAINTHREAD_CONTEXT); 178 provider_ = ContextProviderCommandBuffer::Create(
213 if (context->InitializeOnCurrentThread()) { 179 std::move(context), BROWSER_OFFSCREEN_MAINTHREAD_CONTEXT);
214 context->GetImplementation()->TraceBeginCHROMIUM( 180 if (!provider_->BindToCurrentThread())
215 "gpu_toplevel", 181 return;
216 base::StringPrintf("CmdBufferImageTransportFactory-%p", context.get()) 182 provider_->ContextGL()->TraceBeginCHROMIUM(
217 .c_str()); 183 "gpu_toplevel",
218 } else { 184 base::StringPrintf("CmdBufferImageTransportFactory-%p", provider_.get())
219 context.reset(); 185 .c_str());
220 } 186 provider_->SetLostContextCallback(
187 base::Bind(&GLHelperHolder::OnContextLost, base::Unretained(this)));
188 gl_helper_.reset(
189 new GLHelper(provider_->ContextGL(), provider_->ContextSupport()));
190 }
221 191
222 return context; 192 void GLHelperHolder::OnContextLost() {
193 // Need to post a task because the command buffer client cannot be deleted
194 // from within this callback.
195 base::MessageLoop::current()->PostTask(
196 FROM_HERE, base::Bind(&RenderWidgetHostViewAndroid::OnContextLost));
223 } 197 }
224 198
225 // This can only be used for readback postprocessing. It may return null if the 199 // This can only be used for readback postprocessing. It may return null if the
226 // channel was lost and not reestablished yet. 200 // channel was lost and not reestablished yet.
227 GLHelper* GetPostReadbackGLHelper() { 201 GLHelper* GetPostReadbackGLHelper() {
228 static GLHelperHolder* g_readback_helper_holder = nullptr; 202 static GLHelperHolder* g_readback_helper_holder = nullptr;
229 203
230 if (g_readback_helper_holder && g_readback_helper_holder->IsLost()) { 204 if (g_readback_helper_holder && g_readback_helper_holder->IsLost()) {
231 delete g_readback_helper_holder; 205 delete g_readback_helper_holder;
232 g_readback_helper_holder = nullptr; 206 g_readback_helper_holder = nullptr;
233 } 207 }
234 208
235 if (!g_readback_helper_holder) 209 if (!g_readback_helper_holder)
236 g_readback_helper_holder = GLHelperHolder::Create(); 210 g_readback_helper_holder = GLHelperHolder::Create();
237 211
238 return g_readback_helper_holder->GetGLHelper(); 212 return g_readback_helper_holder->gl_helper();
239 } 213 }
240 214
241 void CopyFromCompositingSurfaceFinished( 215 void CopyFromCompositingSurfaceFinished(
242 const ReadbackRequestCallback& callback, 216 const ReadbackRequestCallback& callback,
243 scoped_ptr<cc::SingleReleaseCallback> release_callback, 217 scoped_ptr<cc::SingleReleaseCallback> release_callback,
244 scoped_ptr<SkBitmap> bitmap, 218 scoped_ptr<SkBitmap> bitmap,
245 const base::TimeTicks& start_time, 219 const base::TimeTicks& start_time,
246 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock, 220 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock,
247 bool result) { 221 bool result) {
248 TRACE_EVENT0( 222 TRACE_EVENT0(
(...skipping 1776 matching lines...) Expand 10 before | Expand all | Expand 10 after
2025 results->orientationAngle = display.RotationAsDegree(); 1999 results->orientationAngle = display.RotationAsDegree();
2026 results->orientationType = 2000 results->orientationType =
2027 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); 2001 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display);
2028 gfx::DeviceDisplayInfo info; 2002 gfx::DeviceDisplayInfo info;
2029 results->depth = info.GetBitsPerPixel(); 2003 results->depth = info.GetBitsPerPixel();
2030 results->depthPerComponent = info.GetBitsPerComponent(); 2004 results->depthPerComponent = info.GetBitsPerComponent();
2031 results->isMonochrome = (results->depthPerComponent == 0); 2005 results->isMonochrome = (results->depthPerComponent == 0);
2032 } 2006 }
2033 2007
2034 } // namespace content 2008 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698