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