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 2176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2206 dest += buffer_padded_row_size; | 2207 dest += buffer_padded_row_size; |
2207 source += pixels_padded_row_size; | 2208 source += pixels_padded_row_size; |
2208 } | 2209 } |
2209 memcpy(dest, source, unpadded_row_size); | 2210 memcpy(dest, source, unpadded_row_size); |
2210 } else { | 2211 } else { |
2211 uint32 size = (height - 1) * pixels_padded_row_size + unpadded_row_size; | 2212 uint32 size = (height - 1) * pixels_padded_row_size + unpadded_row_size; |
2212 memcpy(dest, source, size); | 2213 memcpy(dest, source, size); |
2213 } | 2214 } |
2214 } | 2215 } |
2215 | 2216 |
2217 #if defined(OS_NACL) | |
2218 const uint32_t kMaxExtraTransferBufferSize = 0; | |
2219 #else | |
2220 // Do not use more than 5% of extra shared memory, and do not use any | |
2221 // extra for memory contrained devices (<1GB). | |
2222 const int64_t kPhysicalMemory = base::SysInfo::AmountOfPhysicalMemory(); | |
no sievers
2015/10/15 23:24:45
This might not be safe, because it's unclear when
David Yen
2015/10/19 15:25:52
Done.
| |
2223 const uint32_t kMaxExtraTransferBufferSize = | |
2224 kPhysicalMemory > 1024 * 1024 * 1024 | |
2225 ? static_cast<uint32_t>(kPhysicalMemory / 20) | |
2226 : 0; | |
2227 #endif | |
2228 | |
2216 } // anonymous namespace | 2229 } // anonymous namespace |
2217 | 2230 |
2218 void GLES2Implementation::TexImage2D( | 2231 void GLES2Implementation::TexImage2D( |
2219 GLenum target, GLint level, GLint internalformat, GLsizei width, | 2232 GLenum target, GLint level, GLint internalformat, GLsizei width, |
2220 GLsizei height, GLint border, GLenum format, GLenum type, | 2233 GLsizei height, GLint border, GLenum format, GLenum type, |
2221 const void* pixels) { | 2234 const void* pixels) { |
2222 GPU_CLIENT_SINGLE_THREAD_CHECK(); | 2235 GPU_CLIENT_SINGLE_THREAD_CHECK(); |
2223 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glTexImage2D(" | 2236 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glTexImage2D(" |
2224 << GLES2Util::GetStringTextureTarget(target) << ", " | 2237 << GLES2Util::GetStringTextureTarget(target) << ", " |
2225 << level << ", " | 2238 << level << ", " |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2299 uint32_t shm_offset = 0; | 2312 uint32_t shm_offset = 0; |
2300 void* buffer_pointer = nullptr; | 2313 void* buffer_pointer = nullptr; |
2301 | 2314 |
2302 ScopedTransferBufferPtr transfer_alloc(size, helper_, transfer_buffer_); | 2315 ScopedTransferBufferPtr transfer_alloc(size, helper_, transfer_buffer_); |
2303 ScopedMappedMemoryPtr mapped_alloc(0, helper_, mapped_memory_.get()); | 2316 ScopedMappedMemoryPtr mapped_alloc(0, helper_, mapped_memory_.get()); |
2304 | 2317 |
2305 if (transfer_alloc.valid() && transfer_alloc.size() >= size) { | 2318 if (transfer_alloc.valid() && transfer_alloc.size() >= size) { |
2306 shm_id = transfer_alloc.shm_id(); | 2319 shm_id = transfer_alloc.shm_id(); |
2307 shm_offset = transfer_alloc.offset(); | 2320 shm_offset = transfer_alloc.offset(); |
2308 buffer_pointer = transfer_alloc.address(); | 2321 buffer_pointer = transfer_alloc.address(); |
2309 } else { | 2322 } else if (size < kMaxExtraTransferBufferSize) { |
2310 mapped_alloc.Reset(size); | 2323 mapped_alloc.Reset(size); |
2311 if (mapped_alloc.valid()) { | 2324 if (mapped_alloc.valid()) { |
2312 transfer_alloc.Discard(); | 2325 transfer_alloc.Discard(); |
2313 | 2326 |
2314 mapped_alloc.SetFlushAfterRelease(true); | 2327 mapped_alloc.SetFlushAfterRelease(true); |
2315 shm_id = mapped_alloc.shm_id(); | 2328 shm_id = mapped_alloc.shm_id(); |
2316 shm_offset = mapped_alloc.offset(); | 2329 shm_offset = mapped_alloc.offset(); |
2317 buffer_pointer = mapped_alloc.address(); | 2330 buffer_pointer = mapped_alloc.address(); |
2318 } | 2331 } |
2319 } | 2332 } |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2425 uint32_t shm_offset = 0; | 2438 uint32_t shm_offset = 0; |
2426 void* buffer_pointer = nullptr; | 2439 void* buffer_pointer = nullptr; |
2427 | 2440 |
2428 ScopedTransferBufferPtr transfer_alloc(size, helper_, transfer_buffer_); | 2441 ScopedTransferBufferPtr transfer_alloc(size, helper_, transfer_buffer_); |
2429 ScopedMappedMemoryPtr mapped_alloc(0, helper_, mapped_memory_.get()); | 2442 ScopedMappedMemoryPtr mapped_alloc(0, helper_, mapped_memory_.get()); |
2430 | 2443 |
2431 if (transfer_alloc.valid() && transfer_alloc.size() >= size) { | 2444 if (transfer_alloc.valid() && transfer_alloc.size() >= size) { |
2432 shm_id = transfer_alloc.shm_id(); | 2445 shm_id = transfer_alloc.shm_id(); |
2433 shm_offset = transfer_alloc.offset(); | 2446 shm_offset = transfer_alloc.offset(); |
2434 buffer_pointer = transfer_alloc.address(); | 2447 buffer_pointer = transfer_alloc.address(); |
2435 } else { | 2448 } else if (size < kMaxExtraTransferBufferSize) { |
2436 mapped_alloc.Reset(size); | 2449 mapped_alloc.Reset(size); |
2437 if (mapped_alloc.valid()) { | 2450 if (mapped_alloc.valid()) { |
2438 transfer_alloc.Discard(); | 2451 transfer_alloc.Discard(); |
2439 | 2452 |
2440 mapped_alloc.SetFlushAfterRelease(true); | 2453 mapped_alloc.SetFlushAfterRelease(true); |
2441 shm_id = mapped_alloc.shm_id(); | 2454 shm_id = mapped_alloc.shm_id(); |
2442 shm_offset = mapped_alloc.offset(); | 2455 shm_offset = mapped_alloc.offset(); |
2443 buffer_pointer = mapped_alloc.address(); | 2456 buffer_pointer = mapped_alloc.address(); |
2444 } | 2457 } |
2445 } | 2458 } |
(...skipping 3509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5955 CheckGLError(); | 5968 CheckGLError(); |
5956 } | 5969 } |
5957 | 5970 |
5958 // Include the auto-generated part of this file. We split this because it means | 5971 // 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 | 5972 // 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. | 5973 // instead of having to edit some template or the code generator. |
5961 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" | 5974 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" |
5962 | 5975 |
5963 } // namespace gles2 | 5976 } // namespace gles2 |
5964 } // namespace gpu | 5977 } // namespace gpu |
OLD | NEW |