OLD | NEW |
---|---|
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 Loading... | |
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 context->SetContextType(BROWSER_OFFSCREEN_MAINTHREAD_CONTEXT); |
213 if (context->InitializeOnCurrentThread()) { | 179 provider_ = ContextProviderCommandBuffer::Create( |
214 context->GetImplementation()->TraceBeginCHROMIUM( | 180 std::move(context), |
215 "gpu_toplevel", | 181 BROWSER_OFFSCREEN_MAINTHREAD_CONTEXT); |
danakj
2016/03/16 20:17:05
Is this the right context type?
no sievers
2016/03/16 23:27:10
yes that's good, and you can remove the SetContext
danakj
2016/03/16 23:29:16
Done.
| |
216 base::StringPrintf("CmdBufferImageTransportFactory-%p", context.get()) | 182 if (!provider_->BindToCurrentThread()) |
217 .c_str()); | 183 return; |
218 } else { | 184 provider_->ContextGL()->TraceBeginCHROMIUM( |
219 context.reset(); | 185 "gpu_toplevel", |
220 } | 186 base::StringPrintf("CmdBufferImageTransportFactory-%p", provider_.get()) |
187 .c_str()); | |
188 provider_->SetLostContextCallback( | |
189 base::Bind(&GLHelperHolder::OnContextLost, base::Unretained(this))); | |
190 gl_helper_.reset(new GLHelper(provider_->ContextGL(), | |
191 provider_->ContextSupport())); | |
192 } | |
221 | 193 |
222 return context; | 194 void GLHelperHolder::OnContextLost() { |
195 // Need to post a task because the command buffer client cannot be deleted | |
196 // from within this callback. | |
197 base::MessageLoop::current()->PostTask( | |
198 FROM_HERE, | |
199 base::Bind(&RenderWidgetHostViewAndroid::OnContextLost)); | |
223 } | 200 } |
224 | 201 |
225 // This can only be used for readback postprocessing. It may return null if the | 202 // This can only be used for readback postprocessing. It may return null if the |
226 // channel was lost and not reestablished yet. | 203 // channel was lost and not reestablished yet. |
227 GLHelper* GetPostReadbackGLHelper() { | 204 GLHelper* GetPostReadbackGLHelper() { |
228 static GLHelperHolder* g_readback_helper_holder = nullptr; | 205 static GLHelperHolder* g_readback_helper_holder = nullptr; |
229 | 206 |
230 if (g_readback_helper_holder && g_readback_helper_holder->IsLost()) { | 207 if (g_readback_helper_holder && g_readback_helper_holder->IsLost()) { |
231 delete g_readback_helper_holder; | 208 delete g_readback_helper_holder; |
232 g_readback_helper_holder = nullptr; | 209 g_readback_helper_holder = nullptr; |
233 } | 210 } |
234 | 211 |
235 if (!g_readback_helper_holder) | 212 if (!g_readback_helper_holder) |
236 g_readback_helper_holder = GLHelperHolder::Create(); | 213 g_readback_helper_holder = GLHelperHolder::Create(); |
237 | 214 |
238 return g_readback_helper_holder->GetGLHelper(); | 215 return g_readback_helper_holder->gl_helper(); |
239 } | 216 } |
240 | 217 |
241 void CopyFromCompositingSurfaceFinished( | 218 void CopyFromCompositingSurfaceFinished( |
242 const ReadbackRequestCallback& callback, | 219 const ReadbackRequestCallback& callback, |
243 scoped_ptr<cc::SingleReleaseCallback> release_callback, | 220 scoped_ptr<cc::SingleReleaseCallback> release_callback, |
244 scoped_ptr<SkBitmap> bitmap, | 221 scoped_ptr<SkBitmap> bitmap, |
245 const base::TimeTicks& start_time, | 222 const base::TimeTicks& start_time, |
246 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock, | 223 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock, |
247 bool result) { | 224 bool result) { |
248 TRACE_EVENT0( | 225 TRACE_EVENT0( |
(...skipping 1776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2025 results->orientationAngle = display.RotationAsDegree(); | 2002 results->orientationAngle = display.RotationAsDegree(); |
2026 results->orientationType = | 2003 results->orientationType = |
2027 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); | 2004 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); |
2028 gfx::DeviceDisplayInfo info; | 2005 gfx::DeviceDisplayInfo info; |
2029 results->depth = info.GetBitsPerPixel(); | 2006 results->depth = info.GetBitsPerPixel(); |
2030 results->depthPerComponent = info.GetBitsPerComponent(); | 2007 results->depthPerComponent = info.GetBitsPerComponent(); |
2031 results->isMonochrome = (results->depthPerComponent == 0); | 2008 results->isMonochrome = (results->depthPerComponent == 0); |
2032 } | 2009 } |
2033 | 2010 |
2034 } // namespace content | 2011 } // namespace content |
OLD | NEW |