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 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <stdio.h> | 10 #include <stdio.h> |
11 | 11 |
12 #include <algorithm> | 12 #include <algorithm> |
13 #include <cmath> | 13 #include <cmath> |
14 #include <list> | 14 #include <list> |
15 #include <map> | 15 #include <map> |
16 #include <memory> | 16 #include <memory> |
17 #include <queue> | 17 #include <queue> |
18 | 18 |
19 #include "base/callback.h" | 19 #include "base/callback.h" |
20 #include "base/callback_helpers.h" | 20 #include "base/callback_helpers.h" |
21 #include "base/logging.h" | 21 #include "base/logging.h" |
22 #include "base/memory/linked_ptr.h" | |
23 #include "base/metrics/histogram_macros.h" | 22 #include "base/metrics/histogram_macros.h" |
24 #include "base/numerics/safe_math.h" | 23 #include "base/numerics/safe_math.h" |
25 #include "base/strings/string_number_conversions.h" | 24 #include "base/strings/string_number_conversions.h" |
26 #include "base/strings/stringprintf.h" | 25 #include "base/strings/stringprintf.h" |
27 #include "base/trace_event/trace_event.h" | 26 #include "base/trace_event/trace_event.h" |
28 #include "base/trace_event/trace_event_synthetic_delay.h" | 27 #include "base/trace_event/trace_event_synthetic_delay.h" |
29 #include "build/build_config.h" | 28 #include "build/build_config.h" |
30 #include "gpu/command_buffer/common/debug_marker_manager.h" | 29 #include "gpu/command_buffer/common/debug_marker_manager.h" |
31 #include "gpu/command_buffer/common/gles2_cmd_format.h" | 30 #include "gpu/command_buffer/common/gles2_cmd_format.h" |
32 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 31 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 } | 513 } |
515 | 514 |
516 private: | 515 private: |
517 GLES2DecoderImpl* decoder_; | 516 GLES2DecoderImpl* decoder_; |
518 GLuint id_; | 517 GLuint id_; |
519 DISALLOW_COPY_AND_ASSIGN(BackFramebuffer); | 518 DISALLOW_COPY_AND_ASSIGN(BackFramebuffer); |
520 }; | 519 }; |
521 | 520 |
522 struct FenceCallback { | 521 struct FenceCallback { |
523 FenceCallback() : fence(gl::GLFence::Create()) { DCHECK(fence); } | 522 FenceCallback() : fence(gl::GLFence::Create()) { DCHECK(fence); } |
| 523 FenceCallback(FenceCallback&&) = default; |
| 524 FenceCallback& operator=(FenceCallback&&) = default; |
524 std::vector<base::Closure> callbacks; | 525 std::vector<base::Closure> callbacks; |
525 std::unique_ptr<gl::GLFence> fence; | 526 std::unique_ptr<gl::GLFence> fence; |
526 }; | 527 }; |
527 | 528 |
528 // } // anonymous namespace. | 529 // } // anonymous namespace. |
529 | 530 |
530 // static | 531 // static |
531 const unsigned int GLES2Decoder::kDefaultStencilMask = | 532 const unsigned int GLES2Decoder::kDefaultStencilMask = |
532 static_cast<unsigned int>(-1); | 533 static_cast<unsigned int>(-1); |
533 | 534 |
(...skipping 1704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2238 DecoderTextureState texture_state_; | 2239 DecoderTextureState texture_state_; |
2239 DecoderFramebufferState framebuffer_state_; | 2240 DecoderFramebufferState framebuffer_state_; |
2240 | 2241 |
2241 std::unique_ptr<GPUTracer> gpu_tracer_; | 2242 std::unique_ptr<GPUTracer> gpu_tracer_; |
2242 std::unique_ptr<GPUStateTracer> gpu_state_tracer_; | 2243 std::unique_ptr<GPUStateTracer> gpu_state_tracer_; |
2243 const unsigned char* gpu_decoder_category_; | 2244 const unsigned char* gpu_decoder_category_; |
2244 int gpu_trace_level_; | 2245 int gpu_trace_level_; |
2245 bool gpu_trace_commands_; | 2246 bool gpu_trace_commands_; |
2246 bool gpu_debug_commands_; | 2247 bool gpu_debug_commands_; |
2247 | 2248 |
2248 std::queue<linked_ptr<FenceCallback> > pending_readpixel_fences_; | 2249 std::queue<FenceCallback> pending_readpixel_fences_; |
2249 | 2250 |
2250 // After a second fence is inserted, both the GpuChannelMessageQueue and | 2251 // After a second fence is inserted, both the GpuChannelMessageQueue and |
2251 // CommandExecutor are descheduled. Once the first fence has completed, both | 2252 // CommandExecutor are descheduled. Once the first fence has completed, both |
2252 // get rescheduled. | 2253 // get rescheduled. |
2253 std::vector<std::unique_ptr<gl::GLFence>> deschedule_until_finished_fences_; | 2254 std::vector<std::unique_ptr<gl::GLFence>> deschedule_until_finished_fences_; |
2254 | 2255 |
2255 // Used to validate multisample renderbuffers if needed | 2256 // Used to validate multisample renderbuffers if needed |
2256 GLuint validation_texture_; | 2257 GLuint validation_texture_; |
2257 GLuint validation_fbo_multisample_; | 2258 GLuint validation_fbo_multisample_; |
2258 GLuint validation_fbo_; | 2259 GLuint validation_fbo_; |
(...skipping 8254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10513 // For ANGLE client version 2, GL_STREAM_READ is not available. | 10514 // For ANGLE client version 2, GL_STREAM_READ is not available. |
10514 const GLenum usage_hint = feature_info_->gl_version_info().is_angle ? | 10515 const GLenum usage_hint = feature_info_->gl_version_info().is_angle ? |
10515 GL_STATIC_DRAW : GL_STREAM_READ; | 10516 GL_STATIC_DRAW : GL_STREAM_READ; |
10516 glBufferData(GL_PIXEL_PACK_BUFFER_ARB, pixels_size, NULL, usage_hint); | 10517 glBufferData(GL_PIXEL_PACK_BUFFER_ARB, pixels_size, NULL, usage_hint); |
10517 GLenum error = glGetError(); | 10518 GLenum error = glGetError(); |
10518 if (error == GL_NO_ERROR) { | 10519 if (error == GL_NO_ERROR) { |
10519 // No need to worry about ES3 pixel pack parameters, because no | 10520 // No need to worry about ES3 pixel pack parameters, because no |
10520 // PIXEL_PACK_BUFFER is bound, and all these settings haven't been | 10521 // PIXEL_PACK_BUFFER is bound, and all these settings haven't been |
10521 // sent to GL. | 10522 // sent to GL. |
10522 glReadPixels(x, y, width, height, format, type, 0); | 10523 glReadPixels(x, y, width, height, format, type, 0); |
10523 pending_readpixel_fences_.push(linked_ptr<FenceCallback>( | 10524 pending_readpixel_fences_.push(FenceCallback()); |
10524 new FenceCallback())); | |
10525 WaitForReadPixels(base::Bind(&GLES2DecoderImpl::FinishReadPixels, | 10525 WaitForReadPixels(base::Bind(&GLES2DecoderImpl::FinishReadPixels, |
10526 base::AsWeakPtr(this), c, buffer)); | 10526 base::AsWeakPtr(this), c, buffer)); |
10527 glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0); | 10527 glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0); |
10528 return error::kNoError; | 10528 return error::kNoError; |
10529 } else { | 10529 } else { |
10530 // On error, unbind pack buffer and fall through to sync readpixels | 10530 // On error, unbind pack buffer and fall through to sync readpixels |
10531 glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0); | 10531 glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0); |
10532 glDeleteBuffersARB(1, &buffer); | 10532 glDeleteBuffersARB(1, &buffer); |
10533 } | 10533 } |
10534 } | 10534 } |
(...skipping 3829 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14364 if (!query_manager_.get()) | 14364 if (!query_manager_.get()) |
14365 return; | 14365 return; |
14366 if (!query_manager_->ProcessPendingQueries(did_finish)) | 14366 if (!query_manager_->ProcessPendingQueries(did_finish)) |
14367 current_decoder_error_ = error::kOutOfBounds; | 14367 current_decoder_error_ = error::kOutOfBounds; |
14368 } | 14368 } |
14369 | 14369 |
14370 // Note that if there are no pending readpixels right now, | 14370 // Note that if there are no pending readpixels right now, |
14371 // this function will call the callback immediately. | 14371 // this function will call the callback immediately. |
14372 void GLES2DecoderImpl::WaitForReadPixels(base::Closure callback) { | 14372 void GLES2DecoderImpl::WaitForReadPixels(base::Closure callback) { |
14373 if (features().use_async_readpixels && !pending_readpixel_fences_.empty()) { | 14373 if (features().use_async_readpixels && !pending_readpixel_fences_.empty()) { |
14374 pending_readpixel_fences_.back()->callbacks.push_back(callback); | 14374 pending_readpixel_fences_.back().callbacks.push_back(callback); |
14375 } else { | 14375 } else { |
14376 callback.Run(); | 14376 callback.Run(); |
14377 } | 14377 } |
14378 } | 14378 } |
14379 | 14379 |
14380 void GLES2DecoderImpl::ProcessPendingReadPixels(bool did_finish) { | 14380 void GLES2DecoderImpl::ProcessPendingReadPixels(bool did_finish) { |
14381 // Note: |did_finish| guarantees that the GPU has passed the fence but | 14381 // Note: |did_finish| guarantees that the GPU has passed the fence but |
14382 // we cannot assume that GLFence::HasCompleted() will return true yet as | 14382 // we cannot assume that GLFence::HasCompleted() will return true yet as |
14383 // that's not guaranteed by all GLFence implementations. | 14383 // that's not guaranteed by all GLFence implementations. |
14384 while (!pending_readpixel_fences_.empty() && | 14384 while (!pending_readpixel_fences_.empty() && |
14385 (did_finish || | 14385 (did_finish || |
14386 pending_readpixel_fences_.front()->fence->HasCompleted())) { | 14386 pending_readpixel_fences_.front().fence->HasCompleted())) { |
14387 std::vector<base::Closure> callbacks = | 14387 std::vector<base::Closure> callbacks = |
14388 pending_readpixel_fences_.front()->callbacks; | 14388 std::move(pending_readpixel_fences_.front().callbacks); |
14389 pending_readpixel_fences_.pop(); | 14389 pending_readpixel_fences_.pop(); |
14390 for (size_t i = 0; i < callbacks.size(); i++) { | 14390 for (size_t i = 0; i < callbacks.size(); i++) { |
14391 callbacks[i].Run(); | 14391 callbacks[i].Run(); |
14392 } | 14392 } |
14393 } | 14393 } |
14394 } | 14394 } |
14395 | 14395 |
14396 void GLES2DecoderImpl::ProcessDescheduleUntilFinished() { | 14396 void GLES2DecoderImpl::ProcessDescheduleUntilFinished() { |
14397 if (deschedule_until_finished_fences_.size() < 2) | 14397 if (deschedule_until_finished_fences_.size() < 2) |
14398 return; | 14398 return; |
(...skipping 3056 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17455 } | 17455 } |
17456 | 17456 |
17457 // Include the auto-generated part of this file. We split this because it means | 17457 // Include the auto-generated part of this file. We split this because it means |
17458 // we can easily edit the non-auto generated parts right here in this file | 17458 // we can easily edit the non-auto generated parts right here in this file |
17459 // instead of having to edit some template or the code generator. | 17459 // instead of having to edit some template or the code generator. |
17460 #include "base/macros.h" | 17460 #include "base/macros.h" |
17461 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 17461 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
17462 | 17462 |
17463 } // namespace gles2 | 17463 } // namespace gles2 |
17464 } // namespace gpu | 17464 } // namespace gpu |
OLD | NEW |