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

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

Powered by Google App Engine
This is Rietveld 408576698