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

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

Issue 2012303002: [Merge to 2743] Revert "[Reland 2] Pepper takes ownership of a mailbox before passing it to the tex… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2743
Patch Set: Created 4 years, 6 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 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 // Overridden from GLES2Decoder. 573 // Overridden from GLES2Decoder.
574 bool Initialize(const scoped_refptr<gfx::GLSurface>& surface, 574 bool Initialize(const scoped_refptr<gfx::GLSurface>& surface,
575 const scoped_refptr<gfx::GLContext>& context, 575 const scoped_refptr<gfx::GLContext>& context,
576 bool offscreen, 576 bool offscreen,
577 const gfx::Size& offscreen_size, 577 const gfx::Size& offscreen_size,
578 const DisallowedFeatures& disallowed_features, 578 const DisallowedFeatures& disallowed_features,
579 const ContextCreationAttribHelper& attrib_helper) override; 579 const ContextCreationAttribHelper& attrib_helper) override;
580 void Destroy(bool have_context) override; 580 void Destroy(bool have_context) override;
581 void SetSurface(const scoped_refptr<gfx::GLSurface>& surface) override; 581 void SetSurface(const scoped_refptr<gfx::GLSurface>& surface) override;
582 void ReleaseSurface() override; 582 void ReleaseSurface() override;
583 void TakeFrontBuffer(const Mailbox& mailbox) override; 583 void ProduceFrontBuffer(const Mailbox& mailbox) override;
584 void ReturnFrontBuffer(const Mailbox& mailbox, bool is_lost) override;
585 bool ResizeOffscreenFrameBuffer(const gfx::Size& size) override; 584 bool ResizeOffscreenFrameBuffer(const gfx::Size& size) override;
586 void UpdateParentTextureInfo(); 585 void UpdateParentTextureInfo();
587 bool MakeCurrent() override; 586 bool MakeCurrent() override;
588 GLES2Util* GetGLES2Util() override { return &util_; } 587 GLES2Util* GetGLES2Util() override { return &util_; }
589 gfx::GLContext* GetGLContext() override { return context_.get(); } 588 gfx::GLContext* GetGLContext() override { return context_.get(); }
590 ContextGroup* GetContextGroup() override { return group_.get(); } 589 ContextGroup* GetContextGroup() override { return group_.get(); }
591 Capabilities GetCapabilities() override; 590 Capabilities GetCapabilities() override;
592 void RestoreState(const ContextState* prev_state) override; 591 void RestoreState(const ContextState* prev_state) override;
593 592
594 void RestoreActiveTexture() const override { state_.RestoreActiveTexture(); } 593 void RestoreActiveTexture() const override { state_.RestoreActiveTexture(); }
(...skipping 1448 matching lines...) Expand 10 before | Expand all | Expand 10 after
2043 GLenum offscreen_target_stencil_format_; 2042 GLenum offscreen_target_stencil_format_;
2044 GLsizei offscreen_target_samples_; 2043 GLsizei offscreen_target_samples_;
2045 GLboolean offscreen_target_buffer_preserved_; 2044 GLboolean offscreen_target_buffer_preserved_;
2046 2045
2047 // The copy that is saved when SwapBuffers is called. 2046 // The copy that is saved when SwapBuffers is called.
2048 std::unique_ptr<BackFramebuffer> offscreen_saved_frame_buffer_; 2047 std::unique_ptr<BackFramebuffer> offscreen_saved_frame_buffer_;
2049 std::unique_ptr<BackTexture> offscreen_saved_color_texture_; 2048 std::unique_ptr<BackTexture> offscreen_saved_color_texture_;
2050 scoped_refptr<TextureRef> 2049 scoped_refptr<TextureRef>
2051 offscreen_saved_color_texture_info_; 2050 offscreen_saved_color_texture_info_;
2052 2051
2053 // When a client requests ownership of the swapped front buffer, all
2054 // information is saved in this structure, and |in_use| is set to true. When a
2055 // client releases ownership, |in_use| is set to false.
2056 //
2057 // An instance of this struct, with |in_use| = false may be reused instead of
2058 // making a new BackTexture.
2059 struct SavedBackTexture {
2060 std::unique_ptr<BackTexture> back_texture;
2061 scoped_refptr<TextureRef> texture_ref;
2062 bool in_use;
2063 };
2064 std::vector<SavedBackTexture> saved_back_textures_;
2065
2066 // If there's a SavedBackTexture that's not in use, takes that. Otherwise,
2067 // generates a new back texture.
2068 void CreateBackTexture();
2069 size_t create_back_texture_count_for_test_ = 0;
2070
2071 // Releases all saved BackTextures that are not in use by a client.
2072 void ReleaseNotInUseBackTextures();
2073
2074 // Releases all saved BackTextures.
2075 void ReleaseAllBackTextures();
2076
2077 size_t GetSavedBackTextureCountForTest() override;
2078 size_t GetCreatedBackTextureCountForTest() override;
2079
2080 // The copy that is used as the destination for multi-sample resolves. 2052 // The copy that is used as the destination for multi-sample resolves.
2081 std::unique_ptr<BackFramebuffer> offscreen_resolved_frame_buffer_; 2053 std::unique_ptr<BackFramebuffer> offscreen_resolved_frame_buffer_;
2082 std::unique_ptr<BackTexture> offscreen_resolved_color_texture_; 2054 std::unique_ptr<BackTexture> offscreen_resolved_color_texture_;
2083 GLenum offscreen_saved_color_format_; 2055 GLenum offscreen_saved_color_format_;
2084 2056
2085 std::unique_ptr<QueryManager> query_manager_; 2057 std::unique_ptr<QueryManager> query_manager_;
2086 2058
2087 std::unique_ptr<VertexArrayManager> vertex_array_manager_; 2059 std::unique_ptr<VertexArrayManager> vertex_array_manager_;
2088 2060
2089 std::unique_ptr<ImageManager> image_manager_; 2061 std::unique_ptr<ImageManager> image_manager_;
(...skipping 2114 matching lines...) Expand 10 before | Expand all | Expand 10 after
4204 state_.default_transform_feedback = nullptr; 4176 state_.default_transform_feedback = nullptr;
4205 state_.indexed_uniform_buffer_bindings = nullptr; 4177 state_.indexed_uniform_buffer_bindings = nullptr;
4206 4178
4207 if (offscreen_saved_color_texture_info_.get()) { 4179 if (offscreen_saved_color_texture_info_.get()) {
4208 DCHECK(offscreen_target_color_texture_); 4180 DCHECK(offscreen_target_color_texture_);
4209 DCHECK_EQ(offscreen_saved_color_texture_info_->service_id(), 4181 DCHECK_EQ(offscreen_saved_color_texture_info_->service_id(),
4210 offscreen_saved_color_texture_->id()); 4182 offscreen_saved_color_texture_->id());
4211 offscreen_saved_color_texture_->Invalidate(); 4183 offscreen_saved_color_texture_->Invalidate();
4212 offscreen_saved_color_texture_info_ = NULL; 4184 offscreen_saved_color_texture_info_ = NULL;
4213 } 4185 }
4214 ReleaseAllBackTextures();
4215 if (have_context) { 4186 if (have_context) {
4216 if (copy_texture_CHROMIUM_.get()) { 4187 if (copy_texture_CHROMIUM_.get()) {
4217 copy_texture_CHROMIUM_->Destroy(); 4188 copy_texture_CHROMIUM_->Destroy();
4218 copy_texture_CHROMIUM_.reset(); 4189 copy_texture_CHROMIUM_.reset();
4219 } 4190 }
4220 4191
4221 clear_framebuffer_blit_.reset(); 4192 clear_framebuffer_blit_.reset();
4222 4193
4223 if (state_.current_program.get()) { 4194 if (state_.current_program.get()) {
4224 program_manager()->UnuseProgram(shader_manager(), 4195 program_manager()->UnuseProgram(shader_manager(),
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
4362 if (!context_.get()) 4333 if (!context_.get())
4363 return; 4334 return;
4364 if (WasContextLost()) { 4335 if (WasContextLost()) {
4365 DLOG(ERROR) << " GLES2DecoderImpl: Trying to release lost context."; 4336 DLOG(ERROR) << " GLES2DecoderImpl: Trying to release lost context.";
4366 return; 4337 return;
4367 } 4338 }
4368 context_->ReleaseCurrent(surface_.get()); 4339 context_->ReleaseCurrent(surface_.get());
4369 surface_ = nullptr; 4340 surface_ = nullptr;
4370 } 4341 }
4371 4342
4372 void GLES2DecoderImpl::TakeFrontBuffer(const Mailbox& mailbox) { 4343 void GLES2DecoderImpl::ProduceFrontBuffer(const Mailbox& mailbox) {
4373 if (!offscreen_saved_color_texture_.get()) { 4344 if (!offscreen_saved_color_texture_.get()) {
4374 DLOG(ERROR) << "Called TakeFrontBuffer on a non-offscreen context"; 4345 LOG(ERROR) << "Called ProduceFrontBuffer on a non-offscreen context";
4375 return; 4346 return;
4376 } 4347 }
4377
4378 if (!offscreen_saved_color_texture_info_.get()) { 4348 if (!offscreen_saved_color_texture_info_.get()) {
4379 GLuint service_id = offscreen_saved_color_texture_->id(); 4349 GLuint service_id = offscreen_saved_color_texture_->id();
4380 offscreen_saved_color_texture_info_ = TextureRef::Create( 4350 offscreen_saved_color_texture_info_ = TextureRef::Create(
4381 texture_manager(), 0, service_id); 4351 texture_manager(), 0, service_id);
4382 texture_manager()->SetTarget(offscreen_saved_color_texture_info_.get(), 4352 texture_manager()->SetTarget(offscreen_saved_color_texture_info_.get(),
4383 GL_TEXTURE_2D); 4353 GL_TEXTURE_2D);
4384 UpdateParentTextureInfo(); 4354 UpdateParentTextureInfo();
4385 } 4355 }
4386
4387 mailbox_manager()->ProduceTexture( 4356 mailbox_manager()->ProduceTexture(
4388 mailbox, offscreen_saved_color_texture_info_->texture()); 4357 mailbox, offscreen_saved_color_texture_info_->texture());
4389
4390 // Save the BackTexture and TextureRef.
4391 SavedBackTexture save;
4392 save.back_texture.swap(offscreen_saved_color_texture_);
4393 save.texture_ref = offscreen_saved_color_texture_info_;
4394 offscreen_saved_color_texture_info_ = nullptr;
4395 save.in_use = true;
4396 saved_back_textures_.push_back(std::move(save));
4397
4398 CreateBackTexture();
4399 }
4400
4401 void GLES2DecoderImpl::ReturnFrontBuffer(const Mailbox& mailbox, bool is_lost) {
4402 Texture* texture = mailbox_manager()->ConsumeTexture(mailbox);
4403 for (auto it = saved_back_textures_.begin(); it != saved_back_textures_.end();
4404 ++it) {
4405 if (texture != it->texture_ref->texture())
4406 continue;
4407
4408 if (is_lost || it->back_texture->size() != offscreen_size_) {
4409 it->back_texture->Invalidate();
4410 saved_back_textures_.erase(it);
4411 return;
4412 }
4413
4414 it->in_use = false;
4415 return;
4416 }
4417
4418 DLOG(ERROR) << "Attempting to return a frontbuffer that was not saved.";
4419 }
4420
4421 void GLES2DecoderImpl::CreateBackTexture() {
4422 for (auto it = saved_back_textures_.begin(); it != saved_back_textures_.end();
4423 ++it) {
4424 if (it->in_use)
4425 continue;
4426
4427 if (it->back_texture->size() != offscreen_size_)
4428 continue;
4429 offscreen_saved_color_texture_ = std::move(it->back_texture);
4430 offscreen_saved_color_texture_info_ = it->texture_ref;
4431 saved_back_textures_.erase(it);
4432 return;
4433 }
4434
4435 ++create_back_texture_count_for_test_;
4436 offscreen_saved_color_texture_.reset(
4437 new BackTexture(memory_tracker(), &state_));
4438 offscreen_saved_color_texture_->Create();
4439 offscreen_saved_color_texture_->AllocateStorage(
4440 offscreen_size_, offscreen_saved_color_format_, false);
4441 offscreen_saved_frame_buffer_->AttachRenderTexture(
4442 offscreen_saved_color_texture_.get());
4443 }
4444
4445 void GLES2DecoderImpl::ReleaseNotInUseBackTextures() {
4446 for (auto& saved_back_texture : saved_back_textures_) {
4447 if (!saved_back_texture.in_use)
4448 saved_back_texture.back_texture->Invalidate();
4449 }
4450
4451 auto to_remove =
4452 std::remove_if(saved_back_textures_.begin(), saved_back_textures_.end(),
4453 [](const SavedBackTexture& saved_back_texture) {
4454 return !saved_back_texture.in_use;
4455 });
4456 saved_back_textures_.erase(to_remove, saved_back_textures_.end());
4457 }
4458
4459 void GLES2DecoderImpl::ReleaseAllBackTextures() {
4460 for (auto& saved_back_texture : saved_back_textures_) {
4461 // The texture will be destroyed by texture_ref's destructor.
4462 DCHECK(saved_back_texture.texture_ref);
4463 saved_back_texture.back_texture->Invalidate();
4464 }
4465 saved_back_textures_.clear();
4466 }
4467
4468 size_t GLES2DecoderImpl::GetSavedBackTextureCountForTest() {
4469 return saved_back_textures_.size();
4470 }
4471
4472 size_t GLES2DecoderImpl::GetCreatedBackTextureCountForTest() {
4473 return create_back_texture_count_for_test_;
4474 } 4358 }
4475 4359
4476 bool GLES2DecoderImpl::ResizeOffscreenFrameBuffer(const gfx::Size& size) { 4360 bool GLES2DecoderImpl::ResizeOffscreenFrameBuffer(const gfx::Size& size) {
4477 bool is_offscreen = !!offscreen_target_frame_buffer_.get(); 4361 bool is_offscreen = !!offscreen_target_frame_buffer_.get();
4478 if (!is_offscreen) { 4362 if (!is_offscreen) {
4479 LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer called " 4363 LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer called "
4480 << " with an onscreen framebuffer."; 4364 << " with an onscreen framebuffer.";
4481 return false; 4365 return false;
4482 } 4366 }
4483 4367
(...skipping 8666 matching lines...) Expand 10 before | Expand all | Expand 10 after
13150 "width", offscreen_size_.width(), "height", offscreen_size_.height()); 13034 "width", offscreen_size_.width(), "height", offscreen_size_.height());
13151 if (offscreen_size_ != offscreen_saved_color_texture_->size()) { 13035 if (offscreen_size_ != offscreen_saved_color_texture_->size()) {
13152 // Workaround for NVIDIA driver bug on OS X; crbug.com/89557, 13036 // Workaround for NVIDIA driver bug on OS X; crbug.com/89557,
13153 // crbug.com/94163. TODO(kbr): figure out reproduction so Apple will 13037 // crbug.com/94163. TODO(kbr): figure out reproduction so Apple will
13154 // fix this. 13038 // fix this.
13155 if (workarounds().needs_offscreen_buffer_workaround) { 13039 if (workarounds().needs_offscreen_buffer_workaround) {
13156 offscreen_saved_frame_buffer_->Create(); 13040 offscreen_saved_frame_buffer_->Create();
13157 glFinish(); 13041 glFinish();
13158 } 13042 }
13159 13043
13160 // The size has changed, so none of the cached BackTextures are useful
13161 // anymore.
13162 ReleaseNotInUseBackTextures();
13163
13164 // Allocate the offscreen saved color texture. 13044 // Allocate the offscreen saved color texture.
13165 DCHECK(offscreen_saved_color_format_); 13045 DCHECK(offscreen_saved_color_format_);
13166 offscreen_saved_color_texture_->AllocateStorage( 13046 offscreen_saved_color_texture_->AllocateStorage(
13167 offscreen_size_, offscreen_saved_color_format_, false); 13047 offscreen_size_, offscreen_saved_color_format_, false);
13168 13048
13169 offscreen_saved_frame_buffer_->AttachRenderTexture( 13049 offscreen_saved_frame_buffer_->AttachRenderTexture(
13170 offscreen_saved_color_texture_.get()); 13050 offscreen_saved_color_texture_.get());
13171 if (offscreen_size_.width() != 0 && offscreen_size_.height() != 0) { 13051 if (offscreen_size_.width() != 0 && offscreen_size_.height() != 0) {
13172 if (offscreen_saved_frame_buffer_->CheckStatus() != 13052 if (offscreen_saved_frame_buffer_->CheckStatus() !=
13173 GL_FRAMEBUFFER_COMPLETE) { 13053 GL_FRAMEBUFFER_COMPLETE) {
(...skipping 3618 matching lines...) Expand 10 before | Expand all | Expand 10 after
16792 } 16672 }
16793 16673
16794 // Include the auto-generated part of this file. We split this because it means 16674 // Include the auto-generated part of this file. We split this because it means
16795 // we can easily edit the non-auto generated parts right here in this file 16675 // we can easily edit the non-auto generated parts right here in this file
16796 // instead of having to edit some template or the code generator. 16676 // instead of having to edit some template or the code generator.
16797 #include "base/macros.h" 16677 #include "base/macros.h"
16798 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 16678 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
16799 16679
16800 } // namespace gles2 16680 } // namespace gles2
16801 } // namespace gpu 16681 } // 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