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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 bool bind_generates_resource, | 71 bool bind_generates_resource, |
72 bool lose_context_when_out_of_memory, | 72 bool lose_context_when_out_of_memory, |
73 bool support_client_side_arrays, | 73 bool support_client_side_arrays, |
74 GpuControl* gpu_control) | 74 GpuControl* gpu_control) |
75 : helper_(helper), | 75 : helper_(helper), |
76 transfer_buffer_(transfer_buffer), | 76 transfer_buffer_(transfer_buffer), |
77 angle_pack_reverse_row_order_status_(kUnknownExtensionStatus), | 77 angle_pack_reverse_row_order_status_(kUnknownExtensionStatus), |
78 chromium_framebuffer_multisample_(kUnknownExtensionStatus), | 78 chromium_framebuffer_multisample_(kUnknownExtensionStatus), |
79 pack_alignment_(4), | 79 pack_alignment_(4), |
80 unpack_alignment_(4), | 80 unpack_alignment_(4), |
81 unpack_flip_y_(false), | |
82 unpack_row_length_(0), | 81 unpack_row_length_(0), |
83 unpack_image_height_(0), | 82 unpack_image_height_(0), |
84 unpack_skip_rows_(0), | 83 unpack_skip_rows_(0), |
85 unpack_skip_pixels_(0), | 84 unpack_skip_pixels_(0), |
86 unpack_skip_images_(0), | 85 unpack_skip_images_(0), |
87 pack_reverse_row_order_(false), | 86 pack_reverse_row_order_(false), |
88 active_texture_unit_(0), | 87 active_texture_unit_(0), |
89 bound_framebuffer_(0), | 88 bound_framebuffer_(0), |
90 bound_read_framebuffer_(0), | 89 bound_read_framebuffer_(0), |
91 bound_renderbuffer_(0), | 90 bound_renderbuffer_(0), |
(...skipping 1502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1594 case GL_UNPACK_SKIP_ROWS_EXT: | 1593 case GL_UNPACK_SKIP_ROWS_EXT: |
1595 unpack_skip_rows_ = param; | 1594 unpack_skip_rows_ = param; |
1596 return; | 1595 return; |
1597 case GL_UNPACK_SKIP_PIXELS_EXT: | 1596 case GL_UNPACK_SKIP_PIXELS_EXT: |
1598 unpack_skip_pixels_ = param; | 1597 unpack_skip_pixels_ = param; |
1599 return; | 1598 return; |
1600 case GL_UNPACK_SKIP_IMAGES: | 1599 case GL_UNPACK_SKIP_IMAGES: |
1601 unpack_skip_images_ = param; | 1600 unpack_skip_images_ = param; |
1602 return; | 1601 return; |
1603 case GL_UNPACK_FLIP_Y_CHROMIUM: | 1602 case GL_UNPACK_FLIP_Y_CHROMIUM: |
1604 unpack_flip_y_ = (param != 0); | 1603 case GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM: |
1605 break; | 1604 case GL_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM: |
| 1605 // TODO(zmo): Remove this when blink side callers are removed. |
| 1606 return; |
1606 case GL_PACK_REVERSE_ROW_ORDER_ANGLE: | 1607 case GL_PACK_REVERSE_ROW_ORDER_ANGLE: |
1607 pack_reverse_row_order_ = | 1608 pack_reverse_row_order_ = |
1608 IsAnglePackReverseRowOrderAvailable() ? (param != 0) : false; | 1609 IsAnglePackReverseRowOrderAvailable() ? (param != 0) : false; |
1609 break; | 1610 break; |
1610 default: | 1611 default: |
1611 break; | 1612 break; |
1612 } | 1613 } |
1613 helper_->PixelStorei(pname, param); | 1614 helper_->PixelStorei(pname, param); |
1614 CheckGLError(); | 1615 CheckGLError(); |
1615 } | 1616 } |
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2091 CheckGLError(); | 2092 CheckGLError(); |
2092 } | 2093 } |
2093 | 2094 |
2094 namespace { | 2095 namespace { |
2095 | 2096 |
2096 void CopyRectToBuffer( | 2097 void CopyRectToBuffer( |
2097 const void* pixels, | 2098 const void* pixels, |
2098 uint32 height, | 2099 uint32 height, |
2099 uint32 unpadded_row_size, | 2100 uint32 unpadded_row_size, |
2100 uint32 pixels_padded_row_size, | 2101 uint32 pixels_padded_row_size, |
2101 bool flip_y, | |
2102 void* buffer, | 2102 void* buffer, |
2103 uint32 buffer_padded_row_size) { | 2103 uint32 buffer_padded_row_size) { |
2104 const int8* source = static_cast<const int8*>(pixels); | 2104 const int8* source = static_cast<const int8*>(pixels); |
2105 int8* dest = static_cast<int8*>(buffer); | 2105 int8* dest = static_cast<int8*>(buffer); |
2106 if (flip_y || pixels_padded_row_size != buffer_padded_row_size) { | 2106 if (pixels_padded_row_size != buffer_padded_row_size) { |
2107 if (flip_y) { | |
2108 dest += buffer_padded_row_size * (height - 1); | |
2109 } | |
2110 // the last row is copied unpadded at the end | 2107 // the last row is copied unpadded at the end |
2111 for (; height > 1; --height) { | 2108 for (; height > 1; --height) { |
2112 memcpy(dest, source, buffer_padded_row_size); | 2109 memcpy(dest, source, buffer_padded_row_size); |
2113 if (flip_y) { | 2110 dest += buffer_padded_row_size; |
2114 dest -= buffer_padded_row_size; | |
2115 } else { | |
2116 dest += buffer_padded_row_size; | |
2117 } | |
2118 source += pixels_padded_row_size; | 2111 source += pixels_padded_row_size; |
2119 } | 2112 } |
2120 memcpy(dest, source, unpadded_row_size); | 2113 memcpy(dest, source, unpadded_row_size); |
2121 } else { | 2114 } else { |
2122 uint32 size = (height - 1) * pixels_padded_row_size + unpadded_row_size; | 2115 uint32 size = (height - 1) * pixels_padded_row_size + unpadded_row_size; |
2123 memcpy(dest, source, size); | 2116 memcpy(dest, source, size); |
2124 } | 2117 } |
2125 } | 2118 } |
2126 | 2119 |
2127 } // anonymous namespace | 2120 } // anonymous namespace |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2224 | 2217 |
2225 mapped_alloc.SetFlushAfterRelease(true); | 2218 mapped_alloc.SetFlushAfterRelease(true); |
2226 shm_id = mapped_alloc.shm_id(); | 2219 shm_id = mapped_alloc.shm_id(); |
2227 shm_offset = mapped_alloc.offset(); | 2220 shm_offset = mapped_alloc.offset(); |
2228 buffer_pointer = mapped_alloc.address(); | 2221 buffer_pointer = mapped_alloc.address(); |
2229 } | 2222 } |
2230 } | 2223 } |
2231 | 2224 |
2232 if (buffer_pointer) { | 2225 if (buffer_pointer) { |
2233 CopyRectToBuffer( | 2226 CopyRectToBuffer( |
2234 pixels, height, unpadded_row_size, src_padded_row_size, unpack_flip_y_, | 2227 pixels, height, unpadded_row_size, src_padded_row_size, |
2235 buffer_pointer, padded_row_size); | 2228 buffer_pointer, padded_row_size); |
2236 helper_->TexImage2D( | 2229 helper_->TexImage2D( |
2237 target, level, internalformat, width, height, format, type, | 2230 target, level, internalformat, width, height, format, type, |
2238 shm_id, shm_offset); | 2231 shm_id, shm_offset); |
2239 CheckGLError(); | 2232 CheckGLError(); |
2240 return; | 2233 return; |
2241 } | 2234 } |
2242 | 2235 |
2243 // No, so send it using TexSubImage2D. | 2236 // No, so send it using TexSubImage2D. |
2244 helper_->TexImage2D( | 2237 helper_->TexImage2D( |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2353 shm_offset = mapped_alloc.offset(); | 2346 shm_offset = mapped_alloc.offset(); |
2354 buffer_pointer = mapped_alloc.address(); | 2347 buffer_pointer = mapped_alloc.address(); |
2355 } | 2348 } |
2356 } | 2349 } |
2357 | 2350 |
2358 if (buffer_pointer) { | 2351 if (buffer_pointer) { |
2359 for (GLsizei z = 0; z < depth; ++z) { | 2352 for (GLsizei z = 0; z < depth; ++z) { |
2360 // Only the last row of the last image is unpadded. | 2353 // Only the last row of the last image is unpadded. |
2361 uint32 src_unpadded_row_size = | 2354 uint32 src_unpadded_row_size = |
2362 (z == depth - 1) ? unpadded_row_size : src_padded_row_size; | 2355 (z == depth - 1) ? unpadded_row_size : src_padded_row_size; |
2363 // TODO(zmo): Ignore flip_y flag for now. | |
2364 CopyRectToBuffer( | 2356 CopyRectToBuffer( |
2365 pixels, height, src_unpadded_row_size, src_padded_row_size, false, | 2357 pixels, height, src_unpadded_row_size, src_padded_row_size, |
2366 buffer_pointer, padded_row_size); | 2358 buffer_pointer, padded_row_size); |
2367 pixels = reinterpret_cast<const int8*>(pixels) + | 2359 pixels = reinterpret_cast<const int8*>(pixels) + |
2368 src_padded_row_size * src_height; | 2360 src_padded_row_size * src_height; |
2369 buffer_pointer = reinterpret_cast<int8*>(buffer_pointer) + | 2361 buffer_pointer = reinterpret_cast<int8*>(buffer_pointer) + |
2370 padded_row_size * height; | 2362 padded_row_size * height; |
2371 } | 2363 } |
2372 helper_->TexImage3D( | 2364 helper_->TexImage3D( |
2373 target, level, internalformat, width, height, depth, format, type, | 2365 target, level, internalformat, width, height, depth, format, type, |
2374 shm_id, shm_offset); | 2366 shm_id, shm_offset); |
2375 CheckGLError(); | 2367 CheckGLError(); |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2565 GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, | 2557 GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, |
2566 GLsizei height, GLenum format, GLenum type, uint32 unpadded_row_size, | 2558 GLsizei height, GLenum format, GLenum type, uint32 unpadded_row_size, |
2567 const void* pixels, uint32 pixels_padded_row_size, GLboolean internal, | 2559 const void* pixels, uint32 pixels_padded_row_size, GLboolean internal, |
2568 ScopedTransferBufferPtr* buffer, uint32 buffer_padded_row_size) { | 2560 ScopedTransferBufferPtr* buffer, uint32 buffer_padded_row_size) { |
2569 DCHECK(buffer); | 2561 DCHECK(buffer); |
2570 DCHECK_GE(level, 0); | 2562 DCHECK_GE(level, 0); |
2571 DCHECK_GT(height, 0); | 2563 DCHECK_GT(height, 0); |
2572 DCHECK_GT(width, 0); | 2564 DCHECK_GT(width, 0); |
2573 | 2565 |
2574 const int8* source = reinterpret_cast<const int8*>(pixels); | 2566 const int8* source = reinterpret_cast<const int8*>(pixels); |
2575 GLint original_yoffset = yoffset; | |
2576 // Transfer by rows. | 2567 // Transfer by rows. |
2577 while (height) { | 2568 while (height) { |
2578 unsigned int desired_size = | 2569 unsigned int desired_size = |
2579 buffer_padded_row_size * (height - 1) + unpadded_row_size; | 2570 buffer_padded_row_size * (height - 1) + unpadded_row_size; |
2580 if (!buffer->valid() || buffer->size() == 0) { | 2571 if (!buffer->valid() || buffer->size() == 0) { |
2581 buffer->Reset(desired_size); | 2572 buffer->Reset(desired_size); |
2582 if (!buffer->valid()) { | 2573 if (!buffer->valid()) { |
2583 return; | 2574 return; |
2584 } | 2575 } |
2585 } | 2576 } |
2586 | 2577 |
2587 GLint num_rows = ComputeNumRowsThatFitInBuffer( | 2578 GLint num_rows = ComputeNumRowsThatFitInBuffer( |
2588 buffer_padded_row_size, unpadded_row_size, buffer->size(), height); | 2579 buffer_padded_row_size, unpadded_row_size, buffer->size(), height); |
2589 num_rows = std::min(num_rows, height); | 2580 num_rows = std::min(num_rows, height); |
2590 CopyRectToBuffer( | 2581 CopyRectToBuffer( |
2591 source, num_rows, unpadded_row_size, pixels_padded_row_size, | 2582 source, num_rows, unpadded_row_size, pixels_padded_row_size, |
2592 unpack_flip_y_, buffer->address(), buffer_padded_row_size); | 2583 buffer->address(), buffer_padded_row_size); |
2593 GLint y = unpack_flip_y_ ? original_yoffset + height - num_rows : yoffset; | |
2594 helper_->TexSubImage2D( | 2584 helper_->TexSubImage2D( |
2595 target, level, xoffset, y, width, num_rows, format, type, | 2585 target, level, xoffset, yoffset, width, num_rows, format, type, |
2596 buffer->shm_id(), buffer->offset(), internal); | 2586 buffer->shm_id(), buffer->offset(), internal); |
2597 buffer->Release(); | 2587 buffer->Release(); |
2598 yoffset += num_rows; | 2588 yoffset += num_rows; |
2599 source += num_rows * pixels_padded_row_size; | 2589 source += num_rows * pixels_padded_row_size; |
2600 height -= num_rows; | 2590 height -= num_rows; |
2601 } | 2591 } |
2602 } | 2592 } |
2603 | 2593 |
2604 void GLES2Implementation::TexSubImage3DImpl( | 2594 void GLES2Implementation::TexSubImage3DImpl( |
2605 GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei zoffset, | 2595 GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei zoffset, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2649 GLsizei my_height, my_depth; | 2639 GLsizei my_height, my_depth; |
2650 if (num_images > 0) { | 2640 if (num_images > 0) { |
2651 num_rows = num_images * height; | 2641 num_rows = num_images * height; |
2652 my_height = height; | 2642 my_height = height; |
2653 my_depth = num_images; | 2643 my_depth = num_images; |
2654 } else { | 2644 } else { |
2655 my_height = num_rows; | 2645 my_height = num_rows; |
2656 my_depth = 1; | 2646 my_depth = 1; |
2657 } | 2647 } |
2658 | 2648 |
2659 // TODO(zmo): Ignore flip_y flag for now. | |
2660 if (num_images > 0) { | 2649 if (num_images > 0) { |
2661 int8* buffer_pointer = reinterpret_cast<int8*>(buffer->address()); | 2650 int8* buffer_pointer = reinterpret_cast<int8*>(buffer->address()); |
2662 uint32 src_height = | 2651 uint32 src_height = |
2663 unpack_image_height_ > 0 ? unpack_image_height_ : height; | 2652 unpack_image_height_ > 0 ? unpack_image_height_ : height; |
2664 uint32 image_size_dst = buffer_padded_row_size * height; | 2653 uint32 image_size_dst = buffer_padded_row_size * height; |
2665 uint32 image_size_src = pixels_padded_row_size * src_height; | 2654 uint32 image_size_src = pixels_padded_row_size * src_height; |
2666 for (GLint ii = 0; ii < num_images; ++ii) { | 2655 for (GLint ii = 0; ii < num_images; ++ii) { |
2667 uint32 my_unpadded_row_size; | 2656 uint32 my_unpadded_row_size; |
2668 if (total_rows == num_rows && ii + 1 == num_images) | 2657 if (total_rows == num_rows && ii + 1 == num_images) |
2669 my_unpadded_row_size = unpadded_row_size; | 2658 my_unpadded_row_size = unpadded_row_size; |
2670 else | 2659 else |
2671 my_unpadded_row_size = pixels_padded_row_size; | 2660 my_unpadded_row_size = pixels_padded_row_size; |
2672 CopyRectToBuffer( | 2661 CopyRectToBuffer( |
2673 source + ii * image_size_src, my_height, my_unpadded_row_size, | 2662 source + ii * image_size_src, my_height, my_unpadded_row_size, |
2674 pixels_padded_row_size, false, buffer_pointer + ii * image_size_dst, | 2663 pixels_padded_row_size, buffer_pointer + ii * image_size_dst, |
2675 buffer_padded_row_size); | 2664 buffer_padded_row_size); |
2676 } | 2665 } |
2677 } else { | 2666 } else { |
2678 uint32 my_unpadded_row_size; | 2667 uint32 my_unpadded_row_size; |
2679 if (total_rows == num_rows) | 2668 if (total_rows == num_rows) |
2680 my_unpadded_row_size = unpadded_row_size; | 2669 my_unpadded_row_size = unpadded_row_size; |
2681 else | 2670 else |
2682 my_unpadded_row_size = pixels_padded_row_size; | 2671 my_unpadded_row_size = pixels_padded_row_size; |
2683 CopyRectToBuffer( | 2672 CopyRectToBuffer( |
2684 source, my_height, my_unpadded_row_size, pixels_padded_row_size, | 2673 source, my_height, my_unpadded_row_size, pixels_padded_row_size, |
2685 false, buffer->address(), buffer_padded_row_size); | 2674 buffer->address(), buffer_padded_row_size); |
2686 } | 2675 } |
2687 helper_->TexSubImage3D( | 2676 helper_->TexSubImage3D( |
2688 target, level, xoffset, yoffset + row_index, zoffset + depth_index, | 2677 target, level, xoffset, yoffset + row_index, zoffset + depth_index, |
2689 width, my_height, my_depth, | 2678 width, my_height, my_depth, |
2690 format, type, buffer->shm_id(), buffer->offset(), internal); | 2679 format, type, buffer->shm_id(), buffer->offset(), internal); |
2691 buffer->Release(); | 2680 buffer->Release(); |
2692 | 2681 |
2693 total_rows -= num_rows; | 2682 total_rows -= num_rows; |
2694 if (total_rows > 0) { | 2683 if (total_rows > 0) { |
2695 GLint num_image_paddings; | 2684 GLint num_image_paddings; |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3114 const char* result = NULL; | 3103 const char* result = NULL; |
3115 // Clears the bucket so if the command fails nothing will be in it. | 3104 // Clears the bucket so if the command fails nothing will be in it. |
3116 helper_->SetBucketSize(kResultBucketId, 0); | 3105 helper_->SetBucketSize(kResultBucketId, 0); |
3117 helper_->GetString(name, kResultBucketId); | 3106 helper_->GetString(name, kResultBucketId); |
3118 std::string str; | 3107 std::string str; |
3119 if (GetBucketAsString(kResultBucketId, &str)) { | 3108 if (GetBucketAsString(kResultBucketId, &str)) { |
3120 // Adds extensions implemented on client side only. | 3109 // Adds extensions implemented on client side only. |
3121 switch (name) { | 3110 switch (name) { |
3122 case GL_EXTENSIONS: | 3111 case GL_EXTENSIONS: |
3123 str += std::string(str.empty() ? "" : " ") + | 3112 str += std::string(str.empty() ? "" : " ") + |
3124 "GL_CHROMIUM_flipy " | |
3125 "GL_EXT_unpack_subimage " | 3113 "GL_EXT_unpack_subimage " |
3126 "GL_CHROMIUM_map_sub"; | 3114 "GL_CHROMIUM_map_sub"; |
3127 if (capabilities_.image) | 3115 if (capabilities_.image) |
3128 str += " GL_CHROMIUM_image GL_CHROMIUM_gpu_memory_buffer_image"; | 3116 str += " GL_CHROMIUM_image GL_CHROMIUM_gpu_memory_buffer_image"; |
3129 if (capabilities_.future_sync_points) | 3117 if (capabilities_.future_sync_points) |
3130 str += " GL_CHROMIUM_future_sync_point"; | 3118 str += " GL_CHROMIUM_future_sync_point"; |
3131 break; | 3119 break; |
3132 default: | 3120 default: |
3133 break; | 3121 break; |
3134 } | 3122 } |
(...skipping 2664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5799 CheckGLError(); | 5787 CheckGLError(); |
5800 } | 5788 } |
5801 | 5789 |
5802 // Include the auto-generated part of this file. We split this because it means | 5790 // Include the auto-generated part of this file. We split this because it means |
5803 // we can easily edit the non-auto generated parts right here in this file | 5791 // we can easily edit the non-auto generated parts right here in this file |
5804 // instead of having to edit some template or the code generator. | 5792 // instead of having to edit some template or the code generator. |
5805 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" | 5793 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" |
5806 | 5794 |
5807 } // namespace gles2 | 5795 } // namespace gles2 |
5808 } // namespace gpu | 5796 } // namespace gpu |
OLD | NEW |