| 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 // A class to emulate GLES2 over command buffers. | 5 // A class to emulate GLES2 over command buffers. |
| 6 | 6 |
| 7 #include "gpu/command_buffer/client/gles2_implementation.h" | 7 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 8 | 8 |
| 9 #include <GLES2/gl2.h> | 9 #include <GLES2/gl2.h> |
| 10 #include <GLES2/gl2ext.h> | 10 #include <GLES2/gl2ext.h> |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 #include "base/command_line.h" | 46 #include "base/command_line.h" |
| 47 #include "gpu/command_buffer/client/gpu_switches.h" | 47 #include "gpu/command_buffer/client/gpu_switches.h" |
| 48 #endif | 48 #endif |
| 49 | 49 |
| 50 namespace gpu { | 50 namespace gpu { |
| 51 namespace gles2 { | 51 namespace gles2 { |
| 52 | 52 |
| 53 namespace { | 53 namespace { |
| 54 | 54 |
| 55 // Class that DCHECKs if it is destructed without first having Release called. | 55 // Class that DCHECKs if it is destructed without first having Release called. |
| 56 class ScopedVisibilityImpl : public ContextSupport::ScopedVisibility { | 56 template <typename T> |
| 57 class ScopedContextSupportToken : public T { |
| 57 public: | 58 public: |
| 58 explicit ScopedVisibilityImpl(ContextSupport* context_support) | 59 explicit ScopedContextSupportToken(ContextSupport* context_support) |
| 59 : initial_context_support_(context_support) {} | 60 : initial_context_support_(context_support) {} |
| 60 ~ScopedVisibilityImpl() { DCHECK(!initial_context_support_); } | 61 |
| 62 ~ScopedContextSupportToken() { DCHECK(!initial_context_support_); } |
| 61 | 63 |
| 62 void Release(ContextSupport* context_support) { | 64 void Release(ContextSupport* context_support) { |
| 63 DCHECK_EQ(initial_context_support_, context_support); | 65 DCHECK_EQ(initial_context_support_, context_support); |
| 64 initial_context_support_ = nullptr; | 66 initial_context_support_ = nullptr; |
| 65 } | 67 } |
| 66 | 68 |
| 67 private: | 69 private: |
| 68 const ContextSupport* initial_context_support_; | 70 const ContextSupport* initial_context_support_; |
| 69 }; | 71 }; |
| 70 | 72 |
| 73 using ScopedVisibilityImpl = |
| 74 ScopedContextSupportToken<ContextSupport::ScopedVisibility>; |
| 75 using ScopedBusyImpl = ScopedContextSupportToken<ContextSupport::ScopedBusy>; |
| 76 |
| 71 void CopyRectToBuffer(const void* pixels, | 77 void CopyRectToBuffer(const void* pixels, |
| 72 uint32_t height, | 78 uint32_t height, |
| 73 uint32_t unpadded_row_size, | 79 uint32_t unpadded_row_size, |
| 74 uint32_t pixels_padded_row_size, | 80 uint32_t pixels_padded_row_size, |
| 75 void* buffer, | 81 void* buffer, |
| 76 uint32_t buffer_padded_row_size) { | 82 uint32_t buffer_padded_row_size) { |
| 77 if (height == 0) | 83 if (height == 0) |
| 78 return; | 84 return; |
| 79 const int8_t* source = static_cast<const int8_t*>(pixels); | 85 const int8_t* source = static_cast<const int8_t*>(pixels); |
| 80 int8_t* dest = static_cast<int8_t*>(buffer); | 86 int8_t* dest = static_cast<int8_t*>(buffer); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 94 GLuint ToGLuint(const void* ptr) { | 100 GLuint ToGLuint(const void* ptr) { |
| 95 return static_cast<GLuint>(reinterpret_cast<size_t>(ptr)); | 101 return static_cast<GLuint>(reinterpret_cast<size_t>(ptr)); |
| 96 } | 102 } |
| 97 | 103 |
| 98 static base::StaticAtomicSequenceNumber g_flush_id; | 104 static base::StaticAtomicSequenceNumber g_flush_id; |
| 99 | 105 |
| 100 uint32_t GenerateNextFlushId() { | 106 uint32_t GenerateNextFlushId() { |
| 101 return static_cast<uint32_t>(g_flush_id.GetNext()); | 107 return static_cast<uint32_t>(g_flush_id.GetNext()); |
| 102 } | 108 } |
| 103 | 109 |
| 110 const base::TimeDelta kIdleCallbackDelay = base::TimeDelta::FromSeconds(1); |
| 111 |
| 104 } // anonymous namespace | 112 } // anonymous namespace |
| 105 | 113 |
| 106 #if !defined(_MSC_VER) | 114 #if !defined(_MSC_VER) |
| 107 const size_t GLES2Implementation::kMaxSizeOfSimpleResult; | 115 const size_t GLES2Implementation::kMaxSizeOfSimpleResult; |
| 108 const unsigned int GLES2Implementation::kStartingOffset; | 116 const unsigned int GLES2Implementation::kStartingOffset; |
| 109 #endif | 117 #endif |
| 110 | 118 |
| 111 GLES2Implementation::GLStaticState::GLStaticState() { | 119 GLES2Implementation::GLStaticState::GLStaticState() { |
| 112 } | 120 } |
| 113 | 121 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 #else | 182 #else |
| 175 // Do not use more than 5% of extra shared memory, and do not | 183 // Do not use more than 5% of extra shared memory, and do not |
| 176 // use any extra for memory contrained devices (<=1GB). | 184 // use any extra for memory contrained devices (<=1GB). |
| 177 base::SysInfo::AmountOfPhysicalMemory() > 1024 * 1024 * 1024 | 185 base::SysInfo::AmountOfPhysicalMemory() > 1024 * 1024 * 1024 |
| 178 ? base::saturated_cast<uint32_t>( | 186 ? base::saturated_cast<uint32_t>( |
| 179 base::SysInfo::AmountOfPhysicalMemory() / 20) | 187 base::SysInfo::AmountOfPhysicalMemory() / 20) |
| 180 : 0), | 188 : 0), |
| 181 #endif | 189 #endif |
| 182 current_trace_stack_(0), | 190 current_trace_stack_(0), |
| 183 gpu_control_(gpu_control), | 191 gpu_control_(gpu_control), |
| 192 task_runner_(std::move(task_runner)), |
| 184 capabilities_(gpu_control->GetCapabilities()), | 193 capabilities_(gpu_control->GetCapabilities()), |
| 185 cached_extension_string_(nullptr), | 194 cached_extension_string_(nullptr), |
| 186 weak_ptr_factory_(this) { | 195 weak_ptr_factory_(this) { |
| 187 DCHECK(helper); | 196 DCHECK(helper); |
| 188 DCHECK(transfer_buffer); | 197 DCHECK(transfer_buffer); |
| 189 DCHECK(gpu_control); | 198 DCHECK(gpu_control); |
| 190 | 199 |
| 191 std::stringstream ss; | 200 std::stringstream ss; |
| 192 ss << std::hex << this; | 201 ss << std::hex << this; |
| 193 this_in_hex_ = ss.str(); | 202 this_in_hex_ = ss.str(); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 this, "GLES2Implementation", base::ThreadTaskRunnerHandle::Get()); | 295 this, "GLES2Implementation", base::ThreadTaskRunnerHandle::Get()); |
| 287 } | 296 } |
| 288 | 297 |
| 289 return true; | 298 return true; |
| 290 } | 299 } |
| 291 | 300 |
| 292 GLES2Implementation::~GLES2Implementation() { | 301 GLES2Implementation::~GLES2Implementation() { |
| 293 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | 302 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( |
| 294 this); | 303 this); |
| 295 | 304 |
| 305 CancelIdleCallback(); |
| 306 |
| 296 // Make sure the queries are finished otherwise we'll delete the | 307 // Make sure the queries are finished otherwise we'll delete the |
| 297 // shared memory (mapped_memory_) which will free the memory used | 308 // shared memory (mapped_memory_) which will free the memory used |
| 298 // by the queries. The GPU process when validating that memory is still | 309 // by the queries. The GPU process when validating that memory is still |
| 299 // shared will fail and abort (ie, it will stop running). | 310 // shared will fail and abort (ie, it will stop running). |
| 300 WaitForCmd(); | 311 WaitForCmd(); |
| 301 query_tracker_.reset(); | 312 query_tracker_.reset(); |
| 302 | 313 |
| 303 // GLES2Implementation::Initialize() could fail before allocating | 314 // GLES2Implementation::Initialize() could fail before allocating |
| 304 // reserved_ids_, so we need delete them carefully. | 315 // reserved_ids_, so we need delete them carefully. |
| 305 if (support_client_side_arrays_ && reserved_ids_[0]) { | 316 if (support_client_side_arrays_ && reserved_ids_[0]) { |
| (...skipping 5590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5896 DCHECK(visibility); | 5907 DCHECK(visibility); |
| 5897 DCHECK_GT(num_visible_clients_, 0u); | 5908 DCHECK_GT(num_visible_clients_, 0u); |
| 5898 --num_visible_clients_; | 5909 --num_visible_clients_; |
| 5899 static_cast<ScopedVisibilityImpl*>(visibility.get())->Release(this); | 5910 static_cast<ScopedVisibilityImpl*>(visibility.get())->Release(this); |
| 5900 } | 5911 } |
| 5901 | 5912 |
| 5902 bool GLES2Implementation::AnyClientsVisible() const { | 5913 bool GLES2Implementation::AnyClientsVisible() const { |
| 5903 return num_visible_clients_ > 0; | 5914 return num_visible_clients_ > 0; |
| 5904 } | 5915 } |
| 5905 | 5916 |
| 5917 std::unique_ptr<ContextSupport::ScopedBusy> |
| 5918 GLES2Implementation::ClientBecameBusy() { |
| 5919 base::AutoLock hold(idle_lock_); |
| 5920 DCHECK(is_idle_); |
| 5921 is_idle_ = false; |
| 5922 // Increment the idle callback generation to cancel any pending callbacks. |
| 5923 ++current_idle_callback_generation_; |
| 5924 |
| 5925 return base::MakeUnique<ScopedBusyImpl>(this); |
| 5926 } |
| 5927 |
| 5928 void GLES2Implementation::ClientBecameNotBusy( |
| 5929 std::unique_ptr<ScopedBusy> busy) { |
| 5930 DCHECK(busy); |
| 5931 |
| 5932 base::AutoLock hold(idle_lock_); |
| 5933 DCHECK(!is_idle_); |
| 5934 is_idle_ = true; |
| 5935 |
| 5936 if (idle_callback_ && task_runner_) { |
| 5937 task_runner_->PostDelayedTask( |
| 5938 FROM_HERE, base::Bind(&GLES2Implementation::RunIdleCallback, |
| 5939 weak_ptr_factory_.GetWeakPtr(), |
| 5940 current_idle_callback_generation_), |
| 5941 kIdleCallbackDelay); |
| 5942 } |
| 5943 |
| 5944 static_cast<ScopedBusyImpl*>(busy.get())->Release(this); |
| 5945 } |
| 5946 |
| 5947 void GLES2Implementation::SetIdleCallback(const base::Closure& callback) { |
| 5948 base::AutoLock hold(idle_lock_); |
| 5949 idle_callback_ = callback; |
| 5950 } |
| 5951 |
| 5906 void GLES2Implementation::SetLostContextCallback( | 5952 void GLES2Implementation::SetLostContextCallback( |
| 5907 const base::Closure& callback) { | 5953 const base::Closure& callback) { |
| 5908 lost_context_callback_ = callback; | 5954 lost_context_callback_ = callback; |
| 5909 } | 5955 } |
| 5910 | 5956 |
| 5911 GLuint64 GLES2Implementation::InsertFenceSyncCHROMIUM() { | 5957 GLuint64 GLES2Implementation::InsertFenceSyncCHROMIUM() { |
| 5912 const uint64_t release = gpu_control_->GenerateFenceSyncRelease(); | 5958 const uint64_t release = gpu_control_->GenerateFenceSyncRelease(); |
| 5913 helper_->InsertFenceSyncCHROMIUM(release); | 5959 helper_->InsertFenceSyncCHROMIUM(release); |
| 5914 return release; | 5960 return release; |
| 5915 } | 5961 } |
| (...skipping 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6930 return; | 6976 return; |
| 6931 } | 6977 } |
| 6932 GetStringHelper(GL_EXTENSIONS); | 6978 GetStringHelper(GL_EXTENSIONS); |
| 6933 } | 6979 } |
| 6934 | 6980 |
| 6935 void GLES2Implementation::InvalidateCachedExtensions() { | 6981 void GLES2Implementation::InvalidateCachedExtensions() { |
| 6936 cached_extension_string_ = nullptr; | 6982 cached_extension_string_ = nullptr; |
| 6937 cached_extensions_.clear(); | 6983 cached_extensions_.clear(); |
| 6938 } | 6984 } |
| 6939 | 6985 |
| 6986 void GLES2Implementation::RunIdleCallback(uint32_t callback_generation) const { |
| 6987 base::AutoLock hold(idle_lock_); |
| 6988 |
| 6989 if (!idle_callback_) |
| 6990 return; |
| 6991 if (callback_generation != current_idle_callback_generation_) |
| 6992 return; |
| 6993 |
| 6994 idle_callback_.Run(); |
| 6995 } |
| 6996 |
| 6997 void GLES2Implementation::CancelIdleCallback() { |
| 6998 base::AutoLock hold(idle_lock_); |
| 6999 ++current_idle_callback_generation_; |
| 7000 } |
| 7001 |
| 6940 // Include the auto-generated part of this file. We split this because it means | 7002 // Include the auto-generated part of this file. We split this because it means |
| 6941 // we can easily edit the non-auto generated parts right here in this file | 7003 // we can easily edit the non-auto generated parts right here in this file |
| 6942 // instead of having to edit some template or the code generator. | 7004 // instead of having to edit some template or the code generator. |
| 6943 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" | 7005 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" |
| 6944 | 7006 |
| 6945 } // namespace gles2 | 7007 } // namespace gles2 |
| 6946 } // namespace gpu | 7008 } // namespace gpu |
| OLD | NEW |