OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "mojo/services/gles2/command_buffer_impl.h" | 5 #include "mojo/services/gles2/command_buffer_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/shared_memory.h" | 8 #include "base/memory/shared_memory.h" |
9 | 9 |
10 #include "gpu/command_buffer/common/constants.h" | 10 #include "gpu/command_buffer/common/constants.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 }; | 38 }; |
39 | 39 |
40 private: | 40 private: |
41 virtual ~MemoryTrackerStub() {} | 41 virtual ~MemoryTrackerStub() {} |
42 | 42 |
43 DISALLOW_COPY_AND_ASSIGN(MemoryTrackerStub); | 43 DISALLOW_COPY_AND_ASSIGN(MemoryTrackerStub); |
44 }; | 44 }; |
45 | 45 |
46 } // anonymous namespace | 46 } // anonymous namespace |
47 | 47 |
48 CommandBufferImpl::CommandBufferImpl( | 48 CommandBufferImpl::CommandBufferImpl(gfx::AcceleratedWidget widget, |
49 gfx::GLShareGroup* share_group, | 49 const gfx::Size& size) |
50 gpu::gles2::MailboxManager* mailbox_manager) | 50 : widget_(widget), size_(size) {} |
51 : widget_(gfx::kNullAcceleratedWidget), | |
52 size_(1, 1), | |
53 share_group_(share_group), | |
54 mailbox_manager_(mailbox_manager) { | |
55 } | |
56 | |
57 CommandBufferImpl::CommandBufferImpl( | |
58 gfx::AcceleratedWidget widget, | |
59 const gfx::Size& size, | |
60 gfx::GLShareGroup* share_group, | |
61 gpu::gles2::MailboxManager* mailbox_manager) | |
62 : widget_(widget), | |
63 size_(size), | |
64 share_group_(share_group), | |
65 mailbox_manager_(mailbox_manager) { | |
66 } | |
67 | 51 |
68 CommandBufferImpl::~CommandBufferImpl() { | 52 CommandBufferImpl::~CommandBufferImpl() { |
69 client()->DidDestroy(); | 53 client()->DidDestroy(); |
70 if (decoder_) { | 54 if (decoder_) { |
71 bool have_context = decoder_->MakeCurrent(); | 55 bool have_context = decoder_->MakeCurrent(); |
72 decoder_->Destroy(have_context); | 56 decoder_->Destroy(have_context); |
73 } | 57 } |
74 } | 58 } |
75 | 59 |
76 void CommandBufferImpl::Initialize( | 60 void CommandBufferImpl::Initialize( |
77 CommandBufferSyncClientPtr sync_client, | 61 CommandBufferSyncClientPtr sync_client, |
78 mojo::ScopedSharedBufferHandle shared_state) { | 62 mojo::ScopedSharedBufferHandle shared_state) { |
79 sync_client_ = sync_client.Pass(); | 63 sync_client_ = sync_client.Pass(); |
80 sync_client_->DidInitialize(DoInitialize(shared_state.Pass())); | 64 sync_client_->DidInitialize(DoInitialize(shared_state.Pass())); |
81 } | 65 } |
82 | 66 |
83 bool CommandBufferImpl::DoInitialize( | 67 bool CommandBufferImpl::DoInitialize( |
84 mojo::ScopedSharedBufferHandle shared_state) { | 68 mojo::ScopedSharedBufferHandle shared_state) { |
85 if (widget_ == gfx::kNullAcceleratedWidget) | 69 // TODO(piman): offscreen surface. |
86 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(size_); | 70 surface_ = gfx::GLSurface::CreateViewGLSurface(widget_); |
87 else | |
88 surface_ = gfx::GLSurface::CreateViewGLSurface(widget_); | |
89 if (!surface_.get()) | 71 if (!surface_.get()) |
90 return false; | 72 return false; |
91 | 73 |
92 // TODO(piman): virtual contexts, gpu preference. | 74 // TODO(piman): context sharing, virtual contexts, gpu preference. |
93 context_ = gfx::GLContext::CreateGLContext( | 75 scoped_refptr<gfx::GLContext> context = gfx::GLContext::CreateGLContext( |
94 share_group_, surface_.get(), gfx::PreferIntegratedGpu); | 76 NULL, surface_.get(), gfx::PreferIntegratedGpu); |
95 if (!context_.get()) | 77 if (!context.get()) |
96 return false; | 78 return false; |
97 | 79 |
98 if (!context_->MakeCurrent(surface_.get())) | 80 if (!context->MakeCurrent(surface_.get())) |
99 return false; | 81 return false; |
100 | 82 |
101 // TODO(piman): ShaderTranslatorCache is currently per-ContextGroup but | 83 // TODO(piman): ShaderTranslatorCache is currently per-ContextGroup but |
102 // only needs to be per-thread. | 84 // only needs to be per-thread. |
103 scoped_refptr<gpu::gles2::ContextGroup> context_group = | 85 scoped_refptr<gpu::gles2::ContextGroup> context_group = |
104 new gpu::gles2::ContextGroup(mailbox_manager_, | 86 new gpu::gles2::ContextGroup(NULL, |
105 new MemoryTrackerStub, | 87 new MemoryTrackerStub, |
106 new gpu::gles2::ShaderTranslatorCache, | 88 new gpu::gles2::ShaderTranslatorCache, |
107 NULL, | 89 NULL, |
108 true); | 90 true); |
109 | 91 |
110 command_buffer_.reset( | 92 command_buffer_.reset( |
111 new gpu::CommandBufferService(context_group->transfer_buffer_manager())); | 93 new gpu::CommandBufferService(context_group->transfer_buffer_manager())); |
112 bool result = command_buffer_->Initialize(); | 94 bool result = command_buffer_->Initialize(); |
113 DCHECK(result); | 95 DCHECK(result); |
114 | 96 |
115 decoder_.reset(::gpu::gles2::GLES2Decoder::Create(context_group.get())); | 97 decoder_.reset(::gpu::gles2::GLES2Decoder::Create(context_group.get())); |
116 scheduler_.reset(new gpu::GpuScheduler( | 98 scheduler_.reset(new gpu::GpuScheduler( |
117 command_buffer_.get(), decoder_.get(), decoder_.get())); | 99 command_buffer_.get(), decoder_.get(), decoder_.get())); |
118 decoder_->set_engine(scheduler_.get()); | 100 decoder_->set_engine(scheduler_.get()); |
119 decoder_->SetResizeCallback( | 101 decoder_->SetResizeCallback( |
120 base::Bind(&CommandBufferImpl::OnResize, base::Unretained(this))); | 102 base::Bind(&CommandBufferImpl::OnResize, base::Unretained(this))); |
121 | 103 |
122 gpu::gles2::DisallowedFeatures disallowed_features; | 104 gpu::gles2::DisallowedFeatures disallowed_features; |
123 | 105 |
124 // TODO(piman): attributes. | 106 // TODO(piman): attributes. |
125 std::vector<int32> attrib_vector; | 107 std::vector<int32> attrib_vector; |
126 if (!decoder_->Initialize(surface_, | 108 if (!decoder_->Initialize(surface_, |
127 context_, | 109 context, |
128 false /* offscreen */, | 110 false /* offscreen */, |
129 size_, | 111 size_, |
130 disallowed_features, | 112 disallowed_features, |
131 attrib_vector)) | 113 attrib_vector)) |
132 return false; | 114 return false; |
133 | 115 |
134 command_buffer_->SetPutOffsetChangeCallback(base::Bind( | 116 command_buffer_->SetPutOffsetChangeCallback(base::Bind( |
135 &gpu::GpuScheduler::PutChanged, base::Unretained(scheduler_.get()))); | 117 &gpu::GpuScheduler::PutChanged, base::Unretained(scheduler_.get()))); |
136 command_buffer_->SetGetBufferChangeCallback(base::Bind( | 118 command_buffer_->SetGetBufferChangeCallback(base::Bind( |
137 &gpu::GpuScheduler::SetGetBuffer, base::Unretained(scheduler_.get()))); | 119 &gpu::GpuScheduler::SetGetBuffer, base::Unretained(scheduler_.get()))); |
(...skipping 10 matching lines...) Expand all Loading... |
148 | 130 |
149 command_buffer_->SetSharedStateBuffer(backing.Pass()); | 131 command_buffer_->SetSharedStateBuffer(backing.Pass()); |
150 return true; | 132 return true; |
151 } | 133 } |
152 | 134 |
153 void CommandBufferImpl::SetGetBuffer(int32_t buffer) { | 135 void CommandBufferImpl::SetGetBuffer(int32_t buffer) { |
154 command_buffer_->SetGetBuffer(buffer); | 136 command_buffer_->SetGetBuffer(buffer); |
155 } | 137 } |
156 | 138 |
157 void CommandBufferImpl::Flush(int32_t put_offset) { | 139 void CommandBufferImpl::Flush(int32_t put_offset) { |
158 if (!context_->MakeCurrent(surface_.get())) { | |
159 DLOG(WARNING) << "Context lost"; | |
160 client()->LostContext(gpu::error::kUnknown); | |
161 return; | |
162 } | |
163 command_buffer_->Flush(put_offset); | 140 command_buffer_->Flush(put_offset); |
164 } | 141 } |
165 | 142 |
166 void CommandBufferImpl::MakeProgress(int32_t last_get_offset) { | 143 void CommandBufferImpl::MakeProgress(int32_t last_get_offset) { |
167 // TODO(piman): handle out-of-order. | 144 // TODO(piman): handle out-of-order. |
168 sync_client_->DidMakeProgress( | 145 sync_client_->DidMakeProgress( |
169 CommandBufferState::From(command_buffer_->GetLastState())); | 146 CommandBufferState::From(command_buffer_->GetLastState())); |
170 } | 147 } |
171 | 148 |
172 void CommandBufferImpl::RegisterTransferBuffer( | 149 void CommandBufferImpl::RegisterTransferBuffer( |
(...skipping 22 matching lines...) Expand all Loading... |
195 void CommandBufferImpl::OnParseError() { | 172 void CommandBufferImpl::OnParseError() { |
196 gpu::CommandBuffer::State state = command_buffer_->GetLastState(); | 173 gpu::CommandBuffer::State state = command_buffer_->GetLastState(); |
197 client()->LostContext(state.context_lost_reason); | 174 client()->LostContext(state.context_lost_reason); |
198 } | 175 } |
199 | 176 |
200 void CommandBufferImpl::OnResize(gfx::Size size, float scale_factor) { | 177 void CommandBufferImpl::OnResize(gfx::Size size, float scale_factor) { |
201 surface_->Resize(size); | 178 surface_->Resize(size); |
202 } | 179 } |
203 | 180 |
204 } // namespace mojo | 181 } // namespace mojo |
OLD | NEW |