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/command_line.h" |
9 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
10 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
11 #include "cc/output/context_cache_controller.h" | 12 #include "cc/output/context_cache_controller.h" |
12 #include "cc/output/managed_memory_policy.h" | 13 #include "cc/output/managed_memory_policy.h" |
13 #include "gpu/command_buffer/client/gles2_implementation.h" | 14 #include "gpu/command_buffer/client/gles2_implementation.h" |
14 #include "gpu/command_buffer/client/gles2_lib.h" | 15 #include "gpu/command_buffer/client/gles2_lib.h" |
| 16 #include "gpu/command_buffer/client/gles2_trace_implementation.h" |
| 17 #include "gpu/command_buffer/client/gpu_switches.h" |
15 #include "gpu/command_buffer/client/shared_memory_limits.h" | 18 #include "gpu/command_buffer/client/shared_memory_limits.h" |
16 #include "gpu/ipc/gl_in_process_context.h" | 19 #include "gpu/ipc/gl_in_process_context.h" |
17 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h" | 20 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h" |
18 #include "third_party/skia/include/gpu/GrContext.h" | 21 #include "third_party/skia/include/gpu/GrContext.h" |
19 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" | 22 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" |
20 | 23 |
21 namespace android_webview { | 24 namespace android_webview { |
22 | 25 |
23 // static | 26 // static |
24 scoped_refptr<AwRenderThreadContextProvider> | 27 scoped_refptr<AwRenderThreadContextProvider> |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 limits.min_transfer_buffer_size = 64 * 1024; | 65 limits.min_transfer_buffer_size = 64 * 1024; |
63 | 66 |
64 context_.reset(gpu::GLInProcessContext::Create( | 67 context_.reset(gpu::GLInProcessContext::Create( |
65 service, surface, surface->IsOffscreen(), gpu::kNullSurfaceHandle, | 68 service, surface, surface->IsOffscreen(), gpu::kNullSurfaceHandle, |
66 nullptr /* share_context */, attributes, limits, nullptr, nullptr, | 69 nullptr /* share_context */, attributes, limits, nullptr, nullptr, |
67 nullptr)); | 70 nullptr)); |
68 | 71 |
69 context_->GetImplementation()->SetLostContextCallback(base::Bind( | 72 context_->GetImplementation()->SetLostContextCallback(base::Bind( |
70 &AwRenderThreadContextProvider::OnLostContext, base::Unretained(this))); | 73 &AwRenderThreadContextProvider::OnLostContext, base::Unretained(this))); |
71 | 74 |
| 75 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 76 switches::kEnableGpuClientTracing)) { |
| 77 // This wraps the real GLES2Implementation and we should always use this |
| 78 // instead when it's present. |
| 79 trace_impl_.reset(new gpu::gles2::GLES2TraceImplementation( |
| 80 context_->GetImplementation())); |
| 81 } |
| 82 |
72 cache_controller_.reset( | 83 cache_controller_.reset( |
73 new cc::ContextCacheController(context_->GetImplementation(), nullptr)); | 84 new cc::ContextCacheController(context_->GetImplementation(), nullptr)); |
74 } | 85 } |
75 | 86 |
76 AwRenderThreadContextProvider::~AwRenderThreadContextProvider() { | 87 AwRenderThreadContextProvider::~AwRenderThreadContextProvider() { |
77 DCHECK(main_thread_checker_.CalledOnValidThread()); | 88 DCHECK(main_thread_checker_.CalledOnValidThread()); |
78 if (gr_context_) | 89 if (gr_context_) |
79 gr_context_->releaseResourcesAndAbandonContext(); | 90 gr_context_->releaseResourcesAndAbandonContext(); |
80 } | 91 } |
81 | 92 |
82 uint32_t AwRenderThreadContextProvider::GetCopyTextureInternalFormat() { | 93 uint32_t AwRenderThreadContextProvider::GetCopyTextureInternalFormat() { |
83 // The attributes used in the constructor included an alpha channel. | 94 // The attributes used in the constructor included an alpha channel. |
84 return GL_RGBA; | 95 return GL_RGBA; |
85 } | 96 } |
86 | 97 |
87 bool AwRenderThreadContextProvider::BindToCurrentThread() { | 98 bool AwRenderThreadContextProvider::BindToCurrentThread() { |
88 // This is called on the thread the context will be used. | 99 // This is called on the thread the context will be used. |
89 DCHECK(main_thread_checker_.CalledOnValidThread()); | 100 DCHECK(main_thread_checker_.CalledOnValidThread()); |
90 | 101 |
91 return true; | 102 return true; |
92 } | 103 } |
93 | 104 |
94 gpu::Capabilities AwRenderThreadContextProvider::ContextCapabilities() { | 105 gpu::Capabilities AwRenderThreadContextProvider::ContextCapabilities() { |
95 DCHECK(main_thread_checker_.CalledOnValidThread()); | 106 DCHECK(main_thread_checker_.CalledOnValidThread()); |
96 return context_->GetImplementation()->capabilities(); | 107 return context_->GetImplementation()->capabilities(); |
97 } | 108 } |
98 | 109 |
99 gpu::gles2::GLES2Interface* AwRenderThreadContextProvider::ContextGL() { | 110 gpu::gles2::GLES2Interface* AwRenderThreadContextProvider::ContextGL() { |
100 DCHECK(main_thread_checker_.CalledOnValidThread()); | 111 DCHECK(main_thread_checker_.CalledOnValidThread()); |
101 | 112 if (trace_impl_) |
| 113 return trace_impl_.get(); |
102 return context_->GetImplementation(); | 114 return context_->GetImplementation(); |
103 } | 115 } |
104 | 116 |
105 gpu::ContextSupport* AwRenderThreadContextProvider::ContextSupport() { | 117 gpu::ContextSupport* AwRenderThreadContextProvider::ContextSupport() { |
106 DCHECK(main_thread_checker_.CalledOnValidThread()); | 118 DCHECK(main_thread_checker_.CalledOnValidThread()); |
107 | 119 |
108 return context_->GetImplementation(); | 120 return context_->GetImplementation(); |
109 } | 121 } |
110 | 122 |
111 class GrContext* AwRenderThreadContextProvider::GrContext() { | 123 class GrContext* AwRenderThreadContextProvider::GrContext() { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 void AwRenderThreadContextProvider::OnLostContext() { | 161 void AwRenderThreadContextProvider::OnLostContext() { |
150 DCHECK(main_thread_checker_.CalledOnValidThread()); | 162 DCHECK(main_thread_checker_.CalledOnValidThread()); |
151 | 163 |
152 if (!lost_context_callback_.is_null()) | 164 if (!lost_context_callback_.is_null()) |
153 lost_context_callback_.Run(); | 165 lost_context_callback_.Run(); |
154 if (gr_context_) | 166 if (gr_context_) |
155 gr_context_->abandonContext(); | 167 gr_context_->abandonContext(); |
156 } | 168 } |
157 | 169 |
158 } // namespace android_webview | 170 } // namespace android_webview |
OLD | NEW |