Chromium Code Reviews| 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> |
| 11 #include <GLES2/gl2extchromium.h> | 11 #include <GLES2/gl2extchromium.h> |
| 12 #include <GLES3/gl3.h> | 12 #include <GLES3/gl3.h> |
| 13 #include <algorithm> | 13 #include <algorithm> |
| 14 #include <map> | 14 #include <map> |
| 15 #include <set> | 15 #include <set> |
| 16 #include <sstream> | 16 #include <sstream> |
| 17 #include <string> | 17 #include <string> |
| 18 #include "base/compiler_specific.h" | 18 #include "base/compiler_specific.h" |
| 19 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
| 20 #include "base/sys_info.h" | |
| 20 #include "base/thread_task_runner_handle.h" | 21 #include "base/thread_task_runner_handle.h" |
| 21 #include "base/trace_event/memory_allocator_dump.h" | 22 #include "base/trace_event/memory_allocator_dump.h" |
| 22 #include "base/trace_event/memory_dump_manager.h" | 23 #include "base/trace_event/memory_dump_manager.h" |
| 23 #include "base/trace_event/process_memory_dump.h" | 24 #include "base/trace_event/process_memory_dump.h" |
| 24 #include "gpu/command_buffer/client/buffer_tracker.h" | 25 #include "gpu/command_buffer/client/buffer_tracker.h" |
| 25 #include "gpu/command_buffer/client/gles2_cmd_helper.h" | 26 #include "gpu/command_buffer/client/gles2_cmd_helper.h" |
| 26 #include "gpu/command_buffer/client/gpu_control.h" | 27 #include "gpu/command_buffer/client/gpu_control.h" |
| 27 #include "gpu/command_buffer/client/program_info_manager.h" | 28 #include "gpu/command_buffer/client/program_info_manager.h" |
| 28 #include "gpu/command_buffer/client/query_tracker.h" | 29 #include "gpu/command_buffer/client/query_tracker.h" |
| 29 #include "gpu/command_buffer/client/transfer_buffer.h" | 30 #include "gpu/command_buffer/client/transfer_buffer.h" |
| (...skipping 2265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2295 } | 2296 } |
| 2296 | 2297 |
| 2297 // Check if we can send it all at once. | 2298 // Check if we can send it all at once. |
| 2298 int32_t shm_id = 0; | 2299 int32_t shm_id = 0; |
| 2299 uint32_t shm_offset = 0; | 2300 uint32_t shm_offset = 0; |
| 2300 void* buffer_pointer = nullptr; | 2301 void* buffer_pointer = nullptr; |
| 2301 | 2302 |
| 2302 ScopedTransferBufferPtr transfer_alloc(size, helper_, transfer_buffer_); | 2303 ScopedTransferBufferPtr transfer_alloc(size, helper_, transfer_buffer_); |
| 2303 ScopedMappedMemoryPtr mapped_alloc(0, helper_, mapped_memory_.get()); | 2304 ScopedMappedMemoryPtr mapped_alloc(0, helper_, mapped_memory_.get()); |
| 2304 | 2305 |
| 2306 // Do not use more than 5% of extra shared memory, and do not use any | |
| 2307 // extra for memory contrained devices (<1GB). | |
| 2308 const int64_t physical_memory = base::SysInfo::AmountOfPhysicalMemory(); | |
| 2309 const uint32_t max_extra_transfer_buffer_size = | |
| 2310 physical_memory > 1024 * 1024 * 1024 | |
| 2311 ? static_cast<uint32_t>(physical_memory / 20) | |
| 2312 : 0; | |
| 2313 | |
| 2305 if (transfer_alloc.valid() && transfer_alloc.size() >= size) { | 2314 if (transfer_alloc.valid() && transfer_alloc.size() >= size) { |
| 2306 shm_id = transfer_alloc.shm_id(); | 2315 shm_id = transfer_alloc.shm_id(); |
| 2307 shm_offset = transfer_alloc.offset(); | 2316 shm_offset = transfer_alloc.offset(); |
| 2308 buffer_pointer = transfer_alloc.address(); | 2317 buffer_pointer = transfer_alloc.address(); |
| 2309 } else { | 2318 } else if (size < max_extra_transfer_buffer_size) { |
| 2310 mapped_alloc.Reset(size); | 2319 mapped_alloc.Reset(size); |
| 2311 if (mapped_alloc.valid()) { | 2320 if (mapped_alloc.valid()) { |
| 2312 transfer_alloc.Discard(); | 2321 transfer_alloc.Discard(); |
| 2313 | 2322 |
| 2314 mapped_alloc.SetFlushAfterRelease(true); | 2323 mapped_alloc.SetFlushAfterRelease(true); |
| 2315 shm_id = mapped_alloc.shm_id(); | 2324 shm_id = mapped_alloc.shm_id(); |
| 2316 shm_offset = mapped_alloc.offset(); | 2325 shm_offset = mapped_alloc.offset(); |
| 2317 buffer_pointer = mapped_alloc.address(); | 2326 buffer_pointer = mapped_alloc.address(); |
| 2318 } | 2327 } |
| 2319 } | 2328 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2421 } | 2430 } |
| 2422 | 2431 |
| 2423 // Check if we can send it all at once. | 2432 // Check if we can send it all at once. |
| 2424 int32_t shm_id = 0; | 2433 int32_t shm_id = 0; |
| 2425 uint32_t shm_offset = 0; | 2434 uint32_t shm_offset = 0; |
| 2426 void* buffer_pointer = nullptr; | 2435 void* buffer_pointer = nullptr; |
| 2427 | 2436 |
| 2428 ScopedTransferBufferPtr transfer_alloc(size, helper_, transfer_buffer_); | 2437 ScopedTransferBufferPtr transfer_alloc(size, helper_, transfer_buffer_); |
| 2429 ScopedMappedMemoryPtr mapped_alloc(0, helper_, mapped_memory_.get()); | 2438 ScopedMappedMemoryPtr mapped_alloc(0, helper_, mapped_memory_.get()); |
| 2430 | 2439 |
| 2440 // Do not use more than 5% of extra shared memory, and do not use any | |
| 2441 // extra for memory contrained devices (<1GB). | |
| 2442 const int64_t physical_memory = base::SysInfo::AmountOfPhysicalMemory(); | |
| 2443 const uint32_t max_extra_transfer_buffer_size = | |
|
no sievers
2015/10/15 22:33:30
can you make it a constant in this class?
David Yen
2015/10/15 23:01:54
I made it a static constant instead for the file.
| |
| 2444 physical_memory > 1024 * 1024 * 1024 | |
| 2445 ? static_cast<uint32_t>(physical_memory / 20) | |
| 2446 : 0; | |
| 2447 | |
| 2431 if (transfer_alloc.valid() && transfer_alloc.size() >= size) { | 2448 if (transfer_alloc.valid() && transfer_alloc.size() >= size) { |
| 2432 shm_id = transfer_alloc.shm_id(); | 2449 shm_id = transfer_alloc.shm_id(); |
| 2433 shm_offset = transfer_alloc.offset(); | 2450 shm_offset = transfer_alloc.offset(); |
| 2434 buffer_pointer = transfer_alloc.address(); | 2451 buffer_pointer = transfer_alloc.address(); |
| 2435 } else { | 2452 } else if (size < max_extra_transfer_buffer_size) { |
| 2436 mapped_alloc.Reset(size); | 2453 mapped_alloc.Reset(size); |
| 2437 if (mapped_alloc.valid()) { | 2454 if (mapped_alloc.valid()) { |
| 2438 transfer_alloc.Discard(); | 2455 transfer_alloc.Discard(); |
| 2439 | 2456 |
| 2440 mapped_alloc.SetFlushAfterRelease(true); | 2457 mapped_alloc.SetFlushAfterRelease(true); |
| 2441 shm_id = mapped_alloc.shm_id(); | 2458 shm_id = mapped_alloc.shm_id(); |
| 2442 shm_offset = mapped_alloc.offset(); | 2459 shm_offset = mapped_alloc.offset(); |
| 2443 buffer_pointer = mapped_alloc.address(); | 2460 buffer_pointer = mapped_alloc.address(); |
| 2444 } | 2461 } |
| 2445 } | 2462 } |
| (...skipping 3509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5955 CheckGLError(); | 5972 CheckGLError(); |
| 5956 } | 5973 } |
| 5957 | 5974 |
| 5958 // Include the auto-generated part of this file. We split this because it means | 5975 // Include the auto-generated part of this file. We split this because it means |
| 5959 // we can easily edit the non-auto generated parts right here in this file | 5976 // we can easily edit the non-auto generated parts right here in this file |
| 5960 // instead of having to edit some template or the code generator. | 5977 // instead of having to edit some template or the code generator. |
| 5961 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" | 5978 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" |
| 5962 | 5979 |
| 5963 } // namespace gles2 | 5980 } // namespace gles2 |
| 5964 } // namespace gpu | 5981 } // namespace gpu |
| OLD | NEW |