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

Side by Side Diff: content/browser/android/in_process/synchronous_compositor_factory_impl.cc

Issue 1061763002: android: Merge CreateOffscreenContext and CreateContext into one function. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: shareResources Created 5 years, 8 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/android/in_process/synchronous_compositor_factory_impl .h" 5 #include "content/browser/android/in_process/synchronous_compositor_factory_impl .h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/observer_list.h" 8 #include "base/observer_list.h"
9 #include "content/browser/android/in_process/synchronous_compositor_external_beg in_frame_source.h" 9 #include "content/browser/android/in_process/synchronous_compositor_external_beg in_frame_source.h"
10 #include "content/browser/android/in_process/synchronous_compositor_impl.h" 10 #include "content/browser/android/in_process/synchronous_compositor_impl.h"
(...skipping 21 matching lines...) Expand all
32 blink::WebGraphicsContext3D::Attributes attributes; 32 blink::WebGraphicsContext3D::Attributes attributes;
33 attributes.antialias = false; 33 attributes.antialias = false;
34 attributes.depth = false; 34 attributes.depth = false;
35 attributes.stencil = false; 35 attributes.stencil = false;
36 attributes.shareResources = true; 36 attributes.shareResources = true;
37 attributes.noAutomaticFlushes = true; 37 attributes.noAutomaticFlushes = true;
38 38
39 return attributes; 39 return attributes;
40 } 40 }
41 41
42 scoped_ptr<gpu::GLInProcessContext> CreateOffscreenContext( 42 scoped_ptr<gpu::GLInProcessContext> CreateContextHolder(
43 const blink::WebGraphicsContext3D::Attributes& attributes) { 43 const blink::WebGraphicsContext3D::Attributes& attributes,
44 scoped_refptr<gpu::InProcessCommandBuffer::Service> service,
45 const gpu::GLInProcessContextSharedMemoryLimits& mem_limits,
46 bool is_offscreen) {
44 const gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; 47 const gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu;
45 48
46 gpu::gles2::ContextCreationAttribHelper in_process_attribs; 49 gpu::gles2::ContextCreationAttribHelper in_process_attribs;
47 WebGraphicsContext3DImpl::ConvertAttributes( 50 WebGraphicsContext3DImpl::ConvertAttributes(attributes, &in_process_attribs);
48 attributes, &in_process_attribs);
49 in_process_attribs.lose_context_when_out_of_memory = true; 51 in_process_attribs.lose_context_when_out_of_memory = true;
50 52
51 scoped_ptr<gpu::GLInProcessContext> context(gpu::GLInProcessContext::Create( 53 scoped_ptr<gpu::GLInProcessContext> context(gpu::GLInProcessContext::Create(
52 NULL /* service */,
53 NULL /* surface */,
54 true /* is_offscreen */,
55 gfx::kNullAcceleratedWidget,
56 gfx::Size(1, 1),
57 NULL /* share_context */,
58 attributes.shareResources,
59 in_process_attribs,
60 gpu_preference,
61 gpu::GLInProcessContextSharedMemoryLimits(),
62 nullptr,
63 nullptr));
64 return context.Pass();
65 }
66
67 scoped_ptr<gpu::GLInProcessContext> CreateContext(
68 scoped_refptr<gpu::InProcessCommandBuffer::Service> service,
69 const gpu::GLInProcessContextSharedMemoryLimits& mem_limits,
70 bool is_offscreen,
71 bool share_resources) {
72 const gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu;
73 gpu::gles2::ContextCreationAttribHelper in_process_attribs;
74 WebGraphicsContext3DImpl::ConvertAttributes(
75 GetDefaultAttribs(), &in_process_attribs);
76 in_process_attribs.lose_context_when_out_of_memory = true;
77
78 scoped_ptr<gpu::GLInProcessContext> context(gpu::GLInProcessContext::Create(
79 service, 54 service,
80 NULL /* surface */, 55 NULL /* surface */,
81 is_offscreen, 56 is_offscreen,
82 gfx::kNullAcceleratedWidget, 57 gfx::kNullAcceleratedWidget,
83 gfx::Size(1, 1), 58 gfx::Size(1, 1),
84 NULL /* share_context */, 59 NULL /* share_context */,
85 share_resources /* share_resources */, 60 attributes.shareResources,
86 in_process_attribs, 61 in_process_attribs,
87 gpu_preference, 62 gpu_preference,
88 mem_limits, 63 mem_limits,
89 nullptr, 64 nullptr,
90 nullptr)); 65 nullptr));
91 return context.Pass(); 66 return context.Pass();
92 } 67 }
93 68
94 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> WrapContext( 69 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> WrapContext(
95 scoped_ptr<gpu::GLInProcessContext> context) { 70 scoped_ptr<gpu::GLInProcessContext> context) {
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 SynchronousCompositorFactoryImpl::CreateExternalBeginFrameSource( 175 SynchronousCompositorFactoryImpl::CreateExternalBeginFrameSource(
201 int routing_id) { 176 int routing_id) {
202 return make_scoped_ptr( 177 return make_scoped_ptr(
203 new SynchronousCompositorExternalBeginFrameSource(routing_id)); 178 new SynchronousCompositorExternalBeginFrameSource(routing_id));
204 } 179 }
205 180
206 scoped_refptr<ContextProviderWebContext> 181 scoped_refptr<ContextProviderWebContext>
207 SynchronousCompositorFactoryImpl::CreateOffscreenContextProvider( 182 SynchronousCompositorFactoryImpl::CreateOffscreenContextProvider(
208 const blink::WebGraphicsContext3D::Attributes& attributes, 183 const blink::WebGraphicsContext3D::Attributes& attributes,
209 const std::string& debug_name) { 184 const std::string& debug_name) {
210 scoped_ptr<gpu::GLInProcessContext> context = 185 scoped_ptr<gpu::GLInProcessContext> context = CreateContextHolder(
211 CreateOffscreenContext(attributes); 186 attributes, nullptr, gpu::GLInProcessContextSharedMemoryLimits(), true);
212 return webkit::gpu::ContextProviderInProcess::Create( 187 return webkit::gpu::ContextProviderInProcess::Create(
213 WrapContext(context.Pass()), debug_name); 188 WrapContext(context.Pass()), debug_name);
214 } 189 }
215 190
216 scoped_refptr<cc::ContextProvider> 191 scoped_refptr<cc::ContextProvider>
217 SynchronousCompositorFactoryImpl::CreateContextProviderForCompositor() { 192 SynchronousCompositorFactoryImpl::CreateContextProviderForCompositor() {
218 DCHECK(service_.get()); 193 DCHECK(service_.get());
219 194
220 gpu::GLInProcessContextSharedMemoryLimits mem_limits; 195 gpu::GLInProcessContextSharedMemoryLimits mem_limits;
221 // This is half of what RenderWidget uses because synchronous compositor 196 // This is half of what RenderWidget uses because synchronous compositor
222 // pipeline is only one frame deep. 197 // pipeline is only one frame deep.
223 mem_limits.mapped_memory_reclaim_limit = 6 * 1024 * 1024; 198 mem_limits.mapped_memory_reclaim_limit = 6 * 1024 * 1024;
224 return webkit::gpu::ContextProviderInProcess::Create( 199 return webkit::gpu::ContextProviderInProcess::Create(
225 WrapContext(CreateContext(nullptr, mem_limits, true, true)), 200 WrapContext(
201 CreateContextHolder(GetDefaultAttribs(), nullptr, mem_limits, true)),
226 "Child-Compositor"); 202 "Child-Compositor");
227 } 203 }
228 204
229 scoped_refptr<StreamTextureFactory> 205 scoped_refptr<StreamTextureFactory>
230 SynchronousCompositorFactoryImpl::CreateStreamTextureFactory(int frame_id) { 206 SynchronousCompositorFactoryImpl::CreateStreamTextureFactory(int frame_id) {
231 scoped_refptr<StreamTextureFactorySynchronousImpl> factory( 207 scoped_refptr<StreamTextureFactorySynchronousImpl> factory(
232 StreamTextureFactorySynchronousImpl::Create( 208 StreamTextureFactorySynchronousImpl::Create(
233 base::Bind( 209 base::Bind(
234 &SynchronousCompositorFactoryImpl::TryCreateStreamTextureFactory, 210 &SynchronousCompositorFactoryImpl::TryCreateStreamTextureFactory,
235 base::Unretained(this)), 211 base::Unretained(this)),
236 frame_id)); 212 frame_id));
237 return factory; 213 return factory;
238 } 214 }
239 215
240 WebGraphicsContext3DInProcessCommandBufferImpl* 216 WebGraphicsContext3DInProcessCommandBufferImpl*
241 SynchronousCompositorFactoryImpl::CreateOffscreenGraphicsContext3D( 217 SynchronousCompositorFactoryImpl::CreateOffscreenGraphicsContext3D(
242 const blink::WebGraphicsContext3D::Attributes& attributes) { 218 const blink::WebGraphicsContext3D::Attributes& attributes) {
243 return WrapContextWithAttributes(CreateOffscreenContext(attributes), 219 return WrapContextWithAttributes(
244 attributes).release(); 220 CreateContextHolder(attributes, nullptr,
221 gpu::GLInProcessContextSharedMemoryLimits(),
222 true),
223 attributes).release();
245 } 224 }
246 225
247 void SynchronousCompositorFactoryImpl::CompositorInitializedHardwareDraw() { 226 void SynchronousCompositorFactoryImpl::CompositorInitializedHardwareDraw() {
248 base::AutoLock lock(num_hardware_compositor_lock_); 227 base::AutoLock lock(num_hardware_compositor_lock_);
249 num_hardware_compositors_++; 228 num_hardware_compositors_++;
250 if (num_hardware_compositors_ == 1 && main_thread_proxy_.get()) { 229 if (num_hardware_compositors_ == 1 && main_thread_proxy_.get()) {
251 main_thread_proxy_->PostTask( 230 main_thread_proxy_->PostTask(
252 FROM_HERE, 231 FROM_HERE,
253 base::Bind( 232 base::Bind(
254 &SynchronousCompositorFactoryImpl::RestoreContextOnMainThread, 233 &SynchronousCompositorFactoryImpl::RestoreContextOnMainThread,
(...skipping 29 matching lines...) Expand all
284 // |video_context_provider_| to null is also not safe since it makes 263 // |video_context_provider_| to null is also not safe since it makes
285 // synchronous destruction uncontrolled and possibly deadlock. 264 // synchronous destruction uncontrolled and possibly deadlock.
286 if (!CanCreateMainThreadContext()) { 265 if (!CanCreateMainThreadContext()) {
287 return 266 return
288 scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider>(); 267 scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider>();
289 } 268 }
290 269
291 if (!video_context_provider_.get()) { 270 if (!video_context_provider_.get()) {
292 DCHECK(service_.get()); 271 DCHECK(service_.get());
293 272
273 blink::WebGraphicsContext3D::Attributes attributes = GetDefaultAttribs();
274 attributes.shareResources = false;
294 // This needs to run in on-screen |service_| context due to SurfaceTexture 275 // This needs to run in on-screen |service_| context due to SurfaceTexture
295 // limitations. 276 // limitations.
296 video_context_provider_ = new VideoContextProvider(CreateContext( 277 video_context_provider_ = new VideoContextProvider(CreateContextHolder(
297 service_, gpu::GLInProcessContextSharedMemoryLimits(), false, false)); 278 attributes, service_, gpu::GLInProcessContextSharedMemoryLimits(),
279 false));
298 } 280 }
299 return video_context_provider_; 281 return video_context_provider_;
300 } 282 }
301 283
302 void SynchronousCompositorFactoryImpl::SetDeferredGpuService( 284 void SynchronousCompositorFactoryImpl::SetDeferredGpuService(
303 scoped_refptr<gpu::InProcessCommandBuffer::Service> service) { 285 scoped_refptr<gpu::InProcessCommandBuffer::Service> service) {
304 DCHECK(!service_.get()); 286 DCHECK(!service_.get());
305 service_ = service; 287 service_ = service;
306 } 288 }
307 289
308 void SynchronousCompositorFactoryImpl::SetRecordFullDocument( 290 void SynchronousCompositorFactoryImpl::SetRecordFullDocument(
309 bool record_full_document) { 291 bool record_full_document) {
310 record_full_layer_ = record_full_document; 292 record_full_layer_ = record_full_document;
311 } 293 }
312 294
313 } // namespace content 295 } // 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