Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: gpu/command_buffer/service/gles2_cmd_decoder.cc

Issue 1964793002: Revert of [Reland 1] Pepper takes ownership of a mailbox before passing it to the texture layer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 1393 matching lines...) Expand 10 before | Expand all | Expand 10 after
2001 GLenum offscreen_target_stencil_format_; 2000 GLenum offscreen_target_stencil_format_;
2002 GLsizei offscreen_target_samples_; 2001 GLsizei offscreen_target_samples_;
2003 GLboolean offscreen_target_buffer_preserved_; 2002 GLboolean offscreen_target_buffer_preserved_;
2004 2003
2005 // The copy that is saved when SwapBuffers is called. 2004 // The copy that is saved when SwapBuffers is called.
2006 std::unique_ptr<BackFramebuffer> offscreen_saved_frame_buffer_; 2005 std::unique_ptr<BackFramebuffer> offscreen_saved_frame_buffer_;
2007 std::unique_ptr<BackTexture> offscreen_saved_color_texture_; 2006 std::unique_ptr<BackTexture> offscreen_saved_color_texture_;
2008 scoped_refptr<TextureRef> 2007 scoped_refptr<TextureRef>
2009 offscreen_saved_color_texture_info_; 2008 offscreen_saved_color_texture_info_;
2010 2009
2011 // When a client requests ownership of the swapped front buffer, all
2012 // information is saved in this structure, and |in_use| is set to true. When a
2013 // client releases ownership, |in_use| is set to false.
2014 //
2015 // An instance of this struct, with |in_use| = false may be reused instead of
2016 // making a new BackTexture.
2017 struct SavedBackTexture {
2018 std::unique_ptr<BackTexture> back_texture;
2019 scoped_refptr<TextureRef> texture_ref;
2020 bool in_use;
2021 };
2022 std::vector<SavedBackTexture> saved_back_textures_;
2023
2024 // If there's a SavedBackTexture that's not in use, takes that. Otherwise,
2025 // generates a new back texture.
2026 void CreateBackTexture();
2027 size_t create_back_texture_count_for_test_ = 0;
2028
2029 // Releases all saved BackTextures that are not in use by a client.
2030 void ReleaseNotInUseBackTextures();
2031
2032 // Releases all saved BackTextures.
2033 void ReleaseAllBackTextures();
2034
2035 size_t GetSavedBackTextureCountForTest() override;
2036 size_t GetCreatedBackTextureCountForTest() override;
2037
2038 // The copy that is used as the destination for multi-sample resolves. 2010 // The copy that is used as the destination for multi-sample resolves.
2039 std::unique_ptr<BackFramebuffer> offscreen_resolved_frame_buffer_; 2011 std::unique_ptr<BackFramebuffer> offscreen_resolved_frame_buffer_;
2040 std::unique_ptr<BackTexture> offscreen_resolved_color_texture_; 2012 std::unique_ptr<BackTexture> offscreen_resolved_color_texture_;
2041 GLenum offscreen_saved_color_format_; 2013 GLenum offscreen_saved_color_format_;
2042 2014
2043 std::unique_ptr<QueryManager> query_manager_; 2015 std::unique_ptr<QueryManager> query_manager_;
2044 2016
2045 std::unique_ptr<VertexArrayManager> vertex_array_manager_; 2017 std::unique_ptr<VertexArrayManager> vertex_array_manager_;
2046 2018
2047 std::unique_ptr<ImageManager> image_manager_; 2019 std::unique_ptr<ImageManager> image_manager_;
(...skipping 2054 matching lines...) Expand 10 before | Expand all | Expand 10 after
4102 framebuffer_state_.bound_draw_framebuffer = NULL; 4074 framebuffer_state_.bound_draw_framebuffer = NULL;
4103 state_.bound_renderbuffer = NULL; 4075 state_.bound_renderbuffer = NULL;
4104 4076
4105 if (offscreen_saved_color_texture_info_.get()) { 4077 if (offscreen_saved_color_texture_info_.get()) {
4106 DCHECK(offscreen_target_color_texture_); 4078 DCHECK(offscreen_target_color_texture_);
4107 DCHECK_EQ(offscreen_saved_color_texture_info_->service_id(), 4079 DCHECK_EQ(offscreen_saved_color_texture_info_->service_id(),
4108 offscreen_saved_color_texture_->id()); 4080 offscreen_saved_color_texture_->id());
4109 offscreen_saved_color_texture_->Invalidate(); 4081 offscreen_saved_color_texture_->Invalidate();
4110 offscreen_saved_color_texture_info_ = NULL; 4082 offscreen_saved_color_texture_info_ = NULL;
4111 } 4083 }
4112 ReleaseAllBackTextures();
4113 if (have_context) { 4084 if (have_context) {
4114 if (copy_texture_CHROMIUM_.get()) { 4085 if (copy_texture_CHROMIUM_.get()) {
4115 copy_texture_CHROMIUM_->Destroy(); 4086 copy_texture_CHROMIUM_->Destroy();
4116 copy_texture_CHROMIUM_.reset(); 4087 copy_texture_CHROMIUM_.reset();
4117 } 4088 }
4118 4089
4119 clear_framebuffer_blit_.reset(); 4090 clear_framebuffer_blit_.reset();
4120 4091
4121 if (state_.current_program.get()) { 4092 if (state_.current_program.get()) {
4122 program_manager()->UnuseProgram(shader_manager(), 4093 program_manager()->UnuseProgram(shader_manager(),
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
4241 } 4212 }
4242 4213
4243 void GLES2DecoderImpl::SetSurface( 4214 void GLES2DecoderImpl::SetSurface(
4244 const scoped_refptr<gfx::GLSurface>& surface) { 4215 const scoped_refptr<gfx::GLSurface>& surface) {
4245 DCHECK(context_->IsCurrent(NULL)); 4216 DCHECK(context_->IsCurrent(NULL));
4246 DCHECK(surface_.get()); 4217 DCHECK(surface_.get());
4247 surface_ = surface; 4218 surface_ = surface;
4248 RestoreCurrentFramebufferBindings(); 4219 RestoreCurrentFramebufferBindings();
4249 } 4220 }
4250 4221
4251 void GLES2DecoderImpl::TakeFrontBuffer(const Mailbox& mailbox) { 4222 void GLES2DecoderImpl::ProduceFrontBuffer(const Mailbox& mailbox) {
4252 if (!offscreen_saved_color_texture_.get()) { 4223 if (!offscreen_saved_color_texture_.get()) {
4253 DLOG(ERROR) << "Called TakeFrontBuffer on a non-offscreen context"; 4224 LOG(ERROR) << "Called ProduceFrontBuffer on a non-offscreen context";
4254 return; 4225 return;
4255 } 4226 }
4256
4257 if (!offscreen_saved_color_texture_info_.get()) { 4227 if (!offscreen_saved_color_texture_info_.get()) {
4258 GLuint service_id = offscreen_saved_color_texture_->id(); 4228 GLuint service_id = offscreen_saved_color_texture_->id();
4259 offscreen_saved_color_texture_info_ = TextureRef::Create( 4229 offscreen_saved_color_texture_info_ = TextureRef::Create(
4260 texture_manager(), 0, service_id); 4230 texture_manager(), 0, service_id);
4261 texture_manager()->SetTarget(offscreen_saved_color_texture_info_.get(), 4231 texture_manager()->SetTarget(offscreen_saved_color_texture_info_.get(),
4262 GL_TEXTURE_2D); 4232 GL_TEXTURE_2D);
4263 UpdateParentTextureInfo(); 4233 UpdateParentTextureInfo();
4264 } 4234 }
4265
4266 mailbox_manager()->ProduceTexture( 4235 mailbox_manager()->ProduceTexture(
4267 mailbox, offscreen_saved_color_texture_info_->texture()); 4236 mailbox, offscreen_saved_color_texture_info_->texture());
4268
4269 // Save the BackTexture and TextureRef.
4270 SavedBackTexture save;
4271 save.back_texture.swap(offscreen_saved_color_texture_);
4272 save.texture_ref = offscreen_saved_color_texture_info_;
4273 offscreen_saved_color_texture_info_ = nullptr;
4274 save.in_use = true;
4275 saved_back_textures_.push_back(std::move(save));
4276
4277 CreateBackTexture();
4278 }
4279
4280 void GLES2DecoderImpl::ReturnFrontBuffer(const Mailbox& mailbox, 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 DLOG(ERROR) << "Attempting to return a frontbuffer that was not saved.";
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 auto to_remove =
4331 std::remove_if(saved_back_textures_.begin(), saved_back_textures_.end(),
4332 [](const SavedBackTexture& saved_back_texture) {
4333 return !saved_back_texture.in_use;
4334 });
4335 saved_back_textures_.erase(to_remove, saved_back_textures_.end());
4336 }
4337
4338 void GLES2DecoderImpl::ReleaseAllBackTextures() {
4339 for (auto& saved_back_texture : saved_back_textures_) {
4340 // The texture will be destroyed by texture_ref's destructor.
4341 DCHECK(saved_back_texture.texture_ref);
4342 saved_back_texture.back_texture->Invalidate();
4343 }
4344 saved_back_textures_.clear();
4345 }
4346
4347 size_t GLES2DecoderImpl::GetSavedBackTextureCountForTest() {
4348 return saved_back_textures_.size();
4349 }
4350
4351 size_t GLES2DecoderImpl::GetCreatedBackTextureCountForTest() {
4352 return create_back_texture_count_for_test_;
4353 } 4237 }
4354 4238
4355 bool GLES2DecoderImpl::ResizeOffscreenFrameBuffer(const gfx::Size& size) { 4239 bool GLES2DecoderImpl::ResizeOffscreenFrameBuffer(const gfx::Size& size) {
4356 bool is_offscreen = !!offscreen_target_frame_buffer_.get(); 4240 bool is_offscreen = !!offscreen_target_frame_buffer_.get();
4357 if (!is_offscreen) { 4241 if (!is_offscreen) {
4358 LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer called " 4242 LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer called "
4359 << " with an onscreen framebuffer."; 4243 << " with an onscreen framebuffer.";
4360 return false; 4244 return false;
4361 } 4245 }
4362 4246
(...skipping 8532 matching lines...) Expand 10 before | Expand all | Expand 10 after
12895 "width", offscreen_size_.width(), "height", offscreen_size_.height()); 12779 "width", offscreen_size_.width(), "height", offscreen_size_.height());
12896 if (offscreen_size_ != offscreen_saved_color_texture_->size()) { 12780 if (offscreen_size_ != offscreen_saved_color_texture_->size()) {
12897 // Workaround for NVIDIA driver bug on OS X; crbug.com/89557, 12781 // Workaround for NVIDIA driver bug on OS X; crbug.com/89557,
12898 // crbug.com/94163. TODO(kbr): figure out reproduction so Apple will 12782 // crbug.com/94163. TODO(kbr): figure out reproduction so Apple will
12899 // fix this. 12783 // fix this.
12900 if (workarounds().needs_offscreen_buffer_workaround) { 12784 if (workarounds().needs_offscreen_buffer_workaround) {
12901 offscreen_saved_frame_buffer_->Create(); 12785 offscreen_saved_frame_buffer_->Create();
12902 glFinish(); 12786 glFinish();
12903 } 12787 }
12904 12788
12905 // The size has changed, so none of the cached BackTextures are useful
12906 // anymore.
12907 ReleaseNotInUseBackTextures();
12908
12909 // Allocate the offscreen saved color texture. 12789 // Allocate the offscreen saved color texture.
12910 DCHECK(offscreen_saved_color_format_); 12790 DCHECK(offscreen_saved_color_format_);
12911 offscreen_saved_color_texture_->AllocateStorage( 12791 offscreen_saved_color_texture_->AllocateStorage(
12912 offscreen_size_, offscreen_saved_color_format_, false); 12792 offscreen_size_, offscreen_saved_color_format_, false);
12913 12793
12914 offscreen_saved_frame_buffer_->AttachRenderTexture( 12794 offscreen_saved_frame_buffer_->AttachRenderTexture(
12915 offscreen_saved_color_texture_.get()); 12795 offscreen_saved_color_texture_.get());
12916 if (offscreen_size_.width() != 0 && offscreen_size_.height() != 0) { 12796 if (offscreen_size_.width() != 0 && offscreen_size_.height() != 0) {
12917 if (offscreen_saved_frame_buffer_->CheckStatus() != 12797 if (offscreen_saved_frame_buffer_->CheckStatus() !=
12918 GL_FRAMEBUFFER_COMPLETE) { 12798 GL_FRAMEBUFFER_COMPLETE) {
(...skipping 3628 matching lines...) Expand 10 before | Expand all | Expand 10 after
16547 } 16427 }
16548 16428
16549 // Include the auto-generated part of this file. We split this because it means 16429 // Include the auto-generated part of this file. We split this because it means
16550 // we can easily edit the non-auto generated parts right here in this file 16430 // we can easily edit the non-auto generated parts right here in this file
16551 // instead of having to edit some template or the code generator. 16431 // instead of having to edit some template or the code generator.
16552 #include "base/macros.h" 16432 #include "base/macros.h"
16553 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 16433 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
16554 16434
16555 } // namespace gles2 16435 } // namespace gles2
16556 } // namespace gpu 16436 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/gles2_cmd_decoder.h ('k') | gpu/command_buffer/service/gles2_cmd_decoder_mock.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698