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

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: Created 4 years, 8 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 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 587
588 // Overridden from GLES2Decoder. 588 // Overridden from GLES2Decoder.
589 bool Initialize(const scoped_refptr<gfx::GLSurface>& surface, 589 bool Initialize(const scoped_refptr<gfx::GLSurface>& surface,
590 const scoped_refptr<gfx::GLContext>& context, 590 const scoped_refptr<gfx::GLContext>& context,
591 bool offscreen, 591 bool offscreen,
592 const gfx::Size& offscreen_size, 592 const gfx::Size& offscreen_size,
593 const DisallowedFeatures& disallowed_features, 593 const DisallowedFeatures& disallowed_features,
594 const std::vector<int32_t>& attribs) override; 594 const std::vector<int32_t>& attribs) override;
595 void Destroy(bool have_context) override; 595 void Destroy(bool have_context) override;
596 void SetSurface(const scoped_refptr<gfx::GLSurface>& surface) override; 596 void SetSurface(const scoped_refptr<gfx::GLSurface>& surface) override;
597 void ReleaseSurface() override;
597 void ProduceFrontBuffer(const Mailbox& mailbox) override; 598 void ProduceFrontBuffer(const Mailbox& mailbox) override;
599 void TakeFrontBuffer(const Mailbox& mailbox) override;
600 void ReturnFrontBuffer(const Mailbox& mailbox,
601 bool is_lost) override;
598 bool ResizeOffscreenFrameBuffer(const gfx::Size& size) override; 602 bool ResizeOffscreenFrameBuffer(const gfx::Size& size) override;
599 void UpdateParentTextureInfo(); 603 void UpdateParentTextureInfo();
600 bool MakeCurrent() override; 604 bool MakeCurrent() override;
601 GLES2Util* GetGLES2Util() override { return &util_; } 605 GLES2Util* GetGLES2Util() override { return &util_; }
602 gfx::GLContext* GetGLContext() override { return context_.get(); } 606 gfx::GLContext* GetGLContext() override { return context_.get(); }
603 ContextGroup* GetContextGroup() override { return group_.get(); } 607 ContextGroup* GetContextGroup() override { return group_.get(); }
604 Capabilities GetCapabilities() override; 608 Capabilities GetCapabilities() override;
605 void RestoreState(const ContextState* prev_state) override; 609 void RestoreState(const ContextState* prev_state) override;
606 610
607 void RestoreActiveTexture() const override { state_.RestoreActiveTexture(); } 611 void RestoreActiveTexture() const override { state_.RestoreActiveTexture(); }
(...skipping 1411 matching lines...) Expand 10 before | Expand all | Expand 10 after
2019 2023
2020 // The buffer used to simulate GL_FIXED attribs. 2024 // The buffer used to simulate GL_FIXED attribs.
2021 GLuint fixed_attrib_buffer_id_; 2025 GLuint fixed_attrib_buffer_id_;
2022 2026
2023 // The size of fiixed attrib buffer. 2027 // The size of fiixed attrib buffer.
2024 GLsizei fixed_attrib_buffer_size_; 2028 GLsizei fixed_attrib_buffer_size_;
2025 2029
2026 // The offscreen frame buffer that the client renders to. With EGL, the 2030 // The offscreen frame buffer that the client renders to. With EGL, the
2027 // depth and stencil buffers are separate. With regular GL there is a single 2031 // depth and stencil buffers are separate. With regular GL there is a single
2028 // packed depth stencil buffer in offscreen_target_depth_render_buffer_. 2032 // packed depth stencil buffer in offscreen_target_depth_render_buffer_.
2029 // offscreen_target_stencil_render_buffer_ is unused. 2033 // offscreen_target_stencil_render_buffer_ is unused.
ccameron 2016/04/22 18:25:55 <idle complaining> GLES2CmdDecoder is far too larg
2030 std::unique_ptr<BackFramebuffer> offscreen_target_frame_buffer_; 2034 std::unique_ptr<BackFramebuffer> offscreen_target_frame_buffer_;
2031 std::unique_ptr<BackTexture> offscreen_target_color_texture_; 2035 std::unique_ptr<BackTexture> offscreen_target_color_texture_;
2032 std::unique_ptr<BackRenderbuffer> offscreen_target_color_render_buffer_; 2036 std::unique_ptr<BackRenderbuffer> offscreen_target_color_render_buffer_;
2033 std::unique_ptr<BackRenderbuffer> offscreen_target_depth_render_buffer_; 2037 std::unique_ptr<BackRenderbuffer> offscreen_target_depth_render_buffer_;
2034 std::unique_ptr<BackRenderbuffer> offscreen_target_stencil_render_buffer_; 2038 std::unique_ptr<BackRenderbuffer> offscreen_target_stencil_render_buffer_;
2035 GLenum offscreen_target_color_format_; 2039 GLenum offscreen_target_color_format_;
2036 GLenum offscreen_target_depth_format_; 2040 GLenum offscreen_target_depth_format_;
2037 GLenum offscreen_target_stencil_format_; 2041 GLenum offscreen_target_stencil_format_;
2038 GLsizei offscreen_target_samples_; 2042 GLsizei offscreen_target_samples_;
2039 GLboolean offscreen_target_buffer_preserved_; 2043 GLboolean offscreen_target_buffer_preserved_;
2040 2044
2041 // The copy that is saved when SwapBuffers is called. 2045 // The copy that is saved when SwapBuffers is called.
2042 std::unique_ptr<BackFramebuffer> offscreen_saved_frame_buffer_; 2046 std::unique_ptr<BackFramebuffer> offscreen_saved_frame_buffer_;
2043 std::unique_ptr<BackTexture> offscreen_saved_color_texture_; 2047 std::unique_ptr<BackTexture> offscreen_saved_color_texture_;
2044 scoped_refptr<TextureRef> 2048 scoped_refptr<TextureRef>
2045 offscreen_saved_color_texture_info_; 2049 offscreen_saved_color_texture_info_;
2046 2050
2051 // When a client requests ownership of the swapped front buffer, all
2052 // information is saved in this structure, and |in_use| is set to true. When a
2053 // client releases ownership, |in_use| is set to false.
2054 //
2055 // An instance of this struct, with |in_use| = false may be reused instead of
2056 // making a new BackTexture.
2057 struct SavedBackTexture {
2058 std::unique_ptr<BackTexture> back_texture;
2059 scoped_refptr<TextureRef> texture_ref;
2060 bool in_use;
2061 };
2062 std::vector<SavedBackTexture> saved_back_textures_;
2063
2064 // If there's a SavedBackTexture that's not in use, takes that. Otherwise,
2065 // generates a new back texture.
2066 void CreateBackTexture();
2067 size_t create_back_texture_count_for_test_ = 0;
2068
2069 // Releases all saved BackTextures that are not in use by a client.
2070 void ReleaseNotInUseBackTextures();
2071
2072 // Releases all saved BackTextures.
2073 void ReleaseAllBackTextures();
2074
2075 size_t GetSavedBackTextureCountForTest() override;
2076 size_t GetCreatedBackTextureCountForTest() override;
2077
2047 // The copy that is used as the destination for multi-sample resolves. 2078 // The copy that is used as the destination for multi-sample resolves.
2048 std::unique_ptr<BackFramebuffer> offscreen_resolved_frame_buffer_; 2079 std::unique_ptr<BackFramebuffer> offscreen_resolved_frame_buffer_;
2049 std::unique_ptr<BackTexture> offscreen_resolved_color_texture_; 2080 std::unique_ptr<BackTexture> offscreen_resolved_color_texture_;
2050 GLenum offscreen_saved_color_format_; 2081 GLenum offscreen_saved_color_format_;
2051 2082
2052 std::unique_ptr<QueryManager> query_manager_; 2083 std::unique_ptr<QueryManager> query_manager_;
2053 2084
2054 std::unique_ptr<VertexArrayManager> vertex_array_manager_; 2085 std::unique_ptr<VertexArrayManager> vertex_array_manager_;
2055 2086
2056 std::unique_ptr<ImageManager> image_manager_; 2087 std::unique_ptr<ImageManager> image_manager_;
(...skipping 2082 matching lines...) Expand 10 before | Expand all | Expand 10 after
4139 state_.bound_renderbuffer = NULL; 4170 state_.bound_renderbuffer = NULL;
4140 state_.bound_valuebuffer = NULL; 4171 state_.bound_valuebuffer = NULL;
4141 4172
4142 if (offscreen_saved_color_texture_info_.get()) { 4173 if (offscreen_saved_color_texture_info_.get()) {
4143 DCHECK(offscreen_target_color_texture_); 4174 DCHECK(offscreen_target_color_texture_);
4144 DCHECK_EQ(offscreen_saved_color_texture_info_->service_id(), 4175 DCHECK_EQ(offscreen_saved_color_texture_info_->service_id(),
4145 offscreen_saved_color_texture_->id()); 4176 offscreen_saved_color_texture_->id());
4146 offscreen_saved_color_texture_->Invalidate(); 4177 offscreen_saved_color_texture_->Invalidate();
4147 offscreen_saved_color_texture_info_ = NULL; 4178 offscreen_saved_color_texture_info_ = NULL;
4148 } 4179 }
4180 ReleaseAllBackTextures();
4149 if (have_context) { 4181 if (have_context) {
4150 if (copy_texture_CHROMIUM_.get()) { 4182 if (copy_texture_CHROMIUM_.get()) {
4151 copy_texture_CHROMIUM_->Destroy(); 4183 copy_texture_CHROMIUM_->Destroy();
4152 copy_texture_CHROMIUM_.reset(); 4184 copy_texture_CHROMIUM_.reset();
4153 } 4185 }
4154 4186
4155 clear_framebuffer_blit_.reset(); 4187 clear_framebuffer_blit_.reset();
4156 4188
4157 if (state_.current_program.get()) { 4189 if (state_.current_program.get()) {
4158 program_manager()->UnuseProgram(shader_manager(), 4190 program_manager()->UnuseProgram(shader_manager(),
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
4277 } 4309 }
4278 4310
4279 void GLES2DecoderImpl::SetSurface( 4311 void GLES2DecoderImpl::SetSurface(
4280 const scoped_refptr<gfx::GLSurface>& surface) { 4312 const scoped_refptr<gfx::GLSurface>& surface) {
4281 DCHECK(context_->IsCurrent(NULL)); 4313 DCHECK(context_->IsCurrent(NULL));
4282 DCHECK(surface_.get()); 4314 DCHECK(surface_.get());
4283 surface_ = surface; 4315 surface_ = surface;
4284 RestoreCurrentFramebufferBindings(); 4316 RestoreCurrentFramebufferBindings();
4285 } 4317 }
4286 4318
4319 void GLES2DecoderImpl::ReleaseSurface() {
4320 if (!context_.get())
4321 return;
4322 if (WasContextLost()) {
4323 DLOG(ERROR) << " GLES2DecoderImpl: Trying to release lost context.";
4324 return;
4325 }
4326 context_->ReleaseCurrent(surface_.get());
4327 surface_ = nullptr;
4328 }
4329
4287 void GLES2DecoderImpl::ProduceFrontBuffer(const Mailbox& mailbox) { 4330 void GLES2DecoderImpl::ProduceFrontBuffer(const Mailbox& mailbox) {
4331 NOTREACHED();
ccameron 2016/04/22 18:25:55 Should this be "TODO: delete me" as well?
4288 if (!offscreen_saved_color_texture_.get()) { 4332 if (!offscreen_saved_color_texture_.get()) {
4289 LOG(ERROR) << "Called ProduceFrontBuffer on a non-offscreen context"; 4333 LOG(ERROR) << "Called ProduceFrontBuffer on a non-offscreen context";
4290 return; 4334 return;
4291 } 4335 }
4292 if (!offscreen_saved_color_texture_info_.get()) { 4336 if (!offscreen_saved_color_texture_info_.get()) {
4293 GLuint service_id = offscreen_saved_color_texture_->id(); 4337 GLuint service_id = offscreen_saved_color_texture_->id();
4294 offscreen_saved_color_texture_info_ = TextureRef::Create( 4338 offscreen_saved_color_texture_info_ = TextureRef::Create(
4295 texture_manager(), 0, service_id); 4339 texture_manager(), 0, service_id);
4296 texture_manager()->SetTarget(offscreen_saved_color_texture_info_.get(), 4340 texture_manager()->SetTarget(offscreen_saved_color_texture_info_.get(),
4297 GL_TEXTURE_2D); 4341 GL_TEXTURE_2D);
4298 UpdateParentTextureInfo(); 4342 UpdateParentTextureInfo();
4299 } 4343 }
4300 mailbox_manager()->ProduceTexture( 4344 mailbox_manager()->ProduceTexture(
4301 mailbox, offscreen_saved_color_texture_info_->texture()); 4345 mailbox, offscreen_saved_color_texture_info_->texture());
4302 } 4346 }
4303 4347
4348 void GLES2DecoderImpl::TakeFrontBuffer(const Mailbox& mailbox) {
4349 if (!offscreen_saved_color_texture_.get()) {
4350 LOG(ERROR) << "Called TakeFrontBuffer on a non-offscreen context";
4351 return;
4352 }
4353
4354 if (!offscreen_saved_color_texture_info_.get()) {
4355 GLuint service_id = offscreen_saved_color_texture_->id();
4356 offscreen_saved_color_texture_info_ = TextureRef::Create(
4357 texture_manager(), 0, service_id);
4358 texture_manager()->SetTarget(offscreen_saved_color_texture_info_.get(),
4359 GL_TEXTURE_2D);
4360 UpdateParentTextureInfo();
4361 }
4362
4363 mailbox_manager()->ProduceTexture(
4364 mailbox, offscreen_saved_color_texture_info_->texture());
4365
4366 // Save the BackTexture and TextureRef.
4367 SavedBackTexture save;
4368 save.back_texture.swap(offscreen_saved_color_texture_);
4369 save.texture_ref = offscreen_saved_color_texture_info_;
4370 offscreen_saved_color_texture_info_ = nullptr;
4371 save.in_use = true;
4372 saved_back_textures_.push_back(std::move(save));
4373
4374 CreateBackTexture();
4375 }
4376
4377 void GLES2DecoderImpl::ReturnFrontBuffer(const Mailbox& mailbox,
4378 bool is_lost) {
4379 for (auto it = saved_back_textures_.begin(); it != saved_back_textures_.end();
4380 ++it) {
4381 Texture* texture = mailbox_manager()->ConsumeTexture(mailbox);
ccameron 2016/04/22 18:25:55 Pull the ConsumeTexture above the loop?
erikchen 2016/04/25 20:58:23 Done.
4382 if (texture != it->texture_ref->texture())
4383 continue;
4384
4385 if (is_lost || it->back_texture->size() != offscreen_size_) {
4386 it->back_texture->Invalidate();
4387 saved_back_textures_.erase(it);
4388 return;
4389 }
4390
4391 it->in_use = false;
ccameron 2016/04/22 18:25:55 Are there circumstances where we would be concerne
erikchen 2016/04/25 20:58:23 If this becomes a problem, we can deal with it. I'
4392 return;
4393 }
4394
4395 NOTREACHED();
4396 }
4397
4398 void GLES2DecoderImpl::CreateBackTexture() {
4399 for (auto it = saved_back_textures_.begin(); it != saved_back_textures_.end();
4400 ++it) {
4401 if (it->in_use)
4402 continue;
4403
4404 if (it->back_texture->size() != offscreen_size_)
4405 continue;
4406 offscreen_saved_color_texture_ = std::move(it->back_texture);
4407 offscreen_saved_color_texture_info_ = it->texture_ref;
4408 saved_back_textures_.erase(it);
4409 return;
4410 }
4411
4412 ++create_back_texture_count_for_test_;
4413 offscreen_saved_color_texture_.reset(
4414 new BackTexture(memory_tracker(), &state_));
4415 offscreen_saved_color_texture_->Create();
4416 offscreen_saved_color_texture_->AllocateStorage(
4417 offscreen_size_, offscreen_saved_color_format_, false);
4418 offscreen_saved_frame_buffer_->AttachRenderTexture(
4419 offscreen_saved_color_texture_.get());
4420 }
4421
4422 void GLES2DecoderImpl::ReleaseNotInUseBackTextures() {
4423 for (auto& saved_back_texture : saved_back_textures_) {
4424 if (!saved_back_texture.in_use)
4425 saved_back_texture.back_texture->Invalidate();
4426 }
4427
4428 std::remove_if(saved_back_textures_.begin(), saved_back_textures_.end(),
4429 [](const SavedBackTexture& saved_back_texture) {
4430 return !saved_back_texture.in_use;
4431 });
4432 }
4433
4434 void GLES2DecoderImpl::ReleaseAllBackTextures() {
4435 for (auto& saved_back_texture : saved_back_textures_) {
4436 // The texture will be destroyed by texture_ref's destructor.
4437 DCHECK(saved_back_texture.texture_ref);
4438 saved_back_texture.back_texture->Invalidate();
4439 }
4440 saved_back_textures_.clear();
4441 }
4442
4443 size_t GLES2DecoderImpl::GetSavedBackTextureCountForTest() {
4444 return saved_back_textures_.size();
4445 }
4446
4447 size_t GLES2DecoderImpl::GetCreatedBackTextureCountForTest() {
4448 return create_back_texture_count_for_test_;
4449 }
4450
4304 bool GLES2DecoderImpl::ResizeOffscreenFrameBuffer(const gfx::Size& size) { 4451 bool GLES2DecoderImpl::ResizeOffscreenFrameBuffer(const gfx::Size& size) {
4305 bool is_offscreen = !!offscreen_target_frame_buffer_.get(); 4452 bool is_offscreen = !!offscreen_target_frame_buffer_.get();
4306 if (!is_offscreen) { 4453 if (!is_offscreen) {
4307 LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer called " 4454 LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer called "
4308 << " with an onscreen framebuffer."; 4455 << " with an onscreen framebuffer.";
4309 return false; 4456 return false;
4310 } 4457 }
4311 4458
4312 if (offscreen_size_ == size) 4459 if (offscreen_size_ == size)
4313 return true; 4460 return true;
(...skipping 8522 matching lines...) Expand 10 before | Expand all | Expand 10 after
12836 "width", offscreen_size_.width(), "height", offscreen_size_.height()); 12983 "width", offscreen_size_.width(), "height", offscreen_size_.height());
12837 if (offscreen_size_ != offscreen_saved_color_texture_->size()) { 12984 if (offscreen_size_ != offscreen_saved_color_texture_->size()) {
12838 // Workaround for NVIDIA driver bug on OS X; crbug.com/89557, 12985 // Workaround for NVIDIA driver bug on OS X; crbug.com/89557,
12839 // crbug.com/94163. TODO(kbr): figure out reproduction so Apple will 12986 // crbug.com/94163. TODO(kbr): figure out reproduction so Apple will
12840 // fix this. 12987 // fix this.
12841 if (workarounds().needs_offscreen_buffer_workaround) { 12988 if (workarounds().needs_offscreen_buffer_workaround) {
12842 offscreen_saved_frame_buffer_->Create(); 12989 offscreen_saved_frame_buffer_->Create();
12843 glFinish(); 12990 glFinish();
12844 } 12991 }
12845 12992
12993 // The size has changed, so none of the cached BackTextures are useful
12994 // anymore.
12995 ReleaseNotInUseBackTextures();
12996
12846 // Allocate the offscreen saved color texture. 12997 // Allocate the offscreen saved color texture.
12847 DCHECK(offscreen_saved_color_format_); 12998 DCHECK(offscreen_saved_color_format_);
12848 offscreen_saved_color_texture_->AllocateStorage( 12999 offscreen_saved_color_texture_->AllocateStorage(
12849 offscreen_size_, offscreen_saved_color_format_, false); 13000 offscreen_size_, offscreen_saved_color_format_, false);
12850 13001
12851 offscreen_saved_frame_buffer_->AttachRenderTexture( 13002 offscreen_saved_frame_buffer_->AttachRenderTexture(
12852 offscreen_saved_color_texture_.get()); 13003 offscreen_saved_color_texture_.get());
12853 if (offscreen_size_.width() != 0 && offscreen_size_.height() != 0) { 13004 if (offscreen_size_.width() != 0 && offscreen_size_.height() != 0) {
12854 if (offscreen_saved_frame_buffer_->CheckStatus() != 13005 if (offscreen_saved_frame_buffer_->CheckStatus() !=
12855 GL_FRAMEBUFFER_COMPLETE) { 13006 GL_FRAMEBUFFER_COMPLETE) {
(...skipping 3696 matching lines...) Expand 10 before | Expand all | Expand 10 after
16552 } 16703 }
16553 16704
16554 // Include the auto-generated part of this file. We split this because it means 16705 // Include the auto-generated part of this file. We split this because it means
16555 // we can easily edit the non-auto generated parts right here in this file 16706 // we can easily edit the non-auto generated parts right here in this file
16556 // instead of having to edit some template or the code generator. 16707 // instead of having to edit some template or the code generator.
16557 #include "base/macros.h" 16708 #include "base/macros.h"
16558 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 16709 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
16559 16710
16560 } // namespace gles2 16711 } // namespace gles2
16561 } // namespace gpu 16712 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698