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 <algorithm> | 9 #include <algorithm> |
10 #include <map> | 10 #include <map> |
(...skipping 2218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2229 } | 2229 } |
2230 | 2230 |
2231 if (bound_pixel_pack_transfer_buffer_id_) { | 2231 if (bound_pixel_pack_transfer_buffer_id_) { |
2232 GLuint offset = ToGLuint(pixels); | 2232 GLuint offset = ToGLuint(pixels); |
2233 BufferTracker::Buffer* buffer = GetBoundPixelUnpackTransferBufferIfValid( | 2233 BufferTracker::Buffer* buffer = GetBoundPixelUnpackTransferBufferIfValid( |
2234 bound_pixel_pack_transfer_buffer_id_, | 2234 bound_pixel_pack_transfer_buffer_id_, |
2235 "glReadPixels", offset, padded_row_size * height); | 2235 "glReadPixels", offset, padded_row_size * height); |
2236 if (buffer && buffer->shm_id() != -1) { | 2236 if (buffer && buffer->shm_id() != -1) { |
2237 helper_->ReadPixels(xoffset, yoffset, width, height, format, type, | 2237 helper_->ReadPixels(xoffset, yoffset, width, height, format, type, |
2238 buffer->shm_id(), buffer->shm_offset(), | 2238 buffer->shm_id(), buffer->shm_offset(), |
2239 0, 0); | 2239 0, 0, true); |
2240 buffer->set_transfer_ready_token(helper_->InsertToken()); | |
2241 CheckGLError(); | 2240 CheckGLError(); |
2242 } | 2241 } |
2243 return; | 2242 return; |
2244 } | 2243 } |
2245 | 2244 |
2246 if (!pixels) { | 2245 if (!pixels) { |
2247 SetGLError(GL_INVALID_OPERATION, "glReadPixels", "pixels = NULL"); | 2246 SetGLError(GL_INVALID_OPERATION, "glReadPixels", "pixels = NULL"); |
2248 return; | 2247 return; |
2249 } | 2248 } |
2250 | 2249 |
(...skipping 11 matching lines...) Expand all Loading... | |
2262 // NOTE: We must look up the address of the result area AFTER allocation | 2261 // NOTE: We must look up the address of the result area AFTER allocation |
2263 // of the transfer buffer since the transfer buffer may be reallocated. | 2262 // of the transfer buffer since the transfer buffer may be reallocated. |
2264 Result* result = GetResultAs<Result*>(); | 2263 Result* result = GetResultAs<Result*>(); |
2265 if (!result) { | 2264 if (!result) { |
2266 return; | 2265 return; |
2267 } | 2266 } |
2268 *result = 0; // mark as failed. | 2267 *result = 0; // mark as failed. |
2269 helper_->ReadPixels( | 2268 helper_->ReadPixels( |
2270 xoffset, yoffset, width, num_rows, format, type, | 2269 xoffset, yoffset, width, num_rows, format, type, |
2271 buffer.shm_id(), buffer.offset(), | 2270 buffer.shm_id(), buffer.offset(), |
2272 GetResultShmId(), GetResultShmOffset()); | 2271 GetResultShmId(), GetResultShmOffset(), |
2272 false); | |
2273 WaitForCmd(); | 2273 WaitForCmd(); |
2274 if (*result != 0) { | 2274 if (*result != 0) { |
2275 // when doing a y-flip we have to iterate through top-to-bottom chunks | 2275 // when doing a y-flip we have to iterate through top-to-bottom chunks |
2276 // of the dst. The service side handles reversing the rows within a | 2276 // of the dst. The service side handles reversing the rows within a |
2277 // chunk. | 2277 // chunk. |
2278 int8* rows_dst; | 2278 int8* rows_dst; |
2279 if (pack_reverse_row_order_) { | 2279 if (pack_reverse_row_order_) { |
2280 rows_dst = dest + (height - num_rows) * padded_row_size; | 2280 rows_dst = dest + (height - num_rows) * padded_row_size; |
2281 } else { | 2281 } else { |
2282 rows_dst = dest; | 2282 rows_dst = dest; |
(...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3174 "glDeleteTextures", "id not created by this context."); | 3174 "glDeleteTextures", "id not created by this context."); |
3175 return; | 3175 return; |
3176 } | 3176 } |
3177 // When you delete a query you can't mark its memory as unused until it's | 3177 // When you delete a query you can't mark its memory as unused until it's |
3178 // completed. | 3178 // completed. |
3179 // Note: If you don't do this you won't mess up the service but you will mess | 3179 // Note: If you don't do this you won't mess up the service but you will mess |
3180 // up yourself. | 3180 // up yourself. |
3181 | 3181 |
3182 // TODO(gman): Consider making this faster by putting pending quereies | 3182 // TODO(gman): Consider making this faster by putting pending quereies |
3183 // on some queue to be removed when they are finished. | 3183 // on some queue to be removed when they are finished. |
3184 // TODO(hubbe): Consider using signalQuery callback to delete pending | |
3185 // queries. | |
3184 bool query_pending = false; | 3186 bool query_pending = false; |
3185 for (GLsizei ii = 0; ii < n; ++ii) { | 3187 for (GLsizei ii = 0; ii < n; ++ii) { |
3186 QueryTracker::Query* query = query_tracker_->GetQuery(queries[ii]); | 3188 QueryTracker::Query* query = query_tracker_->GetQuery(queries[ii]); |
3187 if (query && query->Pending()) { | 3189 if (query && !query->CheckResultsAvailable(helper_)) { |
3188 query_pending = true; | 3190 query_pending = true; |
3189 break; | 3191 break; |
3190 } | 3192 } |
3191 } | 3193 } |
3192 | 3194 |
3193 if (query_pending) { | 3195 if (query_pending) { |
3194 WaitForCmd(); | 3196 WaitForCmd(); |
3197 | |
3198 query_pending = false; | |
3199 for (GLsizei ii = 0; ii < n; ++ii) { | |
3200 QueryTracker::Query* query = query_tracker_->GetQuery(queries[ii]); | |
3201 if (query && !query->CheckResultsAvailable(helper_)) { | |
3202 query_pending = true; | |
3203 break; | |
3204 } | |
3205 } | |
3206 if (query_pending) { | |
3207 // Some queries may still not be done even after the GPU process | |
3208 // has sent the command to the driver. When this happens we need | |
3209 // to use glFinish() to wait for the query to finish. | |
3210 // Moral of this story: Don't delete pending queries! | |
3211 helper_->Finish(); | |
piman
2013/06/26 22:17:08
Why do we need to do this?
DeleteQueries + WaitFor
hubbe
2013/06/28 22:17:49
That does sound perfectly reasonable, but then why
piman
2013/06/28 23:35:46
I think you accidentally a word, and I don't under
hubbe
2013/06/29 00:13:56
Ok, I'm changing it. Seems to work in my tests at
| |
3212 WaitForCmd(); | |
3213 } | |
3195 } | 3214 } |
3196 | 3215 |
3197 for (GLsizei ii = 0; ii < n; ++ii) { | 3216 for (GLsizei ii = 0; ii < n; ++ii) { |
3198 QueryTracker::Query* query = query_tracker_->GetQuery(queries[ii]); | 3217 QueryTracker::Query* query = query_tracker_->GetQuery(queries[ii]); |
3199 if (query && query->Pending()) { | 3218 if (query && !query->CheckResultsAvailable(helper_)) { |
3200 if (!query->CheckResultsAvailable(helper_)) { | 3219 // Should only get here on context lost. |
3201 // Should only get here on context lost. | 3220 MustBeContextLost(); |
3202 MustBeContextLost(); | |
3203 } | |
3204 } | 3221 } |
3205 query_tracker_->RemoveQuery(queries[ii], helper_->IsContextLost()); | 3222 query_tracker_->RemoveQuery(queries[ii], helper_->IsContextLost()); |
3206 } | 3223 } |
3207 helper_->DeleteQueriesEXTImmediate(n, queries); | 3224 helper_->DeleteQueriesEXTImmediate(n, queries); |
3208 } | 3225 } |
3209 | 3226 |
3210 // TODO(gman): Remove this. Queries are not shared resources. | 3227 // TODO(gman): Remove this. Queries are not shared resources. |
3211 void GLES2Implementation::DeleteQueriesStub( | 3228 void GLES2Implementation::DeleteQueriesStub( |
3212 GLsizei /* n */, const GLuint* /* queries */) { | 3229 GLsizei /* n */, const GLuint* /* queries */) { |
3213 } | 3230 } |
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3851 CheckGLError(); | 3868 CheckGLError(); |
3852 } | 3869 } |
3853 | 3870 |
3854 // Include the auto-generated part of this file. We split this because it means | 3871 // Include the auto-generated part of this file. We split this because it means |
3855 // we can easily edit the non-auto generated parts right here in this file | 3872 // we can easily edit the non-auto generated parts right here in this file |
3856 // instead of having to edit some template or the code generator. | 3873 // instead of having to edit some template or the code generator. |
3857 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" | 3874 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" |
3858 | 3875 |
3859 } // namespace gles2 | 3876 } // namespace gles2 |
3860 } // namespace gpu | 3877 } // namespace gpu |
OLD | NEW |