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

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

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

Powered by Google App Engine
This is Rietveld 408576698