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