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> |
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 | 586 |
587 // Overridden from GLES2Decoder. | 587 // Overridden from GLES2Decoder. |
588 bool Initialize(const scoped_refptr<gfx::GLSurface>& surface, | 588 bool Initialize(const scoped_refptr<gfx::GLSurface>& surface, |
589 const scoped_refptr<gfx::GLContext>& context, | 589 const scoped_refptr<gfx::GLContext>& context, |
590 bool offscreen, | 590 bool offscreen, |
591 const gfx::Size& offscreen_size, | 591 const gfx::Size& offscreen_size, |
592 const DisallowedFeatures& disallowed_features, | 592 const DisallowedFeatures& disallowed_features, |
593 const std::vector<int32_t>& attribs) override; | 593 const std::vector<int32_t>& attribs) override; |
594 void Destroy(bool have_context) override; | 594 void Destroy(bool have_context) override; |
595 void SetSurface(const scoped_refptr<gfx::GLSurface>& surface) override; | 595 void SetSurface(const scoped_refptr<gfx::GLSurface>& surface) override; |
596 void TakeFrontBuffer(const Mailbox& mailbox) override; | 596 void ProduceFrontBuffer(const Mailbox& mailbox) override; |
597 void ReturnFrontBuffer(const Mailbox& mailbox, bool is_lost) override; | |
598 bool ResizeOffscreenFrameBuffer(const gfx::Size& size) override; | 597 bool ResizeOffscreenFrameBuffer(const gfx::Size& size) override; |
599 void UpdateParentTextureInfo(); | 598 void UpdateParentTextureInfo(); |
600 bool MakeCurrent() override; | 599 bool MakeCurrent() override; |
601 GLES2Util* GetGLES2Util() override { return &util_; } | 600 GLES2Util* GetGLES2Util() override { return &util_; } |
602 gfx::GLContext* GetGLContext() override { return context_.get(); } | 601 gfx::GLContext* GetGLContext() override { return context_.get(); } |
603 ContextGroup* GetContextGroup() override { return group_.get(); } | 602 ContextGroup* GetContextGroup() override { return group_.get(); } |
604 Capabilities GetCapabilities() override; | 603 Capabilities GetCapabilities() override; |
605 void RestoreState(const ContextState* prev_state) override; | 604 void RestoreState(const ContextState* prev_state) override; |
606 | 605 |
607 void RestoreActiveTexture() const override { state_.RestoreActiveTexture(); } | 606 void RestoreActiveTexture() const override { state_.RestoreActiveTexture(); } |
(...skipping 1380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1988 GLenum offscreen_target_stencil_format_; | 1987 GLenum offscreen_target_stencil_format_; |
1989 GLsizei offscreen_target_samples_; | 1988 GLsizei offscreen_target_samples_; |
1990 GLboolean offscreen_target_buffer_preserved_; | 1989 GLboolean offscreen_target_buffer_preserved_; |
1991 | 1990 |
1992 // The copy that is saved when SwapBuffers is called. | 1991 // The copy that is saved when SwapBuffers is called. |
1993 std::unique_ptr<BackFramebuffer> offscreen_saved_frame_buffer_; | 1992 std::unique_ptr<BackFramebuffer> offscreen_saved_frame_buffer_; |
1994 std::unique_ptr<BackTexture> offscreen_saved_color_texture_; | 1993 std::unique_ptr<BackTexture> offscreen_saved_color_texture_; |
1995 scoped_refptr<TextureRef> | 1994 scoped_refptr<TextureRef> |
1996 offscreen_saved_color_texture_info_; | 1995 offscreen_saved_color_texture_info_; |
1997 | 1996 |
1998 // When a client requests ownership of the swapped front buffer, all | |
1999 // information is saved in this structure, and |in_use| is set to true. When a | |
2000 // client releases ownership, |in_use| is set to false. | |
2001 // | |
2002 // An instance of this struct, with |in_use| = false may be reused instead of | |
2003 // making a new BackTexture. | |
2004 struct SavedBackTexture { | |
2005 std::unique_ptr<BackTexture> back_texture; | |
2006 scoped_refptr<TextureRef> texture_ref; | |
2007 bool in_use; | |
2008 }; | |
2009 std::vector<SavedBackTexture> saved_back_textures_; | |
2010 | |
2011 // If there's a SavedBackTexture that's not in use, takes that. Otherwise, | |
2012 // generates a new back texture. | |
2013 void CreateBackTexture(); | |
2014 size_t create_back_texture_count_for_test_ = 0; | |
2015 | |
2016 // Releases all saved BackTextures that are not in use by a client. | |
2017 void ReleaseNotInUseBackTextures(); | |
2018 | |
2019 // Releases all saved BackTextures. | |
2020 void ReleaseAllBackTextures(); | |
2021 | |
2022 size_t GetSavedBackTextureCountForTest() override; | |
2023 size_t GetCreatedBackTextureCountForTest() override; | |
2024 | |
2025 // The copy that is used as the destination for multi-sample resolves. | 1997 // The copy that is used as the destination for multi-sample resolves. |
2026 std::unique_ptr<BackFramebuffer> offscreen_resolved_frame_buffer_; | 1998 std::unique_ptr<BackFramebuffer> offscreen_resolved_frame_buffer_; |
2027 std::unique_ptr<BackTexture> offscreen_resolved_color_texture_; | 1999 std::unique_ptr<BackTexture> offscreen_resolved_color_texture_; |
2028 GLenum offscreen_saved_color_format_; | 2000 GLenum offscreen_saved_color_format_; |
2029 | 2001 |
2030 std::unique_ptr<QueryManager> query_manager_; | 2002 std::unique_ptr<QueryManager> query_manager_; |
2031 | 2003 |
2032 std::unique_ptr<VertexArrayManager> vertex_array_manager_; | 2004 std::unique_ptr<VertexArrayManager> vertex_array_manager_; |
2033 | 2005 |
2034 std::unique_ptr<ImageManager> image_manager_; | 2006 std::unique_ptr<ImageManager> image_manager_; |
(...skipping 2053 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4088 framebuffer_state_.bound_draw_framebuffer = NULL; | 4060 framebuffer_state_.bound_draw_framebuffer = NULL; |
4089 state_.bound_renderbuffer = NULL; | 4061 state_.bound_renderbuffer = NULL; |
4090 | 4062 |
4091 if (offscreen_saved_color_texture_info_.get()) { | 4063 if (offscreen_saved_color_texture_info_.get()) { |
4092 DCHECK(offscreen_target_color_texture_); | 4064 DCHECK(offscreen_target_color_texture_); |
4093 DCHECK_EQ(offscreen_saved_color_texture_info_->service_id(), | 4065 DCHECK_EQ(offscreen_saved_color_texture_info_->service_id(), |
4094 offscreen_saved_color_texture_->id()); | 4066 offscreen_saved_color_texture_->id()); |
4095 offscreen_saved_color_texture_->Invalidate(); | 4067 offscreen_saved_color_texture_->Invalidate(); |
4096 offscreen_saved_color_texture_info_ = NULL; | 4068 offscreen_saved_color_texture_info_ = NULL; |
4097 } | 4069 } |
4098 ReleaseAllBackTextures(); | |
4099 if (have_context) { | 4070 if (have_context) { |
4100 if (copy_texture_CHROMIUM_.get()) { | 4071 if (copy_texture_CHROMIUM_.get()) { |
4101 copy_texture_CHROMIUM_->Destroy(); | 4072 copy_texture_CHROMIUM_->Destroy(); |
4102 copy_texture_CHROMIUM_.reset(); | 4073 copy_texture_CHROMIUM_.reset(); |
4103 } | 4074 } |
4104 | 4075 |
4105 clear_framebuffer_blit_.reset(); | 4076 clear_framebuffer_blit_.reset(); |
4106 | 4077 |
4107 if (state_.current_program.get()) { | 4078 if (state_.current_program.get()) { |
4108 program_manager()->UnuseProgram(shader_manager(), | 4079 program_manager()->UnuseProgram(shader_manager(), |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4227 } | 4198 } |
4228 | 4199 |
4229 void GLES2DecoderImpl::SetSurface( | 4200 void GLES2DecoderImpl::SetSurface( |
4230 const scoped_refptr<gfx::GLSurface>& surface) { | 4201 const scoped_refptr<gfx::GLSurface>& surface) { |
4231 DCHECK(context_->IsCurrent(NULL)); | 4202 DCHECK(context_->IsCurrent(NULL)); |
4232 DCHECK(surface_.get()); | 4203 DCHECK(surface_.get()); |
4233 surface_ = surface; | 4204 surface_ = surface; |
4234 RestoreCurrentFramebufferBindings(); | 4205 RestoreCurrentFramebufferBindings(); |
4235 } | 4206 } |
4236 | 4207 |
4237 void GLES2DecoderImpl::TakeFrontBuffer(const Mailbox& mailbox) { | 4208 void GLES2DecoderImpl::ProduceFrontBuffer(const Mailbox& mailbox) { |
4238 if (!offscreen_saved_color_texture_.get()) { | 4209 if (!offscreen_saved_color_texture_.get()) { |
4239 DLOG(ERROR) << "Called TakeFrontBuffer on a non-offscreen context"; | 4210 LOG(ERROR) << "Called ProduceFrontBuffer on a non-offscreen context"; |
4240 return; | 4211 return; |
4241 } | 4212 } |
4242 | |
4243 if (!offscreen_saved_color_texture_info_.get()) { | 4213 if (!offscreen_saved_color_texture_info_.get()) { |
4244 GLuint service_id = offscreen_saved_color_texture_->id(); | 4214 GLuint service_id = offscreen_saved_color_texture_->id(); |
4245 offscreen_saved_color_texture_info_ = TextureRef::Create( | 4215 offscreen_saved_color_texture_info_ = TextureRef::Create( |
4246 texture_manager(), 0, service_id); | 4216 texture_manager(), 0, service_id); |
4247 texture_manager()->SetTarget(offscreen_saved_color_texture_info_.get(), | 4217 texture_manager()->SetTarget(offscreen_saved_color_texture_info_.get(), |
4248 GL_TEXTURE_2D); | 4218 GL_TEXTURE_2D); |
4249 UpdateParentTextureInfo(); | 4219 UpdateParentTextureInfo(); |
4250 } | 4220 } |
4251 | |
4252 mailbox_manager()->ProduceTexture( | 4221 mailbox_manager()->ProduceTexture( |
4253 mailbox, offscreen_saved_color_texture_info_->texture()); | 4222 mailbox, offscreen_saved_color_texture_info_->texture()); |
4254 | |
4255 // Save the BackTexture and TextureRef. | |
4256 SavedBackTexture save; | |
4257 save.back_texture.swap(offscreen_saved_color_texture_); | |
4258 save.texture_ref = offscreen_saved_color_texture_info_; | |
4259 offscreen_saved_color_texture_info_ = nullptr; | |
4260 save.in_use = true; | |
4261 saved_back_textures_.push_back(std::move(save)); | |
4262 | |
4263 CreateBackTexture(); | |
4264 } | |
4265 | |
4266 void GLES2DecoderImpl::ReturnFrontBuffer(const Mailbox& mailbox, bool is_lost) { | |
4267 Texture* texture = mailbox_manager()->ConsumeTexture(mailbox); | |
4268 for (auto it = saved_back_textures_.begin(); it != saved_back_textures_.end(); | |
4269 ++it) { | |
4270 if (texture != it->texture_ref->texture()) | |
4271 continue; | |
4272 | |
4273 if (is_lost || it->back_texture->size() != offscreen_size_) { | |
4274 it->back_texture->Invalidate(); | |
4275 saved_back_textures_.erase(it); | |
4276 return; | |
4277 } | |
4278 | |
4279 it->in_use = false; | |
4280 return; | |
4281 } | |
4282 | |
4283 DLOG(ERROR) << "Attempting to return a frontbuffer that was not saved."; | |
4284 } | |
4285 | |
4286 void GLES2DecoderImpl::CreateBackTexture() { | |
4287 for (auto it = saved_back_textures_.begin(); it != saved_back_textures_.end(); | |
4288 ++it) { | |
4289 if (it->in_use) | |
4290 continue; | |
4291 | |
4292 if (it->back_texture->size() != offscreen_size_) | |
4293 continue; | |
4294 offscreen_saved_color_texture_ = std::move(it->back_texture); | |
4295 offscreen_saved_color_texture_info_ = it->texture_ref; | |
4296 saved_back_textures_.erase(it); | |
4297 return; | |
4298 } | |
4299 | |
4300 ++create_back_texture_count_for_test_; | |
4301 offscreen_saved_color_texture_.reset( | |
4302 new BackTexture(memory_tracker(), &state_)); | |
4303 offscreen_saved_color_texture_->Create(); | |
4304 offscreen_saved_color_texture_->AllocateStorage( | |
4305 offscreen_size_, offscreen_saved_color_format_, false); | |
4306 offscreen_saved_frame_buffer_->AttachRenderTexture( | |
4307 offscreen_saved_color_texture_.get()); | |
4308 } | |
4309 | |
4310 void GLES2DecoderImpl::ReleaseNotInUseBackTextures() { | |
4311 for (auto& saved_back_texture : saved_back_textures_) { | |
4312 if (!saved_back_texture.in_use) | |
4313 saved_back_texture.back_texture->Invalidate(); | |
4314 } | |
4315 | |
4316 std::remove_if(saved_back_textures_.begin(), saved_back_textures_.end(), | |
4317 [](const SavedBackTexture& saved_back_texture) { | |
4318 return !saved_back_texture.in_use; | |
4319 }); | |
4320 } | |
4321 | |
4322 void GLES2DecoderImpl::ReleaseAllBackTextures() { | |
4323 for (auto& saved_back_texture : saved_back_textures_) { | |
4324 // The texture will be destroyed by texture_ref's destructor. | |
4325 DCHECK(saved_back_texture.texture_ref); | |
4326 saved_back_texture.back_texture->Invalidate(); | |
4327 } | |
4328 saved_back_textures_.clear(); | |
4329 } | |
4330 | |
4331 size_t GLES2DecoderImpl::GetSavedBackTextureCountForTest() { | |
4332 return saved_back_textures_.size(); | |
4333 } | |
4334 | |
4335 size_t GLES2DecoderImpl::GetCreatedBackTextureCountForTest() { | |
4336 return create_back_texture_count_for_test_; | |
4337 } | 4223 } |
4338 | 4224 |
4339 bool GLES2DecoderImpl::ResizeOffscreenFrameBuffer(const gfx::Size& size) { | 4225 bool GLES2DecoderImpl::ResizeOffscreenFrameBuffer(const gfx::Size& size) { |
4340 bool is_offscreen = !!offscreen_target_frame_buffer_.get(); | 4226 bool is_offscreen = !!offscreen_target_frame_buffer_.get(); |
4341 if (!is_offscreen) { | 4227 if (!is_offscreen) { |
4342 LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer called " | 4228 LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer called " |
4343 << " with an onscreen framebuffer."; | 4229 << " with an onscreen framebuffer."; |
4344 return false; | 4230 return false; |
4345 } | 4231 } |
4346 | 4232 |
(...skipping 8475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12822 "width", offscreen_size_.width(), "height", offscreen_size_.height()); | 12708 "width", offscreen_size_.width(), "height", offscreen_size_.height()); |
12823 if (offscreen_size_ != offscreen_saved_color_texture_->size()) { | 12709 if (offscreen_size_ != offscreen_saved_color_texture_->size()) { |
12824 // Workaround for NVIDIA driver bug on OS X; crbug.com/89557, | 12710 // Workaround for NVIDIA driver bug on OS X; crbug.com/89557, |
12825 // crbug.com/94163. TODO(kbr): figure out reproduction so Apple will | 12711 // crbug.com/94163. TODO(kbr): figure out reproduction so Apple will |
12826 // fix this. | 12712 // fix this. |
12827 if (workarounds().needs_offscreen_buffer_workaround) { | 12713 if (workarounds().needs_offscreen_buffer_workaround) { |
12828 offscreen_saved_frame_buffer_->Create(); | 12714 offscreen_saved_frame_buffer_->Create(); |
12829 glFinish(); | 12715 glFinish(); |
12830 } | 12716 } |
12831 | 12717 |
12832 // The size has changed, so none of the cached BackTextures are useful | |
12833 // anymore. | |
12834 ReleaseNotInUseBackTextures(); | |
12835 | |
12836 // Allocate the offscreen saved color texture. | 12718 // Allocate the offscreen saved color texture. |
12837 DCHECK(offscreen_saved_color_format_); | 12719 DCHECK(offscreen_saved_color_format_); |
12838 offscreen_saved_color_texture_->AllocateStorage( | 12720 offscreen_saved_color_texture_->AllocateStorage( |
12839 offscreen_size_, offscreen_saved_color_format_, false); | 12721 offscreen_size_, offscreen_saved_color_format_, false); |
12840 | 12722 |
12841 offscreen_saved_frame_buffer_->AttachRenderTexture( | 12723 offscreen_saved_frame_buffer_->AttachRenderTexture( |
12842 offscreen_saved_color_texture_.get()); | 12724 offscreen_saved_color_texture_.get()); |
12843 if (offscreen_size_.width() != 0 && offscreen_size_.height() != 0) { | 12725 if (offscreen_size_.width() != 0 && offscreen_size_.height() != 0) { |
12844 if (offscreen_saved_frame_buffer_->CheckStatus() != | 12726 if (offscreen_saved_frame_buffer_->CheckStatus() != |
12845 GL_FRAMEBUFFER_COMPLETE) { | 12727 GL_FRAMEBUFFER_COMPLETE) { |
(...skipping 3629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16475 } | 16357 } |
16476 | 16358 |
16477 // Include the auto-generated part of this file. We split this because it means | 16359 // Include the auto-generated part of this file. We split this because it means |
16478 // we can easily edit the non-auto generated parts right here in this file | 16360 // we can easily edit the non-auto generated parts right here in this file |
16479 // instead of having to edit some template or the code generator. | 16361 // instead of having to edit some template or the code generator. |
16480 #include "base/macros.h" | 16362 #include "base/macros.h" |
16481 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 16363 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
16482 | 16364 |
16483 } // namespace gles2 | 16365 } // namespace gles2 |
16484 } // namespace gpu | 16366 } // namespace gpu |
OLD | NEW |