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

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

Issue 1912833002: 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: Comments from bbudge. 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 1380 matching lines...) Expand 10 before | Expand all | Expand 10 after
1987 GLenum offscreen_target_stencil_format_; 1988 GLenum offscreen_target_stencil_format_;
1988 GLsizei offscreen_target_samples_; 1989 GLsizei offscreen_target_samples_;
1989 GLboolean offscreen_target_buffer_preserved_; 1990 GLboolean offscreen_target_buffer_preserved_;
1990 1991
1991 // The copy that is saved when SwapBuffers is called. 1992 // The copy that is saved when SwapBuffers is called.
1992 std::unique_ptr<BackFramebuffer> offscreen_saved_frame_buffer_; 1993 std::unique_ptr<BackFramebuffer> offscreen_saved_frame_buffer_;
1993 std::unique_ptr<BackTexture> offscreen_saved_color_texture_; 1994 std::unique_ptr<BackTexture> offscreen_saved_color_texture_;
1994 scoped_refptr<TextureRef> 1995 scoped_refptr<TextureRef>
1995 offscreen_saved_color_texture_info_; 1996 offscreen_saved_color_texture_info_;
1996 1997
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
1997 // The copy that is used as the destination for multi-sample resolves. 2025 // The copy that is used as the destination for multi-sample resolves.
1998 std::unique_ptr<BackFramebuffer> offscreen_resolved_frame_buffer_; 2026 std::unique_ptr<BackFramebuffer> offscreen_resolved_frame_buffer_;
1999 std::unique_ptr<BackTexture> offscreen_resolved_color_texture_; 2027 std::unique_ptr<BackTexture> offscreen_resolved_color_texture_;
2000 GLenum offscreen_saved_color_format_; 2028 GLenum offscreen_saved_color_format_;
2001 2029
2002 std::unique_ptr<QueryManager> query_manager_; 2030 std::unique_ptr<QueryManager> query_manager_;
2003 2031
2004 std::unique_ptr<VertexArrayManager> vertex_array_manager_; 2032 std::unique_ptr<VertexArrayManager> vertex_array_manager_;
2005 2033
2006 std::unique_ptr<ImageManager> image_manager_; 2034 std::unique_ptr<ImageManager> image_manager_;
(...skipping 2053 matching lines...) Expand 10 before | Expand all | Expand 10 after
4060 framebuffer_state_.bound_draw_framebuffer = NULL; 4088 framebuffer_state_.bound_draw_framebuffer = NULL;
4061 state_.bound_renderbuffer = NULL; 4089 state_.bound_renderbuffer = NULL;
4062 4090
4063 if (offscreen_saved_color_texture_info_.get()) { 4091 if (offscreen_saved_color_texture_info_.get()) {
4064 DCHECK(offscreen_target_color_texture_); 4092 DCHECK(offscreen_target_color_texture_);
4065 DCHECK_EQ(offscreen_saved_color_texture_info_->service_id(), 4093 DCHECK_EQ(offscreen_saved_color_texture_info_->service_id(),
4066 offscreen_saved_color_texture_->id()); 4094 offscreen_saved_color_texture_->id());
4067 offscreen_saved_color_texture_->Invalidate(); 4095 offscreen_saved_color_texture_->Invalidate();
4068 offscreen_saved_color_texture_info_ = NULL; 4096 offscreen_saved_color_texture_info_ = NULL;
4069 } 4097 }
4098 ReleaseAllBackTextures();
4070 if (have_context) { 4099 if (have_context) {
4071 if (copy_texture_CHROMIUM_.get()) { 4100 if (copy_texture_CHROMIUM_.get()) {
4072 copy_texture_CHROMIUM_->Destroy(); 4101 copy_texture_CHROMIUM_->Destroy();
4073 copy_texture_CHROMIUM_.reset(); 4102 copy_texture_CHROMIUM_.reset();
4074 } 4103 }
4075 4104
4076 clear_framebuffer_blit_.reset(); 4105 clear_framebuffer_blit_.reset();
4077 4106
4078 if (state_.current_program.get()) { 4107 if (state_.current_program.get()) {
4079 program_manager()->UnuseProgram(shader_manager(), 4108 program_manager()->UnuseProgram(shader_manager(),
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
4198 } 4227 }
4199 4228
4200 void GLES2DecoderImpl::SetSurface( 4229 void GLES2DecoderImpl::SetSurface(
4201 const scoped_refptr<gfx::GLSurface>& surface) { 4230 const scoped_refptr<gfx::GLSurface>& surface) {
4202 DCHECK(context_->IsCurrent(NULL)); 4231 DCHECK(context_->IsCurrent(NULL));
4203 DCHECK(surface_.get()); 4232 DCHECK(surface_.get());
4204 surface_ = surface; 4233 surface_ = surface;
4205 RestoreCurrentFramebufferBindings(); 4234 RestoreCurrentFramebufferBindings();
4206 } 4235 }
4207 4236
4208 void GLES2DecoderImpl::ProduceFrontBuffer(const Mailbox& mailbox) { 4237 void GLES2DecoderImpl::TakeFrontBuffer(const Mailbox& mailbox) {
4209 if (!offscreen_saved_color_texture_.get()) { 4238 if (!offscreen_saved_color_texture_.get()) {
4210 LOG(ERROR) << "Called ProduceFrontBuffer on a non-offscreen context"; 4239 DLOG(ERROR) << "Called TakeFrontBuffer on a non-offscreen context";
4211 return; 4240 return;
4212 } 4241 }
4242
4213 if (!offscreen_saved_color_texture_info_.get()) { 4243 if (!offscreen_saved_color_texture_info_.get()) {
4214 GLuint service_id = offscreen_saved_color_texture_->id(); 4244 GLuint service_id = offscreen_saved_color_texture_->id();
4215 offscreen_saved_color_texture_info_ = TextureRef::Create( 4245 offscreen_saved_color_texture_info_ = TextureRef::Create(
4216 texture_manager(), 0, service_id); 4246 texture_manager(), 0, service_id);
4217 texture_manager()->SetTarget(offscreen_saved_color_texture_info_.get(), 4247 texture_manager()->SetTarget(offscreen_saved_color_texture_info_.get(),
4218 GL_TEXTURE_2D); 4248 GL_TEXTURE_2D);
4219 UpdateParentTextureInfo(); 4249 UpdateParentTextureInfo();
4220 } 4250 }
4251
4221 mailbox_manager()->ProduceTexture( 4252 mailbox_manager()->ProduceTexture(
4222 mailbox, offscreen_saved_color_texture_info_->texture()); 4253 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_;
4223 } 4337 }
4224 4338
4225 bool GLES2DecoderImpl::ResizeOffscreenFrameBuffer(const gfx::Size& size) { 4339 bool GLES2DecoderImpl::ResizeOffscreenFrameBuffer(const gfx::Size& size) {
4226 bool is_offscreen = !!offscreen_target_frame_buffer_.get(); 4340 bool is_offscreen = !!offscreen_target_frame_buffer_.get();
4227 if (!is_offscreen) { 4341 if (!is_offscreen) {
4228 LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer called " 4342 LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer called "
4229 << " with an onscreen framebuffer."; 4343 << " with an onscreen framebuffer.";
4230 return false; 4344 return false;
4231 } 4345 }
4232 4346
(...skipping 8475 matching lines...) Expand 10 before | Expand all | Expand 10 after
12708 "width", offscreen_size_.width(), "height", offscreen_size_.height()); 12822 "width", offscreen_size_.width(), "height", offscreen_size_.height());
12709 if (offscreen_size_ != offscreen_saved_color_texture_->size()) { 12823 if (offscreen_size_ != offscreen_saved_color_texture_->size()) {
12710 // Workaround for NVIDIA driver bug on OS X; crbug.com/89557, 12824 // Workaround for NVIDIA driver bug on OS X; crbug.com/89557,
12711 // crbug.com/94163. TODO(kbr): figure out reproduction so Apple will 12825 // crbug.com/94163. TODO(kbr): figure out reproduction so Apple will
12712 // fix this. 12826 // fix this.
12713 if (workarounds().needs_offscreen_buffer_workaround) { 12827 if (workarounds().needs_offscreen_buffer_workaround) {
12714 offscreen_saved_frame_buffer_->Create(); 12828 offscreen_saved_frame_buffer_->Create();
12715 glFinish(); 12829 glFinish();
12716 } 12830 }
12717 12831
12832 // The size has changed, so none of the cached BackTextures are useful
12833 // anymore.
12834 ReleaseNotInUseBackTextures();
12835
12718 // Allocate the offscreen saved color texture. 12836 // Allocate the offscreen saved color texture.
12719 DCHECK(offscreen_saved_color_format_); 12837 DCHECK(offscreen_saved_color_format_);
12720 offscreen_saved_color_texture_->AllocateStorage( 12838 offscreen_saved_color_texture_->AllocateStorage(
12721 offscreen_size_, offscreen_saved_color_format_, false); 12839 offscreen_size_, offscreen_saved_color_format_, false);
12722 12840
12723 offscreen_saved_frame_buffer_->AttachRenderTexture( 12841 offscreen_saved_frame_buffer_->AttachRenderTexture(
12724 offscreen_saved_color_texture_.get()); 12842 offscreen_saved_color_texture_.get());
12725 if (offscreen_size_.width() != 0 && offscreen_size_.height() != 0) { 12843 if (offscreen_size_.width() != 0 && offscreen_size_.height() != 0) {
12726 if (offscreen_saved_frame_buffer_->CheckStatus() != 12844 if (offscreen_saved_frame_buffer_->CheckStatus() !=
12727 GL_FRAMEBUFFER_COMPLETE) { 12845 GL_FRAMEBUFFER_COMPLETE) {
(...skipping 3629 matching lines...) Expand 10 before | Expand all | Expand 10 after
16357 } 16475 }
16358 16476
16359 // Include the auto-generated part of this file. We split this because it means 16477 // 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 16478 // 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. 16479 // instead of having to edit some template or the code generator.
16362 #include "base/macros.h" 16480 #include "base/macros.h"
16363 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 16481 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
16364 16482
16365 } // namespace gles2 16483 } // namespace gles2
16366 } // namespace gpu 16484 } // 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