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