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/blink/webgraphicscontext3d_impl.h" | 12 #include "gpu/blink/webgraphicscontext3d_impl.h" |
13 #include "gpu/command_buffer/client/gl_in_process_context.h" | 13 #include "gpu/command_buffer/client/gl_in_process_context.h" |
14 #include "gpu/command_buffer/client/gles2_implementation.h" | 14 #include "gpu/command_buffer/client/gles2_implementation.h" |
15 #include "gpu/command_buffer/client/gles2_lib.h" | 15 #include "gpu/command_buffer/client/gles2_lib.h" |
| 16 #include "gpu/command_buffer/client/shared_memory_limits.h" |
16 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h" | 17 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h" |
17 #include "third_party/skia/include/gpu/GrContext.h" | 18 #include "third_party/skia/include/gpu/GrContext.h" |
18 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" | 19 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" |
19 | 20 |
20 namespace android_webview { | 21 namespace android_webview { |
21 | 22 |
22 // static | 23 // static |
23 scoped_refptr<AwRenderThreadContextProvider> | 24 scoped_refptr<AwRenderThreadContextProvider> |
24 AwRenderThreadContextProvider::Create( | 25 AwRenderThreadContextProvider::Create( |
25 scoped_refptr<gfx::GLSurface> surface, | 26 scoped_refptr<gfx::GLSurface> surface, |
(...skipping 17 matching lines...) Expand all Loading... |
43 // having them both in order to integrate its output with the content behind | 44 // having them both in order to integrate its output with the content behind |
44 // it. | 45 // it. |
45 attributes.alpha_size = 8; | 46 attributes.alpha_size = 8; |
46 attributes.stencil_size = 8; | 47 attributes.stencil_size = 8; |
47 // The depth buffer may exist due to having a stencil buffer, but we don't | 48 // The depth buffer may exist due to having a stencil buffer, but we don't |
48 // need one, so use -1 for it. | 49 // need one, so use -1 for it. |
49 attributes.depth_size = -1; | 50 attributes.depth_size = -1; |
50 attributes.samples = 0; | 51 attributes.samples = 0; |
51 attributes.sample_buffers = 0; | 52 attributes.sample_buffers = 0; |
52 attributes.bind_generates_resource = false; | 53 attributes.bind_generates_resource = false; |
| 54 |
| 55 gpu::SharedMemoryLimits limits; |
| 56 // This context is only used for the display compositor, and there are no |
| 57 // uploads done with it at all. We choose a small transfer buffer limit |
| 58 // here, the minimums match the display compositor context for the android |
| 59 // browser. We don't set the max since we expect the transfer buffer to be |
| 60 // relatively unused. |
| 61 limits.start_transfer_buffer_size = 64 * 1024; |
| 62 limits.min_transfer_buffer_size = 64 * 1024; |
| 63 |
53 context_.reset(gpu::GLInProcessContext::Create( | 64 context_.reset(gpu::GLInProcessContext::Create( |
54 service, surface, surface->IsOffscreen(), gfx::kNullAcceleratedWidget, | 65 service, surface, surface->IsOffscreen(), gfx::kNullAcceleratedWidget, |
55 surface->GetSize(), nullptr /* share_context */, attributes, | 66 surface->GetSize(), nullptr /* share_context */, attributes, |
56 gfx::PreferDiscreteGpu, gpu::GLInProcessContextSharedMemoryLimits(), | 67 gfx::PreferDiscreteGpu, limits, nullptr, nullptr)); |
57 nullptr, nullptr)); | |
58 | 68 |
59 context_->GetImplementation()->SetLostContextCallback(base::Bind( | 69 context_->GetImplementation()->SetLostContextCallback(base::Bind( |
60 &AwRenderThreadContextProvider::OnLostContext, base::Unretained(this))); | 70 &AwRenderThreadContextProvider::OnLostContext, base::Unretained(this))); |
61 } | 71 } |
62 | 72 |
63 AwRenderThreadContextProvider::~AwRenderThreadContextProvider() { | 73 AwRenderThreadContextProvider::~AwRenderThreadContextProvider() { |
64 DCHECK(main_thread_checker_.CalledOnValidThread()); | 74 DCHECK(main_thread_checker_.CalledOnValidThread()); |
65 if (gr_context_) | 75 if (gr_context_) |
66 gr_context_->releaseResourcesAndAbandonContext(); | 76 gr_context_->releaseResourcesAndAbandonContext(); |
67 } | 77 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 void AwRenderThreadContextProvider::OnLostContext() { | 150 void AwRenderThreadContextProvider::OnLostContext() { |
141 DCHECK(main_thread_checker_.CalledOnValidThread()); | 151 DCHECK(main_thread_checker_.CalledOnValidThread()); |
142 | 152 |
143 if (!lost_context_callback_.is_null()) | 153 if (!lost_context_callback_.is_null()) |
144 lost_context_callback_.Run(); | 154 lost_context_callback_.Run(); |
145 if (gr_context_) | 155 if (gr_context_) |
146 gr_context_->abandonContext(); | 156 gr_context_->abandonContext(); |
147 } | 157 } |
148 | 158 |
149 } // namespace android_webview | 159 } // namespace android_webview |
OLD | NEW |