| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "gpu/command_buffer/client/gles2_implementation.h" | 11 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 12 #include "gpu/command_buffer/client/gles2_lib.h" | 12 #include "gpu/command_buffer/client/gles2_lib.h" |
| 13 #include "gpu/command_buffer/client/transfer_buffer.h" | 13 #include "gpu/command_buffer/client/transfer_buffer.h" |
| 14 #include "gpu/command_buffer/common/constants.h" | 14 #include "gpu/command_buffer/common/constants.h" |
| 15 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
| 15 #include "gpu/command_buffer/service/command_buffer_service.h" | 16 #include "gpu/command_buffer/service/command_buffer_service.h" |
| 16 #include "gpu/command_buffer/service/context_group.h" | 17 #include "gpu/command_buffer/service/context_group.h" |
| 17 #include "gpu/command_buffer/service/gl_context_virtual.h" | 18 #include "gpu/command_buffer/service/gl_context_virtual.h" |
| 18 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 19 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 20 #include "gpu/command_buffer/service/gpu_control_service.h" |
| 19 #include "gpu/command_buffer/service/gpu_scheduler.h" | 21 #include "gpu/command_buffer/service/gpu_scheduler.h" |
| 20 #include "gpu/command_buffer/service/image_manager.h" | 22 #include "gpu/command_buffer/service/image_manager.h" |
| 21 #include "gpu/command_buffer/service/mailbox_manager.h" | 23 #include "gpu/command_buffer/service/mailbox_manager.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 23 #include "ui/gl/gl_context.h" | 25 #include "ui/gl/gl_context.h" |
| 24 #include "ui/gl/gl_share_group.h" | 26 #include "ui/gl/gl_share_group.h" |
| 25 #include "ui/gl/gl_surface.h" | 27 #include "ui/gl/gl_surface.h" |
| 26 | 28 |
| 27 namespace gpu { | 29 namespace gpu { |
| 28 | 30 |
| 29 int GLManager::use_count_; | 31 int GLManager::use_count_; |
| 30 scoped_refptr<gfx::GLShareGroup>* GLManager::base_share_group_; | 32 scoped_refptr<gfx::GLShareGroup>* GLManager::base_share_group_; |
| 31 scoped_refptr<gfx::GLSurface>* GLManager::base_surface_; | 33 scoped_refptr<gfx::GLSurface>* GLManager::base_surface_; |
| 32 scoped_refptr<gfx::GLContext>* GLManager::base_context_; | 34 scoped_refptr<gfx::GLContext>* GLManager::base_context_; |
| 33 | 35 |
| 34 GLManager::Options::Options() | 36 GLManager::Options::Options() |
| 35 : size(4, 4), | 37 : size(4, 4), |
| 36 share_group_manager(NULL), | 38 share_group_manager(NULL), |
| 37 share_mailbox_manager(NULL), | 39 share_mailbox_manager(NULL), |
| 38 virtual_manager(NULL), | 40 virtual_manager(NULL), |
| 39 bind_generates_resource(false), | 41 bind_generates_resource(false), |
| 40 context_lost_allowed(false), | 42 context_lost_allowed(false), |
| 41 image_manager(NULL), | 43 image_manager(NULL) { |
| 42 image_factory(NULL) { | |
| 43 } | 44 } |
| 44 | 45 |
| 45 GLManager::GLManager() | 46 GLManager::GLManager() |
| 46 : context_lost_allowed_(false) { | 47 : context_lost_allowed_(false) { |
| 47 SetupBaseContext(); | 48 SetupBaseContext(); |
| 48 } | 49 } |
| 49 | 50 |
| 50 GLManager::~GLManager() { | 51 GLManager::~GLManager() { |
| 51 --use_count_; | 52 --use_count_; |
| 52 if (!use_count_) { | 53 if (!use_count_) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 context_group = options.share_group_manager->decoder_->GetContextGroup(); | 94 context_group = options.share_group_manager->decoder_->GetContextGroup(); |
| 94 client_share_group = | 95 client_share_group = |
| 95 options.share_group_manager->gles2_implementation()->share_group(); | 96 options.share_group_manager->gles2_implementation()->share_group(); |
| 96 } | 97 } |
| 97 | 98 |
| 98 gfx::GLContext* real_gl_context = NULL; | 99 gfx::GLContext* real_gl_context = NULL; |
| 99 if (options.virtual_manager) { | 100 if (options.virtual_manager) { |
| 100 real_gl_context = options.virtual_manager->context(); | 101 real_gl_context = options.virtual_manager->context(); |
| 101 } | 102 } |
| 102 | 103 |
| 103 // From <EGL/egl.h>. | |
| 104 const int32 EGL_ALPHA_SIZE = 0x3021; | |
| 105 const int32 EGL_BLUE_SIZE = 0x3022; | |
| 106 const int32 EGL_GREEN_SIZE = 0x3023; | |
| 107 const int32 EGL_RED_SIZE = 0x3024; | |
| 108 const int32 EGL_DEPTH_SIZE = 0x3025; | |
| 109 const int32 EGL_NONE = 0x3038; | |
| 110 | |
| 111 mailbox_manager_ = | 104 mailbox_manager_ = |
| 112 mailbox_manager ? mailbox_manager : new gles2::MailboxManager; | 105 mailbox_manager ? mailbox_manager : new gles2::MailboxManager; |
| 113 share_group_ = | 106 share_group_ = |
| 114 share_group ? share_group : new gfx::GLShareGroup; | 107 share_group ? share_group : new gfx::GLShareGroup; |
| 115 | 108 |
| 116 gfx::GpuPreference gpu_preference(gfx::PreferDiscreteGpu); | 109 gfx::GpuPreference gpu_preference(gfx::PreferDiscreteGpu); |
| 117 const char* allowed_extensions = "*"; | 110 const char* allowed_extensions = "*"; |
| 118 std::vector<int32> attribs; | 111 std::vector<int32> attribs; |
| 119 attribs.push_back(EGL_RED_SIZE); | 112 gles2::ContextCreationAttribHelper attrib_helper; |
| 120 attribs.push_back(8); | 113 attrib_helper.red_size_ = 8; |
| 121 attribs.push_back(EGL_GREEN_SIZE); | 114 attrib_helper.green_size_ = 8; |
| 122 attribs.push_back(8); | 115 attrib_helper.blue_size_ = 8; |
| 123 attribs.push_back(EGL_BLUE_SIZE); | 116 attrib_helper.alpha_size_ = 8; |
| 124 attribs.push_back(8); | 117 attrib_helper.depth_size_ = 16; |
| 125 attribs.push_back(EGL_ALPHA_SIZE); | 118 attrib_helper.Serialize(&attribs); |
| 126 attribs.push_back(8); | |
| 127 attribs.push_back(EGL_DEPTH_SIZE); | |
| 128 attribs.push_back(16); | |
| 129 attribs.push_back(EGL_NONE); | |
| 130 | 119 |
| 131 if (!context_group) { | 120 if (!context_group) { |
| 132 context_group = new gles2::ContextGroup(mailbox_manager_.get(), | 121 context_group = new gles2::ContextGroup(mailbox_manager_.get(), |
| 133 options.image_manager, | 122 options.image_manager, |
| 134 NULL, | 123 NULL, |
| 135 NULL, | 124 NULL, |
| 136 options.bind_generates_resource); | 125 options.bind_generates_resource); |
| 137 } | 126 } |
| 138 | 127 |
| 139 decoder_.reset(::gpu::gles2::GLES2Decoder::Create(context_group)); | 128 decoder_.reset(::gpu::gles2::GLES2Decoder::Create(context_group)); |
| 140 | 129 |
| 141 command_buffer_.reset(new CommandBufferService( | 130 command_buffer_.reset(new CommandBufferService( |
| 142 decoder_->GetContextGroup()->transfer_buffer_manager())); | 131 decoder_->GetContextGroup()->transfer_buffer_manager())); |
| 143 ASSERT_TRUE(command_buffer_->Initialize()) | 132 ASSERT_TRUE(command_buffer_->Initialize()) |
| 144 << "could not create command buffer service"; | 133 << "could not create command buffer service"; |
| 145 | 134 |
| 135 gpu_control_.reset( |
| 136 new GpuControlService(decoder_->GetContextGroup()->image_manager(), |
| 137 options.gpu_memory_buffer_factory)); |
| 138 |
| 146 gpu_scheduler_.reset(new GpuScheduler(command_buffer_.get(), | 139 gpu_scheduler_.reset(new GpuScheduler(command_buffer_.get(), |
| 147 decoder_.get(), | 140 decoder_.get(), |
| 148 decoder_.get())); | 141 decoder_.get())); |
| 149 | 142 |
| 150 decoder_->set_engine(gpu_scheduler_.get()); | 143 decoder_->set_engine(gpu_scheduler_.get()); |
| 151 | 144 |
| 152 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(options.size); | 145 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(options.size); |
| 153 ASSERT_TRUE(surface_.get() != NULL) << "could not create offscreen surface"; | 146 ASSERT_TRUE(surface_.get() != NULL) << "could not create offscreen surface"; |
| 154 | 147 |
| 155 if (real_gl_context) { | 148 if (real_gl_context) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 | 186 |
| 194 // Create a transfer buffer. | 187 // Create a transfer buffer. |
| 195 transfer_buffer_.reset(new TransferBuffer(gles2_helper_.get())); | 188 transfer_buffer_.reset(new TransferBuffer(gles2_helper_.get())); |
| 196 | 189 |
| 197 // Create the object exposing the OpenGL API. | 190 // Create the object exposing the OpenGL API. |
| 198 gles2_implementation_.reset(new gles2::GLES2Implementation( | 191 gles2_implementation_.reset(new gles2::GLES2Implementation( |
| 199 gles2_helper_.get(), | 192 gles2_helper_.get(), |
| 200 client_share_group, | 193 client_share_group, |
| 201 transfer_buffer_.get(), | 194 transfer_buffer_.get(), |
| 202 options.bind_generates_resource, | 195 options.bind_generates_resource, |
| 203 options.image_factory)); | 196 gpu_control_.get())); |
| 204 | 197 |
| 205 ASSERT_TRUE(gles2_implementation_->Initialize( | 198 ASSERT_TRUE(gles2_implementation_->Initialize( |
| 206 kStartTransferBufferSize, | 199 kStartTransferBufferSize, |
| 207 kMinTransferBufferSize, | 200 kMinTransferBufferSize, |
| 208 kMaxTransferBufferSize)) << "Could not init GLES2Implementation"; | 201 kMaxTransferBufferSize)) << "Could not init GLES2Implementation"; |
| 209 | 202 |
| 210 MakeCurrent(); | 203 MakeCurrent(); |
| 211 } | 204 } |
| 212 | 205 |
| 213 void GLManager::SetupBaseContext() { | 206 void GLManager::SetupBaseContext() { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 if (!context_lost_allowed_) { | 257 if (!context_lost_allowed_) { |
| 265 ASSERT_EQ(::gpu::error::kNoError, state.error); | 258 ASSERT_EQ(::gpu::error::kNoError, state.error); |
| 266 } | 259 } |
| 267 } | 260 } |
| 268 | 261 |
| 269 bool GLManager::GetBufferChanged(int32 transfer_buffer_id) { | 262 bool GLManager::GetBufferChanged(int32 transfer_buffer_id) { |
| 270 return gpu_scheduler_->SetGetBuffer(transfer_buffer_id); | 263 return gpu_scheduler_->SetGetBuffer(transfer_buffer_id); |
| 271 } | 264 } |
| 272 | 265 |
| 273 } // namespace gpu | 266 } // namespace gpu |
| OLD | NEW |