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/gl2ext.h> | 9 #include <GLES2/gl2ext.h> |
10 #include <GLES2/gl2extchromium.h> | 10 #include <GLES2/gl2extchromium.h> |
(...skipping 2169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2180 // advance pixels pointer past the skip rows and skip pixels | 2180 // advance pixels pointer past the skip rows and skip pixels |
2181 pixels = reinterpret_cast<const int8*>(pixels) + | 2181 pixels = reinterpret_cast<const int8*>(pixels) + |
2182 unpack_skip_rows_ * src_padded_row_size; | 2182 unpack_skip_rows_ * src_padded_row_size; |
2183 if (unpack_skip_pixels_) { | 2183 if (unpack_skip_pixels_) { |
2184 uint32 group_size = GLES2Util::ComputeImageGroupSize(format, type); | 2184 uint32 group_size = GLES2Util::ComputeImageGroupSize(format, type); |
2185 pixels = reinterpret_cast<const int8*>(pixels) + | 2185 pixels = reinterpret_cast<const int8*>(pixels) + |
2186 unpack_skip_pixels_ * group_size; | 2186 unpack_skip_pixels_ * group_size; |
2187 } | 2187 } |
2188 | 2188 |
2189 // Check if we can send it all at once. | 2189 // Check if we can send it all at once. |
2190 ScopedTransferBufferPtr buffer(size, helper_, transfer_buffer_); | 2190 int32_t shm_id = 0; |
2191 if (!buffer.valid()) { | 2191 uint32_t shm_offset = 0; |
2192 return; | 2192 void* buffer_pointer = nullptr; |
2193 | |
2194 ScopedTransferBufferPtr transfer_alloc(size, helper_, transfer_buffer_); | |
2195 ScopedMappedMemoryPtr mapped_alloc(0, helper_, mapped_memory_.get()); | |
2196 | |
2197 if (transfer_alloc.valid() && transfer_alloc.size() >= size) { | |
2198 shm_id = transfer_alloc.shm_id(); | |
2199 shm_offset = transfer_alloc.offset(); | |
2200 buffer_pointer = transfer_alloc.address(); | |
2201 } else { | |
2202 mapped_alloc.Reset(size); | |
2203 if (mapped_alloc.valid()) { | |
piman
2015/06/08 21:57:38
It would be good actually in this case, to free th
David Yen
2015/06/08 22:18:01
Is there a way to just mark blocks within the ring
David Yen
2015/06/09 02:03:52
I added a DiscardBlock() function but Maintaining
| |
2204 mapped_alloc.SetFlushAfterRelease(true); | |
2205 shm_id = mapped_alloc.shm_id(); | |
2206 shm_offset = mapped_alloc.offset(); | |
2207 buffer_pointer = mapped_alloc.address(); | |
2208 } | |
2193 } | 2209 } |
2194 | 2210 |
2195 if (buffer.size() >= size) { | 2211 if (buffer_pointer) { |
2196 CopyRectToBuffer( | 2212 CopyRectToBuffer( |
2197 pixels, height, unpadded_row_size, src_padded_row_size, unpack_flip_y_, | 2213 pixels, height, unpadded_row_size, src_padded_row_size, unpack_flip_y_, |
2198 buffer.address(), padded_row_size); | 2214 buffer_pointer, padded_row_size); |
2199 helper_->TexImage2D( | 2215 helper_->TexImage2D( |
2200 target, level, internalformat, width, height, format, type, | 2216 target, level, internalformat, width, height, format, type, |
2201 buffer.shm_id(), buffer.offset()); | 2217 shm_id, shm_offset); |
2202 CheckGLError(); | 2218 CheckGLError(); |
2203 return; | 2219 return; |
2204 } | 2220 } |
2205 | 2221 |
2222 // Check if we can allocate from mapped memory. | |
piman
2015/06/08 21:57:38
You don't need this code any more, right? This is
David Yen
2015/06/08 22:18:01
Oops, forgot to delete. Done.
| |
2223 int32 mapped_shm_id = 0; | |
2224 unsigned int mapped_shm_offset = 0; | |
2225 void* mem = mapped_memory_->Alloc(size, &mapped_shm_id, &mapped_shm_offset); | |
2226 if (mem) { | |
2227 CopyRectToBuffer( | |
2228 pixels, height, unpadded_row_size, src_padded_row_size, unpack_flip_y_, | |
2229 mem, padded_row_size); | |
2230 helper_->TexImage2D( | |
2231 target, level, internalformat, width, height, format, type, | |
2232 mapped_shm_id, mapped_shm_offset); | |
2233 CheckGLError(); | |
2234 mapped_memory_->FreePendingToken(mem, helper_->InsertToken()); | |
2235 return; | |
2236 } | |
2237 | |
2206 // No, so send it using TexSubImage2D. | 2238 // No, so send it using TexSubImage2D. |
2207 helper_->TexImage2D( | 2239 helper_->TexImage2D( |
2208 target, level, internalformat, width, height, format, type, | 2240 target, level, internalformat, width, height, format, type, |
2209 0, 0); | 2241 0, 0); |
2210 TexSubImage2DImpl( | 2242 TexSubImage2DImpl( |
2211 target, level, 0, 0, width, height, format, type, unpadded_row_size, | 2243 target, level, 0, 0, width, height, format, type, unpadded_row_size, |
2212 pixels, src_padded_row_size, GL_TRUE, &buffer, padded_row_size); | 2244 pixels, src_padded_row_size, GL_TRUE, &transfer_alloc, padded_row_size); |
2213 CheckGLError(); | 2245 CheckGLError(); |
2214 } | 2246 } |
2215 | 2247 |
2216 void GLES2Implementation::TexImage3D( | 2248 void GLES2Implementation::TexImage3D( |
2217 GLenum target, GLint level, GLint internalformat, GLsizei width, | 2249 GLenum target, GLint level, GLint internalformat, GLsizei width, |
2218 GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, | 2250 GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, |
2219 const void* pixels) { | 2251 const void* pixels) { |
2220 GPU_CLIENT_SINGLE_THREAD_CHECK(); | 2252 GPU_CLIENT_SINGLE_THREAD_CHECK(); |
2221 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glTexImage3D(" | 2253 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glTexImage3D(" |
2222 << GLES2Util::GetStringTextureTarget(target) << ", " | 2254 << GLES2Util::GetStringTextureTarget(target) << ", " |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2288 pixels = reinterpret_cast<const int8*>(pixels) + | 2320 pixels = reinterpret_cast<const int8*>(pixels) + |
2289 unpack_skip_images_ * src_padded_row_size * src_height + | 2321 unpack_skip_images_ * src_padded_row_size * src_height + |
2290 unpack_skip_rows_ * src_padded_row_size; | 2322 unpack_skip_rows_ * src_padded_row_size; |
2291 if (unpack_skip_pixels_) { | 2323 if (unpack_skip_pixels_) { |
2292 uint32 group_size = GLES2Util::ComputeImageGroupSize(format, type); | 2324 uint32 group_size = GLES2Util::ComputeImageGroupSize(format, type); |
2293 pixels = reinterpret_cast<const int8*>(pixels) + | 2325 pixels = reinterpret_cast<const int8*>(pixels) + |
2294 unpack_skip_pixels_ * group_size; | 2326 unpack_skip_pixels_ * group_size; |
2295 } | 2327 } |
2296 | 2328 |
2297 // Check if we can send it all at once. | 2329 // Check if we can send it all at once. |
2298 ScopedTransferBufferPtr buffer(size, helper_, transfer_buffer_); | 2330 int32_t shm_id = 0; |
2299 if (!buffer.valid()) { | 2331 uint32_t shm_offset = 0; |
2300 return; | 2332 void* buffer_pointer = nullptr; |
2333 | |
2334 ScopedTransferBufferPtr transfer_alloc(size, helper_, transfer_buffer_); | |
2335 ScopedMappedMemoryPtr mapped_alloc(0, helper_, mapped_memory_.get()); | |
2336 | |
2337 if (transfer_alloc.valid() && transfer_alloc.size() >= size) { | |
2338 shm_id = transfer_alloc.shm_id(); | |
2339 shm_offset = transfer_alloc.offset(); | |
2340 buffer_pointer = transfer_alloc.address(); | |
2341 } else { | |
2342 mapped_alloc.Reset(size); | |
2343 if (mapped_alloc.valid()) { | |
2344 mapped_alloc.SetFlushAfterRelease(true); | |
2345 shm_id = mapped_alloc.shm_id(); | |
2346 shm_offset = mapped_alloc.offset(); | |
2347 buffer_pointer = mapped_alloc.address(); | |
2348 } | |
2301 } | 2349 } |
2302 | 2350 |
2303 if (buffer.size() >= size) { | 2351 if (buffer_pointer) { |
2304 void* buffer_pointer = buffer.address(); | |
2305 for (GLsizei z = 0; z < depth; ++z) { | 2352 for (GLsizei z = 0; z < depth; ++z) { |
2306 // Only the last row of the last image is unpadded. | 2353 // Only the last row of the last image is unpadded. |
2307 uint32 src_unpadded_row_size = | 2354 uint32 src_unpadded_row_size = |
2308 (z == depth - 1) ? unpadded_row_size : src_padded_row_size; | 2355 (z == depth - 1) ? unpadded_row_size : src_padded_row_size; |
2309 // TODO(zmo): Ignore flip_y flag for now. | 2356 // TODO(zmo): Ignore flip_y flag for now. |
2310 CopyRectToBuffer( | 2357 CopyRectToBuffer( |
2311 pixels, height, src_unpadded_row_size, src_padded_row_size, false, | 2358 pixels, height, src_unpadded_row_size, src_padded_row_size, false, |
2312 buffer_pointer, padded_row_size); | 2359 buffer_pointer, padded_row_size); |
2313 pixels = reinterpret_cast<const int8*>(pixels) + | 2360 pixels = reinterpret_cast<const int8*>(pixels) + |
2314 src_padded_row_size * src_height; | 2361 src_padded_row_size * src_height; |
2315 buffer_pointer = reinterpret_cast<int8*>(buffer_pointer) + | 2362 buffer_pointer = reinterpret_cast<int8*>(buffer_pointer) + |
2316 padded_row_size * height; | 2363 padded_row_size * height; |
2317 } | 2364 } |
2318 helper_->TexImage3D( | 2365 helper_->TexImage3D( |
2319 target, level, internalformat, width, height, depth, format, type, | 2366 target, level, internalformat, width, height, depth, format, type, |
2320 buffer.shm_id(), buffer.offset()); | 2367 shm_id, shm_offset); |
2321 CheckGLError(); | 2368 CheckGLError(); |
2322 return; | 2369 return; |
2323 } | 2370 } |
2324 | 2371 |
2372 // Check if we can allocate from mapped memory. | |
2373 int32 mapped_shm_id = 0; | |
2374 unsigned int mapped_shm_offset = 0; | |
2375 void* mem = mapped_memory_->Alloc(size, &mapped_shm_id, &mapped_shm_offset); | |
2376 if (mem) { | |
2377 CopyRectToBuffer( | |
2378 pixels, height, unpadded_row_size, src_padded_row_size, unpack_flip_y_, | |
2379 mem, padded_row_size); | |
2380 helper_->TexImage2D( | |
2381 target, level, internalformat, width, height, format, type, | |
2382 mapped_shm_id, mapped_shm_offset); | |
2383 CheckGLError(); | |
2384 mapped_memory_->FreePendingToken(mem, helper_->InsertToken()); | |
2385 } | |
2386 | |
2325 // No, so send it using TexSubImage3D. | 2387 // No, so send it using TexSubImage3D. |
2326 helper_->TexImage3D( | 2388 helper_->TexImage3D( |
2327 target, level, internalformat, width, height, depth, format, type, | 2389 target, level, internalformat, width, height, depth, format, type, |
2328 0, 0); | 2390 0, 0); |
2329 TexSubImage3DImpl( | 2391 TexSubImage3DImpl( |
2330 target, level, 0, 0, 0, width, height, depth, format, type, | 2392 target, level, 0, 0, 0, width, height, depth, format, type, |
2331 unpadded_row_size, pixels, src_padded_row_size, GL_TRUE, &buffer, | 2393 unpadded_row_size, pixels, src_padded_row_size, GL_TRUE, &transfer_alloc, |
2332 padded_row_size); | 2394 padded_row_size); |
2333 CheckGLError(); | 2395 CheckGLError(); |
2334 } | 2396 } |
2335 | 2397 |
2336 void GLES2Implementation::TexSubImage2D( | 2398 void GLES2Implementation::TexSubImage2D( |
2337 GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, | 2399 GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, |
2338 GLsizei height, GLenum format, GLenum type, const void* pixels) { | 2400 GLsizei height, GLenum format, GLenum type, const void* pixels) { |
2339 GPU_CLIENT_SINGLE_THREAD_CHECK(); | 2401 GPU_CLIENT_SINGLE_THREAD_CHECK(); |
2340 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glTexSubImage2D(" | 2402 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glTexSubImage2D(" |
2341 << GLES2Util::GetStringTextureTarget(target) << ", " | 2403 << GLES2Util::GetStringTextureTarget(target) << ", " |
(...skipping 3388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5730 CheckGLError(); | 5792 CheckGLError(); |
5731 } | 5793 } |
5732 | 5794 |
5733 // Include the auto-generated part of this file. We split this because it means | 5795 // Include the auto-generated part of this file. We split this because it means |
5734 // we can easily edit the non-auto generated parts right here in this file | 5796 // we can easily edit the non-auto generated parts right here in this file |
5735 // instead of having to edit some template or the code generator. | 5797 // instead of having to edit some template or the code generator. |
5736 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" | 5798 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" |
5737 | 5799 |
5738 } // namespace gles2 | 5800 } // namespace gles2 |
5739 } // namespace gpu | 5801 } // namespace gpu |
OLD | NEW |