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

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

Issue 1965253002: [Reland 2] 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: Fix preemption bug. 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 577 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 588
589 // Overridden from GLES2Decoder. 589 // Overridden from GLES2Decoder.
590 bool Initialize(const scoped_refptr<gfx::GLSurface>& surface, 590 bool Initialize(const scoped_refptr<gfx::GLSurface>& surface,
591 const scoped_refptr<gfx::GLContext>& context, 591 const scoped_refptr<gfx::GLContext>& context,
592 bool offscreen, 592 bool offscreen,
593 const gfx::Size& offscreen_size, 593 const gfx::Size& offscreen_size,
594 const DisallowedFeatures& disallowed_features, 594 const DisallowedFeatures& disallowed_features,
595 const std::vector<int32_t>& attribs) override; 595 const std::vector<int32_t>& attribs) override;
596 void Destroy(bool have_context) override; 596 void Destroy(bool have_context) override;
597 void SetSurface(const scoped_refptr<gfx::GLSurface>& surface) override; 597 void SetSurface(const scoped_refptr<gfx::GLSurface>& surface) override;
598 void ProduceFrontBuffer(const Mailbox& mailbox) override; 598 void TakeFrontBuffer(const Mailbox& mailbox) override;
599 void ReturnFrontBuffer(const Mailbox& mailbox, bool is_lost) override;
599 bool ResizeOffscreenFrameBuffer(const gfx::Size& size) override; 600 bool ResizeOffscreenFrameBuffer(const gfx::Size& size) override;
600 void UpdateParentTextureInfo(); 601 void UpdateParentTextureInfo();
601 bool MakeCurrent() override; 602 bool MakeCurrent() override;
602 GLES2Util* GetGLES2Util() override { return &util_; } 603 GLES2Util* GetGLES2Util() override { return &util_; }
603 gfx::GLContext* GetGLContext() override { return context_.get(); } 604 gfx::GLContext* GetGLContext() override { return context_.get(); }
604 ContextGroup* GetContextGroup() override { return group_.get(); } 605 ContextGroup* GetContextGroup() override { return group_.get(); }
605 Capabilities GetCapabilities() override; 606 Capabilities GetCapabilities() override;
606 void RestoreState(const ContextState* prev_state) override; 607 void RestoreState(const ContextState* prev_state) override;
607 608
608 void RestoreActiveTexture() const override { state_.RestoreActiveTexture(); } 609 void RestoreActiveTexture() const override { state_.RestoreActiveTexture(); }
(...skipping 1446 matching lines...) Expand 10 before | Expand all | Expand 10 after
2055 GLenum offscreen_target_stencil_format_; 2056 GLenum offscreen_target_stencil_format_;
2056 GLsizei offscreen_target_samples_; 2057 GLsizei offscreen_target_samples_;
2057 GLboolean offscreen_target_buffer_preserved_; 2058 GLboolean offscreen_target_buffer_preserved_;
2058 2059
2059 // The copy that is saved when SwapBuffers is called. 2060 // The copy that is saved when SwapBuffers is called.
2060 std::unique_ptr<BackFramebuffer> offscreen_saved_frame_buffer_; 2061 std::unique_ptr<BackFramebuffer> offscreen_saved_frame_buffer_;
2061 std::unique_ptr<BackTexture> offscreen_saved_color_texture_; 2062 std::unique_ptr<BackTexture> offscreen_saved_color_texture_;
2062 scoped_refptr<TextureRef> 2063 scoped_refptr<TextureRef>
2063 offscreen_saved_color_texture_info_; 2064 offscreen_saved_color_texture_info_;
2064 2065
2066 // When a client requests ownership of the swapped front buffer, all
2067 // information is saved in this structure, and |in_use| is set to true. When a
2068 // client releases ownership, |in_use| is set to false.
2069 //
2070 // An instance of this struct, with |in_use| = false may be reused instead of
2071 // making a new BackTexture.
2072 struct SavedBackTexture {
2073 std::unique_ptr<BackTexture> back_texture;
2074 scoped_refptr<TextureRef> texture_ref;
2075 bool in_use;
2076 };
2077 std::vector<SavedBackTexture> saved_back_textures_;
2078
2079 // If there's a SavedBackTexture that's not in use, takes that. Otherwise,
2080 // generates a new back texture.
2081 void CreateBackTexture();
2082 size_t create_back_texture_count_for_test_ = 0;
2083
2084 // Releases all saved BackTextures that are not in use by a client.
2085 void ReleaseNotInUseBackTextures();
2086
2087 // Releases all saved BackTextures.
2088 void ReleaseAllBackTextures();
2089
2090 size_t GetSavedBackTextureCountForTest() override;
2091 size_t GetCreatedBackTextureCountForTest() override;
2092
2065 // The copy that is used as the destination for multi-sample resolves. 2093 // The copy that is used as the destination for multi-sample resolves.
2066 std::unique_ptr<BackFramebuffer> offscreen_resolved_frame_buffer_; 2094 std::unique_ptr<BackFramebuffer> offscreen_resolved_frame_buffer_;
2067 std::unique_ptr<BackTexture> offscreen_resolved_color_texture_; 2095 std::unique_ptr<BackTexture> offscreen_resolved_color_texture_;
2068 GLenum offscreen_saved_color_format_; 2096 GLenum offscreen_saved_color_format_;
2069 2097
2070 std::unique_ptr<QueryManager> query_manager_; 2098 std::unique_ptr<QueryManager> query_manager_;
2071 2099
2072 std::unique_ptr<VertexArrayManager> vertex_array_manager_; 2100 std::unique_ptr<VertexArrayManager> vertex_array_manager_;
2073 2101
2074 std::unique_ptr<ImageManager> image_manager_; 2102 std::unique_ptr<ImageManager> image_manager_;
(...skipping 2116 matching lines...) Expand 10 before | Expand all | Expand 10 after
4191 state_.default_transform_feedback = nullptr; 4219 state_.default_transform_feedback = nullptr;
4192 state_.indexed_uniform_buffer_bindings = nullptr; 4220 state_.indexed_uniform_buffer_bindings = nullptr;
4193 4221
4194 if (offscreen_saved_color_texture_info_.get()) { 4222 if (offscreen_saved_color_texture_info_.get()) {
4195 DCHECK(offscreen_target_color_texture_); 4223 DCHECK(offscreen_target_color_texture_);
4196 DCHECK_EQ(offscreen_saved_color_texture_info_->service_id(), 4224 DCHECK_EQ(offscreen_saved_color_texture_info_->service_id(),
4197 offscreen_saved_color_texture_->id()); 4225 offscreen_saved_color_texture_->id());
4198 offscreen_saved_color_texture_->Invalidate(); 4226 offscreen_saved_color_texture_->Invalidate();
4199 offscreen_saved_color_texture_info_ = NULL; 4227 offscreen_saved_color_texture_info_ = NULL;
4200 } 4228 }
4229 ReleaseAllBackTextures();
4201 if (have_context) { 4230 if (have_context) {
4202 if (copy_texture_CHROMIUM_.get()) { 4231 if (copy_texture_CHROMIUM_.get()) {
4203 copy_texture_CHROMIUM_->Destroy(); 4232 copy_texture_CHROMIUM_->Destroy();
4204 copy_texture_CHROMIUM_.reset(); 4233 copy_texture_CHROMIUM_.reset();
4205 } 4234 }
4206 4235
4207 clear_framebuffer_blit_.reset(); 4236 clear_framebuffer_blit_.reset();
4208 4237
4209 if (state_.current_program.get()) { 4238 if (state_.current_program.get()) {
4210 program_manager()->UnuseProgram(shader_manager(), 4239 program_manager()->UnuseProgram(shader_manager(),
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
4337 } 4366 }
4338 4367
4339 void GLES2DecoderImpl::SetSurface( 4368 void GLES2DecoderImpl::SetSurface(
4340 const scoped_refptr<gfx::GLSurface>& surface) { 4369 const scoped_refptr<gfx::GLSurface>& surface) {
4341 DCHECK(context_->IsCurrent(NULL)); 4370 DCHECK(context_->IsCurrent(NULL));
4342 DCHECK(surface_.get()); 4371 DCHECK(surface_.get());
4343 surface_ = surface; 4372 surface_ = surface;
4344 RestoreCurrentFramebufferBindings(); 4373 RestoreCurrentFramebufferBindings();
4345 } 4374 }
4346 4375
4347 void GLES2DecoderImpl::ProduceFrontBuffer(const Mailbox& mailbox) { 4376 void GLES2DecoderImpl::TakeFrontBuffer(const Mailbox& mailbox) {
4348 if (!offscreen_saved_color_texture_.get()) { 4377 if (!offscreen_saved_color_texture_.get()) {
4349 LOG(ERROR) << "Called ProduceFrontBuffer on a non-offscreen context"; 4378 DLOG(ERROR) << "Called TakeFrontBuffer on a non-offscreen context";
4350 return; 4379 return;
4351 } 4380 }
4381
4352 if (!offscreen_saved_color_texture_info_.get()) { 4382 if (!offscreen_saved_color_texture_info_.get()) {
4353 GLuint service_id = offscreen_saved_color_texture_->id(); 4383 GLuint service_id = offscreen_saved_color_texture_->id();
4354 offscreen_saved_color_texture_info_ = TextureRef::Create( 4384 offscreen_saved_color_texture_info_ = TextureRef::Create(
4355 texture_manager(), 0, service_id); 4385 texture_manager(), 0, service_id);
4356 texture_manager()->SetTarget(offscreen_saved_color_texture_info_.get(), 4386 texture_manager()->SetTarget(offscreen_saved_color_texture_info_.get(),
4357 GL_TEXTURE_2D); 4387 GL_TEXTURE_2D);
4358 UpdateParentTextureInfo(); 4388 UpdateParentTextureInfo();
4359 } 4389 }
4390
4360 mailbox_manager()->ProduceTexture( 4391 mailbox_manager()->ProduceTexture(
4361 mailbox, offscreen_saved_color_texture_info_->texture()); 4392 mailbox, offscreen_saved_color_texture_info_->texture());
4393
4394 // Save the BackTexture and TextureRef.
4395 SavedBackTexture save;
4396 save.back_texture.swap(offscreen_saved_color_texture_);
4397 save.texture_ref = offscreen_saved_color_texture_info_;
4398 offscreen_saved_color_texture_info_ = nullptr;
4399 save.in_use = true;
4400 saved_back_textures_.push_back(std::move(save));
4401
4402 CreateBackTexture();
4403 }
4404
4405 void GLES2DecoderImpl::ReturnFrontBuffer(const Mailbox& mailbox, bool is_lost) {
4406 Texture* texture = mailbox_manager()->ConsumeTexture(mailbox);
4407 for (auto it = saved_back_textures_.begin(); it != saved_back_textures_.end();
4408 ++it) {
4409 if (texture != it->texture_ref->texture())
4410 continue;
4411
4412 if (is_lost || it->back_texture->size() != offscreen_size_) {
4413 it->back_texture->Invalidate();
4414 saved_back_textures_.erase(it);
4415 return;
4416 }
4417
4418 it->in_use = false;
4419 return;
4420 }
4421
4422 DLOG(ERROR) << "Attempting to return a frontbuffer that was not saved.";
4423 }
4424
4425 void GLES2DecoderImpl::CreateBackTexture() {
4426 for (auto it = saved_back_textures_.begin(); it != saved_back_textures_.end();
4427 ++it) {
4428 if (it->in_use)
4429 continue;
4430
4431 if (it->back_texture->size() != offscreen_size_)
4432 continue;
4433 offscreen_saved_color_texture_ = std::move(it->back_texture);
4434 offscreen_saved_color_texture_info_ = it->texture_ref;
4435 saved_back_textures_.erase(it);
4436 return;
4437 }
4438
4439 ++create_back_texture_count_for_test_;
4440 offscreen_saved_color_texture_.reset(
4441 new BackTexture(memory_tracker(), &state_));
4442 offscreen_saved_color_texture_->Create();
4443 offscreen_saved_color_texture_->AllocateStorage(
4444 offscreen_size_, offscreen_saved_color_format_, false);
4445 offscreen_saved_frame_buffer_->AttachRenderTexture(
4446 offscreen_saved_color_texture_.get());
4447 }
4448
4449 void GLES2DecoderImpl::ReleaseNotInUseBackTextures() {
4450 for (auto& saved_back_texture : saved_back_textures_) {
4451 if (!saved_back_texture.in_use)
4452 saved_back_texture.back_texture->Invalidate();
4453 }
4454
4455 auto to_remove =
4456 std::remove_if(saved_back_textures_.begin(), saved_back_textures_.end(),
4457 [](const SavedBackTexture& saved_back_texture) {
4458 return !saved_back_texture.in_use;
4459 });
4460 saved_back_textures_.erase(to_remove, saved_back_textures_.end());
4461 }
4462
4463 void GLES2DecoderImpl::ReleaseAllBackTextures() {
4464 for (auto& saved_back_texture : saved_back_textures_) {
4465 // The texture will be destroyed by texture_ref's destructor.
4466 DCHECK(saved_back_texture.texture_ref);
4467 saved_back_texture.back_texture->Invalidate();
4468 }
4469 saved_back_textures_.clear();
4470 }
4471
4472 size_t GLES2DecoderImpl::GetSavedBackTextureCountForTest() {
4473 return saved_back_textures_.size();
4474 }
4475
4476 size_t GLES2DecoderImpl::GetCreatedBackTextureCountForTest() {
4477 return create_back_texture_count_for_test_;
4362 } 4478 }
4363 4479
4364 bool GLES2DecoderImpl::ResizeOffscreenFrameBuffer(const gfx::Size& size) { 4480 bool GLES2DecoderImpl::ResizeOffscreenFrameBuffer(const gfx::Size& size) {
4365 bool is_offscreen = !!offscreen_target_frame_buffer_.get(); 4481 bool is_offscreen = !!offscreen_target_frame_buffer_.get();
4366 if (!is_offscreen) { 4482 if (!is_offscreen) {
4367 LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer called " 4483 LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer called "
4368 << " with an onscreen framebuffer."; 4484 << " with an onscreen framebuffer.";
4369 return false; 4485 return false;
4370 } 4486 }
4371 4487
(...skipping 8666 matching lines...) Expand 10 before | Expand all | Expand 10 after
13038 "width", offscreen_size_.width(), "height", offscreen_size_.height()); 13154 "width", offscreen_size_.width(), "height", offscreen_size_.height());
13039 if (offscreen_size_ != offscreen_saved_color_texture_->size()) { 13155 if (offscreen_size_ != offscreen_saved_color_texture_->size()) {
13040 // Workaround for NVIDIA driver bug on OS X; crbug.com/89557, 13156 // Workaround for NVIDIA driver bug on OS X; crbug.com/89557,
13041 // crbug.com/94163. TODO(kbr): figure out reproduction so Apple will 13157 // crbug.com/94163. TODO(kbr): figure out reproduction so Apple will
13042 // fix this. 13158 // fix this.
13043 if (workarounds().needs_offscreen_buffer_workaround) { 13159 if (workarounds().needs_offscreen_buffer_workaround) {
13044 offscreen_saved_frame_buffer_->Create(); 13160 offscreen_saved_frame_buffer_->Create();
13045 glFinish(); 13161 glFinish();
13046 } 13162 }
13047 13163
13164 // The size has changed, so none of the cached BackTextures are useful
13165 // anymore.
13166 ReleaseNotInUseBackTextures();
13167
13048 // Allocate the offscreen saved color texture. 13168 // Allocate the offscreen saved color texture.
13049 DCHECK(offscreen_saved_color_format_); 13169 DCHECK(offscreen_saved_color_format_);
13050 offscreen_saved_color_texture_->AllocateStorage( 13170 offscreen_saved_color_texture_->AllocateStorage(
13051 offscreen_size_, offscreen_saved_color_format_, false); 13171 offscreen_size_, offscreen_saved_color_format_, false);
13052 13172
13053 offscreen_saved_frame_buffer_->AttachRenderTexture( 13173 offscreen_saved_frame_buffer_->AttachRenderTexture(
13054 offscreen_saved_color_texture_.get()); 13174 offscreen_saved_color_texture_.get());
13055 if (offscreen_size_.width() != 0 && offscreen_size_.height() != 0) { 13175 if (offscreen_size_.width() != 0 && offscreen_size_.height() != 0) {
13056 if (offscreen_saved_frame_buffer_->CheckStatus() != 13176 if (offscreen_saved_frame_buffer_->CheckStatus() !=
13057 GL_FRAMEBUFFER_COMPLETE) { 13177 GL_FRAMEBUFFER_COMPLETE) {
(...skipping 3616 matching lines...) Expand 10 before | Expand all | Expand 10 after
16674 } 16794 }
16675 16795
16676 // Include the auto-generated part of this file. We split this because it means 16796 // Include the auto-generated part of this file. We split this because it means
16677 // we can easily edit the non-auto generated parts right here in this file 16797 // we can easily edit the non-auto generated parts right here in this file
16678 // instead of having to edit some template or the code generator. 16798 // instead of having to edit some template or the code generator.
16679 #include "base/macros.h" 16799 #include "base/macros.h"
16680 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 16800 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
16681 16801
16682 } // namespace gles2 16802 } // namespace gles2
16683 } // namespace gpu 16803 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698