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 "../client/gles2_implementation.h" | 7 #include "../client/gles2_implementation.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <map> | 10 #include <map> |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 bound_framebuffer_(0), | 398 bound_framebuffer_(0), |
399 bound_renderbuffer_(0), | 399 bound_renderbuffer_(0), |
400 bound_array_buffer_id_(0), | 400 bound_array_buffer_id_(0), |
401 bound_element_array_buffer_id_(0), | 401 bound_element_array_buffer_id_(0), |
402 client_side_array_id_(0), | 402 client_side_array_id_(0), |
403 client_side_element_array_id_(0), | 403 client_side_element_array_id_(0), |
404 error_bits_(0), | 404 error_bits_(0), |
405 debug_(false), | 405 debug_(false), |
406 use_count_(0), | 406 use_count_(0), |
407 current_query_(NULL), | 407 current_query_(NULL), |
408 error_message_callback_(NULL) { | 408 error_message_callback_(NULL), |
| 409 context_lost_(false) { |
409 GPU_DCHECK(helper); | 410 GPU_DCHECK(helper); |
410 GPU_DCHECK(transfer_buffer); | 411 GPU_DCHECK(transfer_buffer); |
411 GPU_CLIENT_LOG_CODE_BLOCK({ | 412 GPU_CLIENT_LOG_CODE_BLOCK({ |
412 debug_ = CommandLine::ForCurrentProcess()->HasSwitch( | 413 debug_ = CommandLine::ForCurrentProcess()->HasSwitch( |
413 switches::kEnableGPUClientLogging); | 414 switches::kEnableGPUClientLogging); |
414 }); | 415 }); |
415 | 416 |
416 share_group_ = (share_group ? share_group : new ShareGroup( | 417 share_group_ = (share_group ? share_group : new ShareGroup( |
417 share_resources, bind_generates_resource)); | 418 share_resources, bind_generates_resource)); |
418 | 419 |
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1061 // Flush our command buffer | 1062 // Flush our command buffer |
1062 // (tell the service to execute up to the flush cmd.) | 1063 // (tell the service to execute up to the flush cmd.) |
1063 helper_->CommandBufferHelper::Flush(); | 1064 helper_->CommandBufferHelper::Flush(); |
1064 } | 1065 } |
1065 | 1066 |
1066 void GLES2Implementation::Finish() { | 1067 void GLES2Implementation::Finish() { |
1067 GPU_CLIENT_SINGLE_THREAD_CHECK(); | 1068 GPU_CLIENT_SINGLE_THREAD_CHECK(); |
1068 FinishHelper(); | 1069 FinishHelper(); |
1069 } | 1070 } |
1070 | 1071 |
| 1072 bool GLES2Implementation::MustBeContextLost() { |
| 1073 if (!context_lost_) { |
| 1074 FinishHelper(); |
| 1075 context_lost_ = error::IsError(helper_->command_buffer()->GetLastError()); |
| 1076 } |
| 1077 GPU_CHECK(context_lost_); |
| 1078 return context_lost_; |
| 1079 } |
| 1080 |
1071 void GLES2Implementation::FinishHelper() { | 1081 void GLES2Implementation::FinishHelper() { |
1072 GPU_CLIENT_LOG("[" << this << "] glFinish()"); | 1082 GPU_CLIENT_LOG("[" << this << "] glFinish()"); |
1073 TRACE_EVENT0("gpu", "GLES2::Finish"); | 1083 TRACE_EVENT0("gpu", "GLES2::Finish"); |
1074 // Insert the cmd to call glFinish | 1084 // Insert the cmd to call glFinish |
1075 helper_->Finish(); | 1085 helper_->Finish(); |
1076 // Finish our command buffer | 1086 // Finish our command buffer |
1077 // (tell the service to execute up to the Finish cmd and wait for it to | 1087 // (tell the service to execute up to the Finish cmd and wait for it to |
1078 // execute.) | 1088 // execute.) |
1079 helper_->CommandBufferHelper::Finish(); | 1089 helper_->CommandBufferHelper::Finish(); |
1080 } | 1090 } |
(...skipping 1956 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3037 } | 3047 } |
3038 } | 3048 } |
3039 | 3049 |
3040 if (query_pending) { | 3050 if (query_pending) { |
3041 FinishHelper(); | 3051 FinishHelper(); |
3042 } | 3052 } |
3043 | 3053 |
3044 for (GLsizei ii = 0; ii < n; ++ii) { | 3054 for (GLsizei ii = 0; ii < n; ++ii) { |
3045 QueryTracker::Query* query = query_tracker_->GetQuery(queries[ii]); | 3055 QueryTracker::Query* query = query_tracker_->GetQuery(queries[ii]); |
3046 if (query && query->Pending()) { | 3056 if (query && query->Pending()) { |
3047 GPU_CHECK(query->CheckResultsAvailable(helper_)); | 3057 if (!query->CheckResultsAvailable(helper_)) { |
| 3058 // Should only get here on context lost. |
| 3059 MustBeContextLost(); |
| 3060 } |
3048 } | 3061 } |
3049 query_tracker_->RemoveQuery(queries[ii]); | 3062 query_tracker_->RemoveQuery(queries[ii]); |
3050 } | 3063 } |
3051 helper_->DeleteQueriesEXTImmediate(n, queries); | 3064 helper_->DeleteQueriesEXTImmediate(n, queries); |
3052 } | 3065 } |
3053 | 3066 |
3054 // TODO(gman): Remove this. Queries are not shared resources. | 3067 // TODO(gman): Remove this. Queries are not shared resources. |
3055 void GLES2Implementation::DeleteQueriesStub( | 3068 void GLES2Implementation::DeleteQueriesStub( |
3056 GLsizei /* n */, const GLuint* /* queries */) { | 3069 GLsizei /* n */, const GLuint* /* queries */) { |
3057 } | 3070 } |
(...skipping 26 matching lines...) Expand all Loading... |
3084 SetGLError(GL_INVALID_OPERATION, "glBeginQueryEXT", "id is 0"); | 3097 SetGLError(GL_INVALID_OPERATION, "glBeginQueryEXT", "id is 0"); |
3085 return; | 3098 return; |
3086 } | 3099 } |
3087 | 3100 |
3088 // TODO(gman) if id not GENned INV_OPERATION | 3101 // TODO(gman) if id not GENned INV_OPERATION |
3089 | 3102 |
3090 // if id does not have an object | 3103 // if id does not have an object |
3091 QueryTracker::Query* query = query_tracker_->GetQuery(id); | 3104 QueryTracker::Query* query = query_tracker_->GetQuery(id); |
3092 if (!query) { | 3105 if (!query) { |
3093 query = query_tracker_->CreateQuery(id, target); | 3106 query = query_tracker_->CreateQuery(id, target); |
| 3107 if (!query) { |
| 3108 MustBeContextLost(); |
| 3109 return; |
| 3110 } |
3094 } else if (query->target() != target) { | 3111 } else if (query->target() != target) { |
3095 SetGLError( | 3112 SetGLError( |
3096 GL_INVALID_OPERATION, "glBeginQueryEXT", "target does not match"); | 3113 GL_INVALID_OPERATION, "glBeginQueryEXT", "target does not match"); |
3097 return; | 3114 return; |
3098 } | 3115 } |
3099 | 3116 |
3100 current_query_ = query; | 3117 current_query_ = query; |
3101 | 3118 |
3102 query->Begin(this); | 3119 query->Begin(this); |
3103 } | 3120 } |
3104 | 3121 |
3105 void GLES2Implementation::EndQueryEXT(GLenum target) { | 3122 void GLES2Implementation::EndQueryEXT(GLenum target) { |
3106 GPU_CLIENT_SINGLE_THREAD_CHECK(); | 3123 GPU_CLIENT_SINGLE_THREAD_CHECK(); |
3107 GPU_CLIENT_LOG("[" << this << "] EndQueryEXT(" | 3124 GPU_CLIENT_LOG("[" << this << "] EndQueryEXT(" |
3108 << GLES2Util::GetStringQueryTarget(target) << ")"); | 3125 << GLES2Util::GetStringQueryTarget(target) << ")"); |
| 3126 // Don't do anything if the context is lost. |
| 3127 if (context_lost_) { |
| 3128 return; |
| 3129 } |
3109 | 3130 |
3110 if (!current_query_) { | 3131 if (!current_query_) { |
3111 SetGLError(GL_INVALID_OPERATION, "glEndQueryEXT", "no active query"); | 3132 SetGLError(GL_INVALID_OPERATION, "glEndQueryEXT", "no active query"); |
3112 return; | 3133 return; |
3113 } | 3134 } |
3114 | 3135 |
3115 if (current_query_->target() != target) { | 3136 if (current_query_->target() != target) { |
3116 SetGLError(GL_INVALID_OPERATION, | 3137 SetGLError(GL_INVALID_OPERATION, |
3117 "glEndQueryEXT", "target does not match active query"); | 3138 "glEndQueryEXT", "target does not match active query"); |
3118 return; | 3139 return; |
(...skipping 20 matching lines...) Expand all Loading... |
3139 GPU_CLIENT_LOG(" " << *params); | 3160 GPU_CLIENT_LOG(" " << *params); |
3140 } | 3161 } |
3141 | 3162 |
3142 void GLES2Implementation::GetQueryObjectuivEXT( | 3163 void GLES2Implementation::GetQueryObjectuivEXT( |
3143 GLuint id, GLenum pname, GLuint* params) { | 3164 GLuint id, GLenum pname, GLuint* params) { |
3144 GPU_CLIENT_SINGLE_THREAD_CHECK(); | 3165 GPU_CLIENT_SINGLE_THREAD_CHECK(); |
3145 GPU_CLIENT_LOG("[" << this << "] GetQueryivEXT(" << id << ", " | 3166 GPU_CLIENT_LOG("[" << this << "] GetQueryivEXT(" << id << ", " |
3146 << GLES2Util::GetStringQueryObjectParameter(pname) << ", " | 3167 << GLES2Util::GetStringQueryObjectParameter(pname) << ", " |
3147 << static_cast<const void*>(params) << ")"); | 3168 << static_cast<const void*>(params) << ")"); |
3148 | 3169 |
| 3170 // exit if the context is lost. |
| 3171 if (context_lost_) { |
| 3172 return; |
| 3173 } |
| 3174 |
3149 QueryTracker::Query* query = query_tracker_->GetQuery(id); | 3175 QueryTracker::Query* query = query_tracker_->GetQuery(id); |
3150 if (!query) { | 3176 if (!query) { |
3151 SetGLError(GL_INVALID_OPERATION, "glQueryObjectuivEXT", "unknown query id"); | 3177 SetGLError(GL_INVALID_OPERATION, "glQueryObjectuivEXT", "unknown query id"); |
3152 return; | 3178 return; |
3153 } | 3179 } |
3154 | 3180 |
3155 if (query == current_query_) { | 3181 if (query == current_query_) { |
3156 SetGLError( | 3182 SetGLError( |
3157 GL_INVALID_OPERATION, | 3183 GL_INVALID_OPERATION, |
3158 "glQueryObjectuivEXT", "query active. Did you to call glEndQueryEXT?"); | 3184 "glQueryObjectuivEXT", "query active. Did you to call glEndQueryEXT?"); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3298 helper_->GenMailboxCHROMIUM(kResultBucketId); | 3324 helper_->GenMailboxCHROMIUM(kResultBucketId); |
3299 | 3325 |
3300 std::vector<GLbyte> result; | 3326 std::vector<GLbyte> result; |
3301 GetBucketContents(kResultBucketId, &result); | 3327 GetBucketContents(kResultBucketId, &result); |
3302 | 3328 |
3303 std::copy(result.begin(), result.end(), mailbox); | 3329 std::copy(result.begin(), result.end(), mailbox); |
3304 } | 3330 } |
3305 | 3331 |
3306 } // namespace gles2 | 3332 } // namespace gles2 |
3307 } // namespace gpu | 3333 } // namespace gpu |
OLD | NEW |