| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "android_webview/browser/aw_render_thread_context_provider.h" | 5 #include "android_webview/browser/aw_render_thread_context_provider.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| 11 #include "cc/output/managed_memory_policy.h" | 11 #include "cc/output/managed_memory_policy.h" |
| 12 #include "gpu/command_buffer/client/gl_in_process_context.h" | 12 #include "gpu/command_buffer/client/gl_in_process_context.h" |
| 13 #include "gpu/command_buffer/client/gles2_implementation.h" | 13 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 14 #include "gpu/command_buffer/client/gles2_lib.h" | 14 #include "gpu/command_buffer/client/gles2_lib.h" |
| 15 #include "gpu/command_buffer/client/shared_memory_limits.h" | 15 #include "gpu/command_buffer/client/shared_memory_limits.h" |
| 16 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h" | 16 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h" |
| 17 #include "third_party/skia/include/gpu/GrContext.h" | 17 #include "third_party/skia/include/gpu/GrContext.h" |
| 18 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" | 18 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" |
| 19 | 19 |
| 20 namespace android_webview { | 20 namespace android_webview { |
| 21 | 21 |
| 22 // static | 22 // static |
| 23 scoped_refptr<AwRenderThreadContextProvider> | 23 scoped_refptr<AwRenderThreadContextProvider> |
| 24 AwRenderThreadContextProvider::Create( | 24 AwRenderThreadContextProvider::Create( |
| 25 scoped_refptr<gfx::GLSurface> surface, | 25 scoped_refptr<gl::GLSurface> surface, |
| 26 scoped_refptr<gpu::InProcessCommandBuffer::Service> service) { | 26 scoped_refptr<gpu::InProcessCommandBuffer::Service> service) { |
| 27 return new AwRenderThreadContextProvider(surface, service); | 27 return new AwRenderThreadContextProvider(surface, service); |
| 28 } | 28 } |
| 29 | 29 |
| 30 AwRenderThreadContextProvider::AwRenderThreadContextProvider( | 30 AwRenderThreadContextProvider::AwRenderThreadContextProvider( |
| 31 scoped_refptr<gfx::GLSurface> surface, | 31 scoped_refptr<gl::GLSurface> surface, |
| 32 scoped_refptr<gpu::InProcessCommandBuffer::Service> service) { | 32 scoped_refptr<gpu::InProcessCommandBuffer::Service> service) { |
| 33 DCHECK(main_thread_checker_.CalledOnValidThread()); | 33 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 34 | 34 |
| 35 // This is an onscreen context, wrapping the GLSurface given to us from | 35 // This is an onscreen context, wrapping the GLSurface given to us from |
| 36 // the Android OS. The widget we pass here will be ignored since we're | 36 // the Android OS. The widget we pass here will be ignored since we're |
| 37 // providing the GLSurface to the context already. | 37 // providing the GLSurface to the context already. |
| 38 DCHECK(!surface->IsOffscreen()); | 38 DCHECK(!surface->IsOffscreen()); |
| 39 gpu::gles2::ContextCreationAttribHelper attributes; | 39 gpu::gles2::ContextCreationAttribHelper attributes; |
| 40 // The context is wrapping an already allocated surface, so we can't control | 40 // The context is wrapping an already allocated surface, so we can't control |
| 41 // what buffers it has from these attributes. We do expect an alpha and | 41 // what buffers it has from these attributes. We do expect an alpha and |
| (...skipping 14 matching lines...) Expand all Loading... |
| 56 // uploads done with it at all. We choose a small transfer buffer limit | 56 // uploads done with it at all. We choose a small transfer buffer limit |
| 57 // here, the minimums match the display compositor context for the android | 57 // here, the minimums match the display compositor context for the android |
| 58 // browser. We don't set the max since we expect the transfer buffer to be | 58 // browser. We don't set the max since we expect the transfer buffer to be |
| 59 // relatively unused. | 59 // relatively unused. |
| 60 limits.start_transfer_buffer_size = 64 * 1024; | 60 limits.start_transfer_buffer_size = 64 * 1024; |
| 61 limits.min_transfer_buffer_size = 64 * 1024; | 61 limits.min_transfer_buffer_size = 64 * 1024; |
| 62 | 62 |
| 63 context_.reset(gpu::GLInProcessContext::Create( | 63 context_.reset(gpu::GLInProcessContext::Create( |
| 64 service, surface, surface->IsOffscreen(), gfx::kNullAcceleratedWidget, | 64 service, surface, surface->IsOffscreen(), gfx::kNullAcceleratedWidget, |
| 65 surface->GetSize(), nullptr /* share_context */, attributes, | 65 surface->GetSize(), nullptr /* share_context */, attributes, |
| 66 gfx::PreferDiscreteGpu, limits, nullptr, nullptr)); | 66 gl::PreferDiscreteGpu, limits, nullptr, nullptr)); |
| 67 | 67 |
| 68 context_->GetImplementation()->SetLostContextCallback(base::Bind( | 68 context_->GetImplementation()->SetLostContextCallback(base::Bind( |
| 69 &AwRenderThreadContextProvider::OnLostContext, base::Unretained(this))); | 69 &AwRenderThreadContextProvider::OnLostContext, base::Unretained(this))); |
| 70 } | 70 } |
| 71 | 71 |
| 72 AwRenderThreadContextProvider::~AwRenderThreadContextProvider() { | 72 AwRenderThreadContextProvider::~AwRenderThreadContextProvider() { |
| 73 DCHECK(main_thread_checker_.CalledOnValidThread()); | 73 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 74 if (gr_context_) | 74 if (gr_context_) |
| 75 gr_context_->releaseResourcesAndAbandonContext(); | 75 gr_context_->releaseResourcesAndAbandonContext(); |
| 76 } | 76 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 void AwRenderThreadContextProvider::OnLostContext() { | 144 void AwRenderThreadContextProvider::OnLostContext() { |
| 145 DCHECK(main_thread_checker_.CalledOnValidThread()); | 145 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 146 | 146 |
| 147 if (!lost_context_callback_.is_null()) | 147 if (!lost_context_callback_.is_null()) |
| 148 lost_context_callback_.Run(); | 148 lost_context_callback_.Run(); |
| 149 if (gr_context_) | 149 if (gr_context_) |
| 150 gr_context_->abandonContext(); | 150 gr_context_->abandonContext(); |
| 151 } | 151 } |
| 152 | 152 |
| 153 } // namespace android_webview | 153 } // namespace android_webview |
| OLD | NEW |