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

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: CreatContext() 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 share_resources,
47 bool is_offscreen) {
44 const gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; 48 const gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu;
45 49
46 gpu::gles2::ContextCreationAttribHelper in_process_attribs; 50 gpu::gles2::ContextCreationAttribHelper in_process_attribs;
47 WebGraphicsContext3DImpl::ConvertAttributes( 51 WebGraphicsContext3DImpl::ConvertAttributes(attributes, &in_process_attribs);
48 attributes, &in_process_attribs);
49 in_process_attribs.lose_context_when_out_of_memory = true; 52 in_process_attribs.lose_context_when_out_of_memory = true;
50 53
51 scoped_ptr<gpu::GLInProcessContext> context(gpu::GLInProcessContext::Create( 54 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, 55 service,
80 NULL /* surface */, 56 NULL /* surface */,
81 is_offscreen, 57 is_offscreen,
82 gfx::kNullAcceleratedWidget, 58 gfx::kNullAcceleratedWidget,
83 gfx::Size(1, 1), 59 gfx::Size(1, 1),
84 NULL /* share_context */, 60 NULL /* share_context */,
85 share_resources /* share_resources */, 61 is_offscreen ? attributes.shareResources : share_resources,
boliu 2015/04/07 02:23:26 Can just make this attributes.shareResources? Anyt
tfarina 2015/04/07 04:01:43 Done.
86 in_process_attribs, 62 in_process_attribs,
87 gpu_preference, 63 gpu_preference,
88 mem_limits, 64 mem_limits,
89 nullptr, 65 nullptr,
90 nullptr)); 66 nullptr));
91 return context.Pass(); 67 return context.Pass();
92 } 68 }
93 69
94 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> WrapContext( 70 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> WrapContext(
95 scoped_ptr<gpu::GLInProcessContext> context) { 71 scoped_ptr<gpu::GLInProcessContext> context) {
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 SynchronousCompositorFactoryImpl::CreateExternalBeginFrameSource( 176 SynchronousCompositorFactoryImpl::CreateExternalBeginFrameSource(
201 int routing_id) { 177 int routing_id) {
202 return make_scoped_ptr( 178 return make_scoped_ptr(
203 new SynchronousCompositorExternalBeginFrameSource(routing_id)); 179 new SynchronousCompositorExternalBeginFrameSource(routing_id));
204 } 180 }
205 181
206 scoped_refptr<ContextProviderWebContext> 182 scoped_refptr<ContextProviderWebContext>
207 SynchronousCompositorFactoryImpl::CreateOffscreenContextProvider( 183 SynchronousCompositorFactoryImpl::CreateOffscreenContextProvider(
208 const blink::WebGraphicsContext3D::Attributes& attributes, 184 const blink::WebGraphicsContext3D::Attributes& attributes,
209 const std::string& debug_name) { 185 const std::string& debug_name) {
210 scoped_ptr<gpu::GLInProcessContext> context = 186 scoped_ptr<gpu::GLInProcessContext> context = CreateContextHolder(
211 CreateOffscreenContext(attributes); 187 attributes, nullptr, gpu::GLInProcessContextSharedMemoryLimits(), true,
188 true);
212 return webkit::gpu::ContextProviderInProcess::Create( 189 return webkit::gpu::ContextProviderInProcess::Create(
213 WrapContext(context.Pass()), debug_name); 190 WrapContext(context.Pass()), debug_name);
214 } 191 }
215 192
216 scoped_refptr<cc::ContextProvider> 193 scoped_refptr<cc::ContextProvider>
217 SynchronousCompositorFactoryImpl::CreateContextProviderForCompositor() { 194 SynchronousCompositorFactoryImpl::CreateContextProviderForCompositor() {
218 DCHECK(service_.get()); 195 DCHECK(service_.get());
219 196
220 gpu::GLInProcessContextSharedMemoryLimits mem_limits; 197 gpu::GLInProcessContextSharedMemoryLimits mem_limits;
221 // This is half of what RenderWidget uses because synchronous compositor 198 // This is half of what RenderWidget uses because synchronous compositor
222 // pipeline is only one frame deep. 199 // pipeline is only one frame deep.
223 mem_limits.mapped_memory_reclaim_limit = 6 * 1024 * 1024; 200 mem_limits.mapped_memory_reclaim_limit = 6 * 1024 * 1024;
224 return webkit::gpu::ContextProviderInProcess::Create( 201 return webkit::gpu::ContextProviderInProcess::Create(
225 WrapContext(CreateContext(nullptr, mem_limits, true, true)), 202 WrapContext(CreateContextHolder(GetDefaultAttribs(), nullptr, mem_limits,
203 true, true)),
226 "Child-Compositor"); 204 "Child-Compositor");
227 } 205 }
228 206
229 scoped_refptr<StreamTextureFactory> 207 scoped_refptr<StreamTextureFactory>
230 SynchronousCompositorFactoryImpl::CreateStreamTextureFactory(int frame_id) { 208 SynchronousCompositorFactoryImpl::CreateStreamTextureFactory(int frame_id) {
231 scoped_refptr<StreamTextureFactorySynchronousImpl> factory( 209 scoped_refptr<StreamTextureFactorySynchronousImpl> factory(
232 StreamTextureFactorySynchronousImpl::Create( 210 StreamTextureFactorySynchronousImpl::Create(
233 base::Bind( 211 base::Bind(
234 &SynchronousCompositorFactoryImpl::TryCreateStreamTextureFactory, 212 &SynchronousCompositorFactoryImpl::TryCreateStreamTextureFactory,
235 base::Unretained(this)), 213 base::Unretained(this)),
236 frame_id)); 214 frame_id));
237 return factory; 215 return factory;
238 } 216 }
239 217
240 WebGraphicsContext3DInProcessCommandBufferImpl* 218 WebGraphicsContext3DInProcessCommandBufferImpl*
241 SynchronousCompositorFactoryImpl::CreateOffscreenGraphicsContext3D( 219 SynchronousCompositorFactoryImpl::CreateOffscreenGraphicsContext3D(
242 const blink::WebGraphicsContext3D::Attributes& attributes) { 220 const blink::WebGraphicsContext3D::Attributes& attributes) {
243 return WrapContextWithAttributes(CreateOffscreenContext(attributes), 221 return WrapContextWithAttributes(
244 attributes).release(); 222 CreateContextHolder(attributes, nullptr,
223 gpu::GLInProcessContextSharedMemoryLimits(),
224 true, true),
225 attributes).release();
245 } 226 }
246 227
247 void SynchronousCompositorFactoryImpl::CompositorInitializedHardwareDraw() { 228 void SynchronousCompositorFactoryImpl::CompositorInitializedHardwareDraw() {
248 base::AutoLock lock(num_hardware_compositor_lock_); 229 base::AutoLock lock(num_hardware_compositor_lock_);
249 num_hardware_compositors_++; 230 num_hardware_compositors_++;
250 if (num_hardware_compositors_ == 1 && main_thread_proxy_.get()) { 231 if (num_hardware_compositors_ == 1 && main_thread_proxy_.get()) {
251 main_thread_proxy_->PostTask( 232 main_thread_proxy_->PostTask(
252 FROM_HERE, 233 FROM_HERE,
253 base::Bind( 234 base::Bind(
254 &SynchronousCompositorFactoryImpl::RestoreContextOnMainThread, 235 &SynchronousCompositorFactoryImpl::RestoreContextOnMainThread,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 if (!CanCreateMainThreadContext()) { 267 if (!CanCreateMainThreadContext()) {
287 return 268 return
288 scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider>(); 269 scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider>();
289 } 270 }
290 271
291 if (!video_context_provider_.get()) { 272 if (!video_context_provider_.get()) {
292 DCHECK(service_.get()); 273 DCHECK(service_.get());
293 274
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 GetDefaultAttribs(), service_,
279 gpu::GLInProcessContextSharedMemoryLimits(), false, 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