OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "components/view_manager/surfaces/surfaces_context_provider.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/bind_helpers.h" | |
9 #include "base/synchronization/waitable_event.h" | |
10 #include "components/view_manager/gles2/command_buffer_driver.h" | |
11 #include "components/view_manager/gles2/command_buffer_impl.h" | |
12 #include "components/view_manager/gles2/command_buffer_local.h" | |
13 #include "components/view_manager/gles2/gpu_state.h" | |
14 #include "components/view_manager/surfaces/surfaces_context_provider_delegate.h" | |
15 #include "gpu/command_buffer/client/gles2_cmd_helper.h" | |
16 #include "gpu/command_buffer/client/gles2_implementation.h" | |
17 #include "gpu/command_buffer/client/transfer_buffer.h" | |
18 | |
19 namespace surfaces { | |
20 | |
21 namespace { | |
22 const size_t kDefaultCommandBufferSize = 1024 * 1024; | |
23 const size_t kDefaultStartTransferBufferSize = 1 * 1024 * 1024; | |
24 const size_t kDefaultMinTransferBufferSize = 1 * 256 * 1024; | |
25 const size_t kDefaultMaxTransferBufferSize = 16 * 1024 * 1024; | |
26 | |
27 } | |
28 | |
29 SurfacesContextProvider::SurfacesContextProvider( | |
30 SurfacesContextProviderDelegate* delegate, | |
31 gfx::AcceleratedWidget widget, | |
32 const scoped_refptr<gles2::GpuState>& state) | |
33 : delegate_(delegate), | |
34 state_(state), | |
35 widget_(widget) { | |
36 capabilities_.gpu.image = true; | |
37 command_buffer_local_.reset( | |
38 new gles2::CommandBufferLocal(this, widget_, state_)); | |
39 } | |
40 | |
41 // This is called when we have an accelerated widget. | |
42 bool SurfacesContextProvider::BindToCurrentThread() { | |
43 // SurfacesContextProvider should always live on the same thread as the | |
44 // View Manager. | |
45 DCHECK(CalledOnValidThread()); | |
46 if (!command_buffer_local_->Initialize()) | |
47 return false; | |
48 gles2_helper_.reset( | |
49 new gpu::gles2::GLES2CmdHelper( | |
50 command_buffer_local_->GetCommandBuffer())); | |
51 if (!gles2_helper_->Initialize(kDefaultCommandBufferSize)) | |
52 return false; | |
53 gles2_helper_->SetAutomaticFlushes(false); | |
54 transfer_buffer_.reset(new gpu::TransferBuffer(gles2_helper_.get())); | |
55 gpu::Capabilities capabilities = command_buffer_local_->GetCapabilities(); | |
56 bool bind_generates_resource = | |
57 !!capabilities.bind_generates_resource_chromium; | |
58 // TODO(piman): Some contexts (such as compositor) want this to be true, so | |
59 // this needs to be a public parameter. | |
60 bool lose_context_when_out_of_memory = false; | |
61 bool support_client_side_arrays = false; | |
62 implementation_.reset( | |
63 new gpu::gles2::GLES2Implementation(gles2_helper_.get(), | |
64 NULL, | |
65 transfer_buffer_.get(), | |
66 bind_generates_resource, | |
67 lose_context_when_out_of_memory, | |
68 support_client_side_arrays, | |
69 command_buffer_local_.get())); | |
70 return implementation_->Initialize(kDefaultStartTransferBufferSize, | |
71 kDefaultMinTransferBufferSize, | |
72 kDefaultMaxTransferBufferSize, | |
73 gpu::gles2::GLES2Implementation::kNoLimit); | |
74 } | |
75 | |
76 gpu::gles2::GLES2Interface* SurfacesContextProvider::ContextGL() { | |
77 return implementation_.get(); | |
78 } | |
79 | |
80 gpu::ContextSupport* SurfacesContextProvider::ContextSupport() { | |
81 return implementation_.get(); | |
82 } | |
83 | |
84 class GrContext* SurfacesContextProvider::GrContext() { | |
85 return NULL; | |
86 } | |
87 | |
88 void SurfacesContextProvider::InvalidateGrContext(uint32_t state) { | |
89 } | |
90 | |
91 cc::ContextProvider::Capabilities | |
92 SurfacesContextProvider::ContextCapabilities() { | |
93 return capabilities_; | |
94 } | |
95 | |
96 void SurfacesContextProvider::SetupLock() { | |
97 } | |
98 | |
99 base::Lock* SurfacesContextProvider::GetLock() { | |
100 return &context_lock_; | |
101 } | |
102 | |
103 bool SurfacesContextProvider::DestroyedOnMainThread() { | |
104 return !command_buffer_local_; | |
105 } | |
106 | |
107 void SurfacesContextProvider::SetLostContextCallback( | |
108 const LostContextCallback& lost_context_callback) { | |
109 lost_context_callback_ = lost_context_callback; | |
110 } | |
111 | |
112 SurfacesContextProvider::~SurfacesContextProvider() { | |
113 implementation_->Flush(); | |
114 implementation_.reset(); | |
115 transfer_buffer_.reset(); | |
116 gles2_helper_.reset(); | |
117 command_buffer_local_.reset(); | |
118 } | |
119 | |
120 void SurfacesContextProvider::UpdateVSyncParameters(int64_t timebase, | |
121 int64_t interval) { | |
122 if (delegate_) | |
123 delegate_->OnVSyncParametersUpdated(timebase, interval); | |
124 } | |
125 | |
126 void SurfacesContextProvider::DidLoseContext() { | |
127 lost_context_callback_.Run(); | |
128 } | |
129 | |
130 } // namespace surfaces | |
OLD | NEW |