OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "gpu/command_buffer/tests/gl_manager.h" | 5 #include "gpu/command_buffer/tests/gl_manager.h" |
6 | 6 |
7 #include <GLES2/gl2.h> | 7 #include <GLES2/gl2.h> |
8 #include <GLES2/gl2ext.h> | 8 #include <GLES2/gl2ext.h> |
9 #include <GLES2/gl2extchromium.h> | 9 #include <GLES2/gl2extchromium.h> |
10 #include <stddef.h> | 10 #include <stddef.h> |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "gpu/command_buffer/client/gles2_implementation.h" | 22 #include "gpu/command_buffer/client/gles2_implementation.h" |
23 #include "gpu/command_buffer/client/gles2_lib.h" | 23 #include "gpu/command_buffer/client/gles2_lib.h" |
24 #include "gpu/command_buffer/client/shared_memory_limits.h" | 24 #include "gpu/command_buffer/client/shared_memory_limits.h" |
25 #include "gpu/command_buffer/client/transfer_buffer.h" | 25 #include "gpu/command_buffer/client/transfer_buffer.h" |
26 #include "gpu/command_buffer/common/constants.h" | 26 #include "gpu/command_buffer/common/constants.h" |
27 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 27 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
28 #include "gpu/command_buffer/common/sync_token.h" | 28 #include "gpu/command_buffer/common/sync_token.h" |
29 #include "gpu/command_buffer/service/command_buffer_service.h" | 29 #include "gpu/command_buffer/service/command_buffer_service.h" |
30 #include "gpu/command_buffer/service/command_executor.h" | 30 #include "gpu/command_buffer/service/command_executor.h" |
31 #include "gpu/command_buffer/service/context_group.h" | 31 #include "gpu/command_buffer/service/context_group.h" |
| 32 #include "gpu/command_buffer/service/fence_manager.h" |
32 #include "gpu/command_buffer/service/gl_context_virtual.h" | 33 #include "gpu/command_buffer/service/gl_context_virtual.h" |
33 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 34 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
34 #include "gpu/command_buffer/service/image_manager.h" | 35 #include "gpu/command_buffer/service/image_manager.h" |
35 #include "gpu/command_buffer/service/mailbox_manager_impl.h" | 36 #include "gpu/command_buffer/service/mailbox_manager_impl.h" |
36 #include "gpu/command_buffer/service/memory_tracking.h" | 37 #include "gpu/command_buffer/service/memory_tracking.h" |
37 #include "gpu/command_buffer/service/service_utils.h" | 38 #include "gpu/command_buffer/service/service_utils.h" |
38 #include "gpu/command_buffer/service/sync_point_manager.h" | 39 #include "gpu/command_buffer/service/sync_point_manager.h" |
39 #include "gpu/command_buffer/service/transfer_buffer_manager.h" | 40 #include "gpu/command_buffer/service/transfer_buffer_manager.h" |
40 #include "testing/gtest/include/gtest/gtest.h" | 41 #include "testing/gtest/include/gtest/gtest.h" |
41 #include "ui/gfx/buffer_format_util.h" | 42 #include "ui/gfx/buffer_format_util.h" |
| 43 #include "ui/gfx/gpu_fence.h" |
42 #include "ui/gfx/gpu_memory_buffer.h" | 44 #include "ui/gfx/gpu_memory_buffer.h" |
| 45 #include "ui/gfx/shared_event.h" |
43 #include "ui/gl/gl_context.h" | 46 #include "ui/gl/gl_context.h" |
| 47 #include "ui/gl/gl_fence_shared_event.h" |
44 #include "ui/gl/gl_image_ref_counted_memory.h" | 48 #include "ui/gl/gl_image_ref_counted_memory.h" |
45 #include "ui/gl/gl_share_group.h" | 49 #include "ui/gl/gl_share_group.h" |
46 #include "ui/gl/gl_surface.h" | 50 #include "ui/gl/gl_surface.h" |
47 #include "ui/gl/init/gl_factory.h" | 51 #include "ui/gl/init/gl_factory.h" |
48 | 52 |
49 #if defined(OS_MACOSX) | 53 #if defined(OS_MACOSX) |
50 #include "ui/gfx/mac/io_surface.h" | 54 #include "ui/gfx/mac/io_surface.h" |
51 #include "ui/gl/gl_image_io_surface.h" | 55 #include "ui/gl/gl_image_io_surface.h" |
52 #endif | 56 #endif |
53 | 57 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 IOSurfaceRef iosurface() { return iosurface_; } | 166 IOSurfaceRef iosurface() { return iosurface_; } |
163 | 167 |
164 private: | 168 private: |
165 bool mapped_; | 169 bool mapped_; |
166 IOSurfaceRef iosurface_; | 170 IOSurfaceRef iosurface_; |
167 const gfx::Size size_; | 171 const gfx::Size size_; |
168 gfx::BufferFormat format_; | 172 gfx::BufferFormat format_; |
169 }; | 173 }; |
170 #endif // defined(OS_MACOSX) | 174 #endif // defined(OS_MACOSX) |
171 | 175 |
| 176 class GpuFenceImpl : public gfx::GpuFence { |
| 177 public: |
| 178 GpuFenceImpl() {} |
| 179 explicit GpuFenceImpl(const gfx::GpuFenceHandle& handle) |
| 180 : shared_event_(handle.shared_event_handle) {} |
| 181 ~GpuFenceImpl() override {} |
| 182 |
| 183 static GpuFenceImpl* FromClientFence(ClientFence fence) { |
| 184 return reinterpret_cast<GpuFenceImpl*>(fence); |
| 185 } |
| 186 |
| 187 // Overridden from gfx::GpuFence: |
| 188 bool IsSignaled() override { return shared_event_.IsSignaled(); } |
| 189 bool Wait(const base::TimeDelta& max_time) override { |
| 190 return shared_event_.Wait(max_time); |
| 191 } |
| 192 void Reset() override { shared_event_.Reset(); } |
| 193 gfx::GpuFenceHandle GetHandle() const override { |
| 194 gfx::GpuFenceHandle handle; |
| 195 handle.shared_event_handle = shared_event_.GetHandle(); |
| 196 return handle; |
| 197 } |
| 198 ClientFence AsClientFence() override { |
| 199 return reinterpret_cast<ClientFence>(this); |
| 200 } |
| 201 |
| 202 private: |
| 203 gfx::SharedEvent shared_event_; |
| 204 }; |
| 205 |
172 } // namespace | 206 } // namespace |
173 | 207 |
174 int GLManager::use_count_; | 208 int GLManager::use_count_; |
175 scoped_refptr<gl::GLShareGroup>* GLManager::base_share_group_; | 209 scoped_refptr<gl::GLShareGroup>* GLManager::base_share_group_; |
176 scoped_refptr<gl::GLSurface>* GLManager::base_surface_; | 210 scoped_refptr<gl::GLSurface>* GLManager::base_surface_; |
177 scoped_refptr<gl::GLContext>* GLManager::base_context_; | 211 scoped_refptr<gl::GLContext>* GLManager::base_context_; |
178 | 212 |
179 GLManager::Options::Options() | 213 GLManager::Options::Options() |
180 : size(4, 4), | 214 : size(4, 4), |
181 sync_point_manager(NULL), | 215 sync_point_manager(NULL), |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 return base::WrapUnique<gfx::GpuMemoryBuffer>( | 263 return base::WrapUnique<gfx::GpuMemoryBuffer>( |
230 new IOSurfaceGpuMemoryBuffer(size, format)); | 264 new IOSurfaceGpuMemoryBuffer(size, format)); |
231 } | 265 } |
232 #endif // defined(OS_MACOSX) | 266 #endif // defined(OS_MACOSX) |
233 std::vector<uint8_t> data(gfx::BufferSizeForBufferFormat(size, format), 0); | 267 std::vector<uint8_t> data(gfx::BufferSizeForBufferFormat(size, format), 0); |
234 scoped_refptr<base::RefCountedBytes> bytes(new base::RefCountedBytes(data)); | 268 scoped_refptr<base::RefCountedBytes> bytes(new base::RefCountedBytes(data)); |
235 return base::WrapUnique<gfx::GpuMemoryBuffer>( | 269 return base::WrapUnique<gfx::GpuMemoryBuffer>( |
236 new GpuMemoryBufferImpl(bytes.get(), size, format)); | 270 new GpuMemoryBufferImpl(bytes.get(), size, format)); |
237 } | 271 } |
238 | 272 |
| 273 std::unique_ptr<gfx::GpuFence> GLManager::CreateGpuFence() { |
| 274 return base::WrapUnique<gfx::GpuFence>(new GpuFenceImpl); |
| 275 } |
| 276 |
239 void GLManager::Initialize(const GLManager::Options& options) { | 277 void GLManager::Initialize(const GLManager::Options& options) { |
240 InitializeWithCommandLine(options, *base::CommandLine::ForCurrentProcess()); | 278 InitializeWithCommandLine(options, *base::CommandLine::ForCurrentProcess()); |
241 } | 279 } |
242 | 280 |
243 void GLManager::InitializeWithCommandLine( | 281 void GLManager::InitializeWithCommandLine( |
244 const GLManager::Options& options, | 282 const GLManager::Options& options, |
245 const base::CommandLine& command_line) { | 283 const base::CommandLine& command_line) { |
246 const int32_t kCommandBufferSize = 1024 * 1024; | 284 const int32_t kCommandBufferSize = 1024 * 1024; |
247 const size_t kStartTransferBufferSize = 4 * 1024 * 1024; | 285 const size_t kStartTransferBufferSize = 4 * 1024 * 1024; |
248 const size_t kMinTransferBufferSize = 1 * 256 * 1024; | 286 const size_t kMinTransferBufferSize = 1 * 256 * 1024; |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 } | 672 } |
635 | 673 |
636 // Something went wrong, just run the callback now. | 674 // Something went wrong, just run the callback now. |
637 callback.Run(); | 675 callback.Run(); |
638 } | 676 } |
639 | 677 |
640 bool GLManager::CanWaitUnverifiedSyncToken(const gpu::SyncToken* sync_token) { | 678 bool GLManager::CanWaitUnverifiedSyncToken(const gpu::SyncToken* sync_token) { |
641 return false; | 679 return false; |
642 } | 680 } |
643 | 681 |
| 682 int32_t GLManager::CreateFence(ClientFence fence) { |
| 683 GpuFenceImpl* gpu_fence = GpuFenceImpl::FromClientFence(fence); |
| 684 |
| 685 gfx::GpuFenceHandle handle = gpu_fence->GetHandle(); |
| 686 std::unique_ptr<gl::GLFenceSharedEvent> gl_fence(new gl::GLFenceSharedEvent( |
| 687 gfx::SharedEvent::DuplicateHandle(handle.shared_event_handle))); |
| 688 |
| 689 static int32_t next_id = 1; |
| 690 int32_t new_id = next_id++; |
| 691 gpu::gles2::FenceManager* fence_manager = decoder_->GetFenceManager(); |
| 692 DCHECK(fence_manager); |
| 693 fence_manager->AddFence(std::move(gl_fence), new_id); |
| 694 return new_id; |
| 695 } |
| 696 |
| 697 void GLManager::DestroyFence(int32_t id) { |
| 698 gpu::gles2::FenceManager* fence_manager = decoder_->GetFenceManager(); |
| 699 DCHECK(fence_manager); |
| 700 fence_manager->RemoveFence(id); |
| 701 } |
| 702 |
644 } // namespace gpu | 703 } // namespace gpu |
OLD | NEW |