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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 uint32_t size = (height - 1) * pixels_padded_row_size + unpadded_row_size; | 69 uint32_t size = (height - 1) * pixels_padded_row_size + unpadded_row_size; |
70 memcpy(dest, source, size); | 70 memcpy(dest, source, size); |
71 } | 71 } |
72 } | 72 } |
73 | 73 |
74 // A 32-bit and 64-bit compatible way of converting a pointer to a GLuint. | 74 // A 32-bit and 64-bit compatible way of converting a pointer to a GLuint. |
75 GLuint ToGLuint(const void* ptr) { | 75 GLuint ToGLuint(const void* ptr) { |
76 return static_cast<GLuint>(reinterpret_cast<size_t>(ptr)); | 76 return static_cast<GLuint>(reinterpret_cast<size_t>(ptr)); |
77 } | 77 } |
78 | 78 |
79 uint32_t GenerateNextFlushId() { | |
piman
2016/03/16 22:53:46
Should we use StaticAtomicSequenceNumber instead?
| |
80 static base::subtle::Atomic32 flush_id = 0; | |
81 base::subtle::Atomic32 my_id = | |
82 base::subtle::Barrier_AtomicIncrement(&flush_id, 1); | |
83 return static_cast<uint32_t>(my_id); | |
84 } | |
85 | |
79 } // anonymous namespace | 86 } // anonymous namespace |
80 | 87 |
81 #if !defined(_MSC_VER) | 88 #if !defined(_MSC_VER) |
82 const size_t GLES2Implementation::kMaxSizeOfSimpleResult; | 89 const size_t GLES2Implementation::kMaxSizeOfSimpleResult; |
83 const unsigned int GLES2Implementation::kStartingOffset; | 90 const unsigned int GLES2Implementation::kStartingOffset; |
84 #endif | 91 #endif |
85 | 92 |
86 GLES2Implementation::GLStaticState::GLStaticState() { | 93 GLES2Implementation::GLStaticState::GLStaticState() { |
87 } | 94 } |
88 | 95 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 bound_pixel_unpack_buffer_(0), | 142 bound_pixel_unpack_buffer_(0), |
136 bound_transform_feedback_buffer_(0), | 143 bound_transform_feedback_buffer_(0), |
137 bound_uniform_buffer_(0), | 144 bound_uniform_buffer_(0), |
138 bound_pixel_pack_transfer_buffer_id_(0), | 145 bound_pixel_pack_transfer_buffer_id_(0), |
139 bound_pixel_unpack_transfer_buffer_id_(0), | 146 bound_pixel_unpack_transfer_buffer_id_(0), |
140 error_bits_(0), | 147 error_bits_(0), |
141 debug_(false), | 148 debug_(false), |
142 lose_context_when_out_of_memory_(lose_context_when_out_of_memory), | 149 lose_context_when_out_of_memory_(lose_context_when_out_of_memory), |
143 support_client_side_arrays_(support_client_side_arrays), | 150 support_client_side_arrays_(support_client_side_arrays), |
144 use_count_(0), | 151 use_count_(0), |
152 flush_id_(0), | |
145 max_extra_transfer_buffer_size_( | 153 max_extra_transfer_buffer_size_( |
146 #if defined(OS_NACL) | 154 #if defined(OS_NACL) |
147 0), | 155 0), |
148 #else | 156 #else |
149 // Do not use more than 5% of extra shared memory, and do not | 157 // Do not use more than 5% of extra shared memory, and do not |
150 // use any extra for memory contrained devices (<=1GB). | 158 // use any extra for memory contrained devices (<=1GB). |
151 base::SysInfo::AmountOfPhysicalMemory() > 1024 * 1024 * 1024 | 159 base::SysInfo::AmountOfPhysicalMemory() > 1024 * 1024 * 1024 |
152 ? base::saturated_cast<uint32_t>( | 160 ? base::saturated_cast<uint32_t>( |
153 base::SysInfo::AmountOfPhysicalMemory() / 20) | 161 base::SysInfo::AmountOfPhysicalMemory() / 20) |
154 : 0), | 162 : 0), |
(...skipping 1164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1319 } | 1327 } |
1320 } | 1328 } |
1321 helper_->DrawElements(mode, count, type, offset); | 1329 helper_->DrawElements(mode, count, type, offset); |
1322 RestoreElementAndArrayBuffers(simulated); | 1330 RestoreElementAndArrayBuffers(simulated); |
1323 CheckGLError(); | 1331 CheckGLError(); |
1324 } | 1332 } |
1325 | 1333 |
1326 void GLES2Implementation::Flush() { | 1334 void GLES2Implementation::Flush() { |
1327 GPU_CLIENT_SINGLE_THREAD_CHECK(); | 1335 GPU_CLIENT_SINGLE_THREAD_CHECK(); |
1328 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glFlush()"); | 1336 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glFlush()"); |
1337 flush_id_ = GenerateNextFlushId(); | |
1329 // Insert the cmd to call glFlush | 1338 // Insert the cmd to call glFlush |
1330 helper_->Flush(); | 1339 helper_->Flush(); |
1331 FlushHelper(); | 1340 FlushHelper(); |
1332 } | 1341 } |
1333 | 1342 |
1334 void GLES2Implementation::ShallowFlushCHROMIUM() { | 1343 void GLES2Implementation::ShallowFlushCHROMIUM() { |
1335 GPU_CLIENT_SINGLE_THREAD_CHECK(); | 1344 GPU_CLIENT_SINGLE_THREAD_CHECK(); |
1336 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glShallowFlushCHROMIUM()"); | 1345 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glShallowFlushCHROMIUM()"); |
1346 flush_id_ = GenerateNextFlushId(); | |
1337 FlushHelper(); | 1347 FlushHelper(); |
1338 } | 1348 } |
1339 | 1349 |
1340 void GLES2Implementation::FlushHelper() { | 1350 void GLES2Implementation::FlushHelper() { |
1341 // Flush our command buffer | 1351 // Flush our command buffer |
1342 // (tell the service to execute up to the flush cmd.) | 1352 // (tell the service to execute up to the flush cmd.) |
1343 helper_->CommandBufferHelper::Flush(); | 1353 helper_->CommandBufferHelper::Flush(); |
1344 | 1354 |
1345 if (aggressively_free_resources_) | 1355 if (aggressively_free_resources_) |
1346 FreeEverything(); | 1356 FreeEverything(); |
1347 } | 1357 } |
1348 | 1358 |
1349 void GLES2Implementation::OrderingBarrierCHROMIUM() { | 1359 void GLES2Implementation::OrderingBarrierCHROMIUM() { |
1350 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glOrderingBarrierCHROMIUM"); | 1360 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glOrderingBarrierCHROMIUM"); |
1351 // Flush command buffer at the GPU channel level. May be implemented as | 1361 // Flush command buffer at the GPU channel level. May be implemented as |
1352 // Flush(). | 1362 // Flush(). |
1353 helper_->CommandBufferHelper::OrderingBarrier(); | 1363 helper_->CommandBufferHelper::OrderingBarrier(); |
1354 } | 1364 } |
1355 | 1365 |
1356 void GLES2Implementation::Finish() { | 1366 void GLES2Implementation::Finish() { |
1357 GPU_CLIENT_SINGLE_THREAD_CHECK(); | 1367 GPU_CLIENT_SINGLE_THREAD_CHECK(); |
1368 flush_id_ = GenerateNextFlushId(); | |
1358 FinishHelper(); | 1369 FinishHelper(); |
1359 } | 1370 } |
1360 | 1371 |
1361 void GLES2Implementation::ShallowFinishCHROMIUM() { | 1372 void GLES2Implementation::ShallowFinishCHROMIUM() { |
1362 GPU_CLIENT_SINGLE_THREAD_CHECK(); | 1373 GPU_CLIENT_SINGLE_THREAD_CHECK(); |
1363 TRACE_EVENT0("gpu", "GLES2::ShallowFinishCHROMIUM"); | 1374 TRACE_EVENT0("gpu", "GLES2::ShallowFinishCHROMIUM"); |
1375 flush_id_ = GenerateNextFlushId(); | |
1364 // Flush our command buffer (tell the service to execute up to the flush cmd | 1376 // Flush our command buffer (tell the service to execute up to the flush cmd |
1365 // and don't return until it completes). | 1377 // and don't return until it completes). |
1366 helper_->CommandBufferHelper::Finish(); | 1378 helper_->CommandBufferHelper::Finish(); |
1367 | 1379 |
1368 if (aggressively_free_resources_) | 1380 if (aggressively_free_resources_) |
1369 FreeEverything(); | 1381 FreeEverything(); |
1370 } | 1382 } |
1371 | 1383 |
1372 void GLES2Implementation::FinishHelper() { | 1384 void GLES2Implementation::FinishHelper() { |
1373 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glFinish()"); | 1385 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glFinish()"); |
1374 TRACE_EVENT0("gpu", "GLES2::Finish"); | 1386 TRACE_EVENT0("gpu", "GLES2::Finish"); |
1375 // Insert the cmd to call glFinish | 1387 // Insert the cmd to call glFinish |
1376 helper_->Finish(); | 1388 helper_->Finish(); |
1377 // Finish our command buffer | 1389 // Finish our command buffer |
1378 // (tell the service to execute up to the Finish cmd and wait for it to | 1390 // (tell the service to execute up to the Finish cmd and wait for it to |
1379 // execute.) | 1391 // execute.) |
1380 helper_->CommandBufferHelper::Finish(); | 1392 helper_->CommandBufferHelper::Finish(); |
1381 | 1393 |
1382 if (aggressively_free_resources_) | 1394 if (aggressively_free_resources_) |
1383 FreeEverything(); | 1395 FreeEverything(); |
1384 } | 1396 } |
1385 | 1397 |
1398 GLuint GLES2Implementation::GetLastFlushIdCHROMIUM() { | |
1399 GPU_CLIENT_SINGLE_THREAD_CHECK(); | |
1400 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glGetLastFlushIdCHROMIUM()"); | |
1401 return flush_id_; | |
1402 } | |
1403 | |
1386 void GLES2Implementation::SwapBuffers() { | 1404 void GLES2Implementation::SwapBuffers() { |
1387 GPU_CLIENT_SINGLE_THREAD_CHECK(); | 1405 GPU_CLIENT_SINGLE_THREAD_CHECK(); |
1388 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glSwapBuffers()"); | 1406 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glSwapBuffers()"); |
1389 // TODO(piman): Strictly speaking we'd want to insert the token after the | 1407 // TODO(piman): Strictly speaking we'd want to insert the token after the |
1390 // swap, but the state update with the updated token might not have happened | 1408 // swap, but the state update with the updated token might not have happened |
1391 // by the time the SwapBuffer callback gets called, forcing us to synchronize | 1409 // by the time the SwapBuffer callback gets called, forcing us to synchronize |
1392 // with the GPU process more than needed. So instead, make it happen before. | 1410 // with the GPU process more than needed. So instead, make it happen before. |
1393 // All it means is that we could be slightly looser on the kMaxSwapBuffers | 1411 // All it means is that we could be slightly looser on the kMaxSwapBuffers |
1394 // semantics if the client doesn't use the callback mechanism, and by chance | 1412 // semantics if the client doesn't use the callback mechanism, and by chance |
1395 // the scheduler yields between the InsertToken and the SwapBuffers. | 1413 // the scheduler yields between the InsertToken and the SwapBuffers. |
(...skipping 5409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6805 cached_extensions_.clear(); | 6823 cached_extensions_.clear(); |
6806 } | 6824 } |
6807 | 6825 |
6808 // Include the auto-generated part of this file. We split this because it means | 6826 // Include the auto-generated part of this file. We split this because it means |
6809 // we can easily edit the non-auto generated parts right here in this file | 6827 // we can easily edit the non-auto generated parts right here in this file |
6810 // instead of having to edit some template or the code generator. | 6828 // instead of having to edit some template or the code generator. |
6811 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" | 6829 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" |
6812 | 6830 |
6813 } // namespace gles2 | 6831 } // namespace gles2 |
6814 } // namespace gpu | 6832 } // namespace gpu |
OLD | NEW |