OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <list> | 10 #include <list> |
11 #include <map> | 11 #include <map> |
12 #include <string> | 12 #include <string> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/atomicops.h" | 15 #include "base/atomicops.h" |
16 #include "base/at_exit.h" | 16 #include "base/at_exit.h" |
17 #include "base/callback.h" | 17 #include "base/bind.h" |
18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
19 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
20 #include "build/build_config.h" | 20 #include "build/build_config.h" |
21 #define GLES2_GPU_SERVICE 1 | 21 #define GLES2_GPU_SERVICE 1 |
22 #include "gpu/command_buffer/common/gles2_cmd_format.h" | 22 #include "gpu/command_buffer/common/gles2_cmd_format.h" |
23 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 23 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
24 #include "gpu/command_buffer/common/id_allocator.h" | 24 #include "gpu/command_buffer/common/id_allocator.h" |
25 #include "gpu/command_buffer/common/trace_event.h" | 25 #include "gpu/command_buffer/common/trace_event.h" |
26 #include "gpu/command_buffer/service/buffer_manager.h" | 26 #include "gpu/command_buffer/service/buffer_manager.h" |
27 #include "gpu/command_buffer/service/cmd_buffer_engine.h" | 27 #include "gpu/command_buffer/service/cmd_buffer_engine.h" |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 virtual bool ResizeOffscreenFrameBuffer(const gfx::Size& size); | 504 virtual bool ResizeOffscreenFrameBuffer(const gfx::Size& size); |
505 void UpdateParentTextureInfo(); | 505 void UpdateParentTextureInfo(); |
506 virtual bool MakeCurrent(); | 506 virtual bool MakeCurrent(); |
507 virtual void ReleaseCurrent(); | 507 virtual void ReleaseCurrent(); |
508 virtual GLES2Util* GetGLES2Util() { return &util_; } | 508 virtual GLES2Util* GetGLES2Util() { return &util_; } |
509 virtual gfx::GLContext* GetGLContext() { return context_.get(); } | 509 virtual gfx::GLContext* GetGLContext() { return context_.get(); } |
510 virtual gfx::GLSurface* GetGLSurface() { return surface_.get(); } | 510 virtual gfx::GLSurface* GetGLSurface() { return surface_.get(); } |
511 virtual ContextGroup* GetContextGroup() { return group_.get(); } | 511 virtual ContextGroup* GetContextGroup() { return group_.get(); } |
512 | 512 |
513 virtual void SetGLError(GLenum error, const char* msg); | 513 virtual void SetGLError(GLenum error, const char* msg); |
514 virtual void SetResizeCallback(Callback1<gfx::Size>::Type* callback); | 514 virtual void SetResizeCallback( |
| 515 const base::Callback<void(gfx::Size)>& callback); |
515 | 516 |
516 virtual void SetSwapBuffersCallback(Callback0::Type* callback); | 517 virtual void SetSwapBuffersCallback(const base::Closure& callback); |
517 | 518 |
518 virtual void SetStreamTextureManager(StreamTextureManager* manager); | 519 virtual void SetStreamTextureManager(StreamTextureManager* manager); |
519 virtual bool GetServiceTextureId(uint32 client_texture_id, | 520 virtual bool GetServiceTextureId(uint32 client_texture_id, |
520 uint32* service_texture_id); | 521 uint32* service_texture_id); |
521 | 522 |
522 // Restores the current state to the user's settings. | 523 // Restores the current state to the user's settings. |
523 void RestoreCurrentFramebufferBindings(); | 524 void RestoreCurrentFramebufferBindings(); |
524 void RestoreCurrentRenderbufferBindings(); | 525 void RestoreCurrentRenderbufferBindings(); |
525 void RestoreCurrentTexture2DBindings(); | 526 void RestoreCurrentTexture2DBindings(); |
526 | 527 |
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1364 | 1365 |
1365 // The copy that is saved when SwapBuffers is called. | 1366 // The copy that is saved when SwapBuffers is called. |
1366 scoped_ptr<FrameBuffer> offscreen_saved_frame_buffer_; | 1367 scoped_ptr<FrameBuffer> offscreen_saved_frame_buffer_; |
1367 scoped_ptr<Texture> offscreen_saved_color_texture_; | 1368 scoped_ptr<Texture> offscreen_saved_color_texture_; |
1368 | 1369 |
1369 // The copy that is used as the destination for multi-sample resolves. | 1370 // The copy that is used as the destination for multi-sample resolves. |
1370 scoped_ptr<FrameBuffer> offscreen_resolved_frame_buffer_; | 1371 scoped_ptr<FrameBuffer> offscreen_resolved_frame_buffer_; |
1371 scoped_ptr<Texture> offscreen_resolved_color_texture_; | 1372 scoped_ptr<Texture> offscreen_resolved_color_texture_; |
1372 GLenum offscreen_saved_color_format_; | 1373 GLenum offscreen_saved_color_format_; |
1373 | 1374 |
1374 scoped_ptr<Callback1<gfx::Size>::Type> resize_callback_; | 1375 base::Callback<void(gfx::Size)> resize_callback_; |
1375 | 1376 |
1376 scoped_ptr<Callback0::Type> swap_buffers_callback_; | 1377 base::Closure swap_buffers_callback_; |
1377 | 1378 |
1378 StreamTextureManager* stream_texture_manager_; | 1379 StreamTextureManager* stream_texture_manager_; |
1379 | 1380 |
1380 // The format of the back buffer_ | 1381 // The format of the back buffer_ |
1381 GLenum back_buffer_color_format_; | 1382 GLenum back_buffer_color_format_; |
1382 bool back_buffer_has_depth_; | 1383 bool back_buffer_has_depth_; |
1383 bool back_buffer_has_stencil_; | 1384 bool back_buffer_has_stencil_; |
1384 | 1385 |
1385 bool teximage2d_faster_than_texsubimage2d_; | 1386 bool teximage2d_faster_than_texsubimage2d_; |
1386 bool bufferdata_faster_than_buffersubdata_; | 1387 bool bufferdata_faster_than_buffersubdata_; |
(...skipping 1124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2511 GL_CLAMP_TO_EDGE); | 2512 GL_CLAMP_TO_EDGE); |
2512 parent_texture_manager->SetParameter( | 2513 parent_texture_manager->SetParameter( |
2513 feature_info_, | 2514 feature_info_, |
2514 info, | 2515 info, |
2515 GL_TEXTURE_WRAP_T, | 2516 GL_TEXTURE_WRAP_T, |
2516 GL_CLAMP_TO_EDGE); | 2517 GL_CLAMP_TO_EDGE); |
2517 } | 2518 } |
2518 } | 2519 } |
2519 | 2520 |
2520 void GLES2DecoderImpl::SetResizeCallback( | 2521 void GLES2DecoderImpl::SetResizeCallback( |
2521 Callback1<gfx::Size>::Type* callback) { | 2522 const base::Callback<void(gfx::Size)>& callback) { |
2522 resize_callback_.reset(callback); | 2523 resize_callback_ = callback; |
2523 } | 2524 } |
2524 | 2525 |
2525 void GLES2DecoderImpl::SetSwapBuffersCallback(Callback0::Type* callback) { | 2526 void GLES2DecoderImpl::SetSwapBuffersCallback(const base::Closure& callback) { |
2526 swap_buffers_callback_.reset(callback); | 2527 swap_buffers_callback_ = callback; |
2527 } | 2528 } |
2528 | 2529 |
2529 void GLES2DecoderImpl::SetStreamTextureManager(StreamTextureManager* manager) { | 2530 void GLES2DecoderImpl::SetStreamTextureManager(StreamTextureManager* manager) { |
2530 stream_texture_manager_ = manager; | 2531 stream_texture_manager_ = manager; |
2531 } | 2532 } |
2532 | 2533 |
2533 bool GLES2DecoderImpl::GetServiceTextureId(uint32 client_texture_id, | 2534 bool GLES2DecoderImpl::GetServiceTextureId(uint32 client_texture_id, |
2534 uint32* service_texture_id) { | 2535 uint32* service_texture_id) { |
2535 TextureManager::TextureInfo* texture = | 2536 TextureManager::TextureInfo* texture = |
2536 texture_manager()->GetTextureInfo(client_texture_id); | 2537 texture_manager()->GetTextureInfo(client_texture_id); |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2789 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(TOUCH_UI) | 2790 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(TOUCH_UI) |
2790 // Make sure that we are done drawing to the back buffer before resizing. | 2791 // Make sure that we are done drawing to the back buffer before resizing. |
2791 glFinish(); | 2792 glFinish(); |
2792 #endif | 2793 #endif |
2793 bool is_offscreen = !!offscreen_target_frame_buffer_.get(); | 2794 bool is_offscreen = !!offscreen_target_frame_buffer_.get(); |
2794 if (is_offscreen) { | 2795 if (is_offscreen) { |
2795 if (!ResizeOffscreenFrameBuffer(gfx::Size(width, height))) | 2796 if (!ResizeOffscreenFrameBuffer(gfx::Size(width, height))) |
2796 return error::kLostContext; | 2797 return error::kLostContext; |
2797 } | 2798 } |
2798 | 2799 |
2799 if (resize_callback_.get()) { | 2800 if (!resize_callback_.is_null()) { |
2800 resize_callback_->Run(gfx::Size(width, height)); | 2801 resize_callback_.Run(gfx::Size(width, height)); |
2801 DCHECK(context_->IsCurrent(surface_.get())); | 2802 DCHECK(context_->IsCurrent(surface_.get())); |
2802 if (!context_->IsCurrent(surface_.get())) | 2803 if (!context_->IsCurrent(surface_.get())) |
2803 return error::kLostContext; | 2804 return error::kLostContext; |
2804 } | 2805 } |
2805 | 2806 |
2806 return error::kNoError; | 2807 return error::kNoError; |
2807 } | 2808 } |
2808 | 2809 |
2809 const char* GLES2DecoderImpl::GetCommandName(unsigned int command_id) const { | 2810 const char* GLES2DecoderImpl::GetCommandName(unsigned int command_id) const { |
2810 if (command_id > kStartPoint && command_id < kNumCommands) { | 2811 if (command_id > kStartPoint && command_id < kNumCommands) { |
(...skipping 4319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7130 | 7131 |
7131 UpdateParentTextureInfo(); | 7132 UpdateParentTextureInfo(); |
7132 } | 7133 } |
7133 | 7134 |
7134 ScopedGLErrorSuppressor suppressor(this); | 7135 ScopedGLErrorSuppressor suppressor(this); |
7135 | 7136 |
7136 if (IsOffscreenBufferMultisampled()) { | 7137 if (IsOffscreenBufferMultisampled()) { |
7137 // For multisampled buffers, bind the resolved frame buffer so that | 7138 // For multisampled buffers, bind the resolved frame buffer so that |
7138 // callbacks can call ReadPixels or CopyTexImage2D. | 7139 // callbacks can call ReadPixels or CopyTexImage2D. |
7139 ScopedResolvedFrameBufferBinder binder(this, true, false); | 7140 ScopedResolvedFrameBufferBinder binder(this, true, false); |
7140 if (swap_buffers_callback_.get()) { | 7141 if (!swap_buffers_callback_.is_null()) { |
7141 swap_buffers_callback_->Run(); | 7142 swap_buffers_callback_.Run(); |
7142 } | 7143 } |
7143 | 7144 |
7144 return error::kNoError; | 7145 return error::kNoError; |
7145 } else { | 7146 } else { |
7146 ScopedFrameBufferBinder binder(this, | 7147 ScopedFrameBufferBinder binder(this, |
7147 offscreen_target_frame_buffer_->id()); | 7148 offscreen_target_frame_buffer_->id()); |
7148 | 7149 |
7149 if (surface_->IsOffscreen()) { | 7150 if (surface_->IsOffscreen()) { |
7150 // Copy the target frame buffer to the saved offscreen texture. | 7151 // Copy the target frame buffer to the saved offscreen texture. |
7151 offscreen_saved_color_texture_->Copy( | 7152 offscreen_saved_color_texture_->Copy( |
7152 offscreen_saved_color_texture_->size(), | 7153 offscreen_saved_color_texture_->size(), |
7153 offscreen_saved_color_format_); | 7154 offscreen_saved_color_format_); |
7154 | 7155 |
7155 // Ensure the side effects of the copy are visible to the parent | 7156 // Ensure the side effects of the copy are visible to the parent |
7156 // context. There is no need to do this for ANGLE because it uses a | 7157 // context. There is no need to do this for ANGLE because it uses a |
7157 // single D3D device for all contexts. | 7158 // single D3D device for all contexts. |
7158 if (!IsAngle()) | 7159 if (!IsAngle()) |
7159 glFlush(); | 7160 glFlush(); |
7160 } | 7161 } |
7161 | 7162 |
7162 // Run the callback with |binder| in scope, so that the callback can call | 7163 // Run the callback with |binder| in scope, so that the callback can call |
7163 // ReadPixels or CopyTexImage2D. | 7164 // ReadPixels or CopyTexImage2D. |
7164 if (swap_buffers_callback_.get()) { | 7165 if (!swap_buffers_callback_.is_null()) { |
7165 swap_buffers_callback_->Run(); | 7166 swap_buffers_callback_.Run(); |
7166 } | 7167 } |
7167 | 7168 |
7168 return error::kNoError; | 7169 return error::kNoError; |
7169 } | 7170 } |
7170 } else { | 7171 } else { |
7171 TRACE_EVENT1("gpu", "GLContext::SwapBuffers", "frame", this_frame_number); | 7172 TRACE_EVENT1("gpu", "GLContext::SwapBuffers", "frame", this_frame_number); |
7172 if (!surface_->SwapBuffers()) { | 7173 if (!surface_->SwapBuffers()) { |
7173 LOG(ERROR) << "Context lost because SwapBuffers failed."; | 7174 LOG(ERROR) << "Context lost because SwapBuffers failed."; |
7174 return error::kLostContext; | 7175 return error::kLostContext; |
7175 } | 7176 } |
7176 } | 7177 } |
7177 | 7178 |
7178 if (swap_buffers_callback_.get()) { | 7179 if (!swap_buffers_callback_.is_null()) { |
7179 swap_buffers_callback_->Run(); | 7180 swap_buffers_callback_.Run(); |
7180 } | 7181 } |
7181 | 7182 |
7182 return error::kNoError; | 7183 return error::kNoError; |
7183 } | 7184 } |
7184 | 7185 |
7185 error::Error GLES2DecoderImpl::HandleEnableFeatureCHROMIUM( | 7186 error::Error GLES2DecoderImpl::HandleEnableFeatureCHROMIUM( |
7186 uint32 immediate_data_size, const gles2::EnableFeatureCHROMIUM& c) { | 7187 uint32 immediate_data_size, const gles2::EnableFeatureCHROMIUM& c) { |
7187 Bucket* bucket = GetBucket(c.bucket_id); | 7188 Bucket* bucket = GetBucket(c.bucket_id); |
7188 if (!bucket || bucket->size() == 0) { | 7189 if (!bucket || bucket->size() == 0) { |
7189 return error::kInvalidArguments; | 7190 return error::kInvalidArguments; |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7484 return error::kNoError; | 7485 return error::kNoError; |
7485 } | 7486 } |
7486 | 7487 |
7487 // Include the auto-generated part of this file. We split this because it means | 7488 // Include the auto-generated part of this file. We split this because it means |
7488 // we can easily edit the non-auto generated parts right here in this file | 7489 // we can easily edit the non-auto generated parts right here in this file |
7489 // instead of having to edit some template or the code generator. | 7490 // instead of having to edit some template or the code generator. |
7490 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 7491 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
7491 | 7492 |
7492 } // namespace gles2 | 7493 } // namespace gles2 |
7493 } // namespace gpu | 7494 } // namespace gpu |
OLD | NEW |