| OLD | NEW |
| 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 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 private: | 380 private: |
| 381 GLuint temp_texture_id_ = 0; | 381 GLuint temp_texture_id_ = 0; |
| 382 GLuint temp_fbo_id_ = 0; | 382 GLuint temp_fbo_id_ = 0; |
| 383 std::unique_ptr<ScopedFrameBufferBinder> fbo_binder_; | 383 std::unique_ptr<ScopedFrameBufferBinder> fbo_binder_; |
| 384 DISALLOW_COPY_AND_ASSIGN(ScopedFrameBufferReadPixelHelper); | 384 DISALLOW_COPY_AND_ASSIGN(ScopedFrameBufferReadPixelHelper); |
| 385 }; | 385 }; |
| 386 | 386 |
| 387 // Encapsulates an OpenGL texture. | 387 // Encapsulates an OpenGL texture. |
| 388 class BackTexture { | 388 class BackTexture { |
| 389 public: | 389 public: |
| 390 explicit BackTexture(MemoryTracker* memory_tracker, ContextState* state); | 390 explicit BackTexture(GLES2DecoderImpl* decoder); |
| 391 ~BackTexture(); | 391 ~BackTexture(); |
| 392 | 392 |
| 393 // Create a new render texture. | 393 // Create a new render texture. |
| 394 void Create(); | 394 void Create(); |
| 395 | 395 |
| 396 // Set the initial size and format of a render texture or resize it. | 396 // Set the initial size and format of a render texture or resize it. |
| 397 bool AllocateStorage(const gfx::Size& size, GLenum format, bool zero); | 397 bool AllocateStorage(const gfx::Size& size, GLenum format, bool zero); |
| 398 | 398 |
| 399 // Copy the contents of the currently bound frame buffer. | 399 // Copy the contents of the currently bound frame buffer. |
| 400 void Copy(const gfx::Size& size, GLenum format); | 400 void Copy(const gfx::Size& size, GLenum format); |
| 401 | 401 |
| 402 // Destroy the render texture. This must be explicitly called before | 402 // Destroy the render texture. This must be explicitly called before |
| 403 // destroying this object. | 403 // destroying this object. |
| 404 void Destroy(); | 404 void Destroy(); |
| 405 | 405 |
| 406 // Invalidate the texture. This can be used when a context is lost and it is | 406 // Invalidate the texture. This can be used when a context is lost and it is |
| 407 // not possible to make it current in order to free the resource. | 407 // not possible to make it current in order to free the resource. |
| 408 void Invalidate(); | 408 void Invalidate(); |
| 409 | 409 |
| 410 scoped_refptr<TextureRef> texture_ref() { return texture_ref_; } |
| 411 |
| 410 GLuint id() const { | 412 GLuint id() const { |
| 411 return id_; | 413 return texture_ref_ ? texture_ref_->service_id() : 0; |
| 412 } | 414 } |
| 413 | 415 |
| 414 gfx::Size size() const { | 416 gfx::Size size() const { |
| 415 return size_; | 417 return size_; |
| 416 } | 418 } |
| 417 | 419 |
| 418 private: | 420 private: |
| 419 MemoryTypeTracker memory_tracker_; | 421 MemoryTypeTracker memory_tracker_; |
| 420 ContextState* state_; | |
| 421 size_t bytes_allocated_; | 422 size_t bytes_allocated_; |
| 422 GLuint id_; | |
| 423 gfx::Size size_; | 423 gfx::Size size_; |
| 424 GLES2DecoderImpl* decoder_; |
| 425 |
| 426 scoped_refptr<TextureRef> texture_ref_; |
| 427 |
| 424 DISALLOW_COPY_AND_ASSIGN(BackTexture); | 428 DISALLOW_COPY_AND_ASSIGN(BackTexture); |
| 425 }; | 429 }; |
| 426 | 430 |
| 427 // Encapsulates an OpenGL render buffer of any format. | 431 // Encapsulates an OpenGL render buffer of any format. |
| 428 class BackRenderbuffer { | 432 class BackRenderbuffer { |
| 429 public: | 433 public: |
| 430 explicit BackRenderbuffer( | 434 explicit BackRenderbuffer( |
| 431 RenderbufferManager* renderbuffer_manager, | 435 RenderbufferManager* renderbuffer_manager, |
| 432 MemoryTracker* memory_tracker, | 436 MemoryTracker* memory_tracker, |
| 433 ContextState* state); | 437 ContextState* state); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 bool offscreen, | 572 bool offscreen, |
| 569 const gfx::Size& offscreen_size, | 573 const gfx::Size& offscreen_size, |
| 570 const DisallowedFeatures& disallowed_features, | 574 const DisallowedFeatures& disallowed_features, |
| 571 const ContextCreationAttribHelper& attrib_helper) override; | 575 const ContextCreationAttribHelper& attrib_helper) override; |
| 572 void Destroy(bool have_context) override; | 576 void Destroy(bool have_context) override; |
| 573 void SetSurface(const scoped_refptr<gl::GLSurface>& surface) override; | 577 void SetSurface(const scoped_refptr<gl::GLSurface>& surface) override; |
| 574 void ReleaseSurface() override; | 578 void ReleaseSurface() override; |
| 575 void TakeFrontBuffer(const Mailbox& mailbox) override; | 579 void TakeFrontBuffer(const Mailbox& mailbox) override; |
| 576 void ReturnFrontBuffer(const Mailbox& mailbox, bool is_lost) override; | 580 void ReturnFrontBuffer(const Mailbox& mailbox, bool is_lost) override; |
| 577 bool ResizeOffscreenFrameBuffer(const gfx::Size& size) override; | 581 bool ResizeOffscreenFrameBuffer(const gfx::Size& size) override; |
| 578 void UpdateParentTextureInfo(); | |
| 579 bool MakeCurrent() override; | 582 bool MakeCurrent() override; |
| 580 GLES2Util* GetGLES2Util() override { return &util_; } | 583 GLES2Util* GetGLES2Util() override { return &util_; } |
| 581 gl::GLContext* GetGLContext() override { return context_.get(); } | 584 gl::GLContext* GetGLContext() override { return context_.get(); } |
| 582 ContextGroup* GetContextGroup() override { return group_.get(); } | 585 ContextGroup* GetContextGroup() override { return group_.get(); } |
| 583 Capabilities GetCapabilities() override; | 586 Capabilities GetCapabilities() override; |
| 584 void RestoreState(const ContextState* prev_state) override; | 587 void RestoreState(const ContextState* prev_state) override; |
| 585 | 588 |
| 586 void RestoreActiveTexture() const override { state_.RestoreActiveTexture(); } | 589 void RestoreActiveTexture() const override { state_.RestoreActiveTexture(); } |
| 587 void RestoreAllTextureUnitBindings( | 590 void RestoreAllTextureUnitBindings( |
| 588 const ContextState* prev_state) const override { | 591 const ContextState* prev_state) const override { |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 GLbitfield mask, | 701 GLbitfield mask, |
| 699 GLenum filter); | 702 GLenum filter); |
| 700 | 703 |
| 701 PathManager* path_manager() { return group_->path_manager(); } | 704 PathManager* path_manager() { return group_->path_manager(); } |
| 702 | 705 |
| 703 private: | 706 private: |
| 704 friend class ScopedFrameBufferBinder; | 707 friend class ScopedFrameBufferBinder; |
| 705 friend class ScopedFrameBufferReadPixelHelper; | 708 friend class ScopedFrameBufferReadPixelHelper; |
| 706 friend class ScopedResolvedFrameBufferBinder; | 709 friend class ScopedResolvedFrameBufferBinder; |
| 707 friend class BackFramebuffer; | 710 friend class BackFramebuffer; |
| 711 friend class BackTexture; |
| 708 | 712 |
| 709 enum FramebufferOperation { | 713 enum FramebufferOperation { |
| 710 kFramebufferDiscard, | 714 kFramebufferDiscard, |
| 711 kFramebufferInvalidate, | 715 kFramebufferInvalidate, |
| 712 kFramebufferInvalidateSub | 716 kFramebufferInvalidateSub |
| 713 }; | 717 }; |
| 714 | 718 |
| 715 enum BindIndexedBufferFunctionType { | 719 enum BindIndexedBufferFunctionType { |
| 716 kBindBufferBase, | 720 kBindBufferBase, |
| 717 kBindBufferRange | 721 kBindBufferRange |
| (...skipping 1323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2041 GLenum offscreen_target_stencil_format_; | 2045 GLenum offscreen_target_stencil_format_; |
| 2042 GLsizei offscreen_target_samples_; | 2046 GLsizei offscreen_target_samples_; |
| 2043 GLboolean offscreen_target_buffer_preserved_; | 2047 GLboolean offscreen_target_buffer_preserved_; |
| 2044 | 2048 |
| 2045 // The saved copy of the backbuffer after a call to SwapBuffers. | 2049 // The saved copy of the backbuffer after a call to SwapBuffers. |
| 2046 std::unique_ptr<BackTexture> offscreen_saved_color_texture_; | 2050 std::unique_ptr<BackTexture> offscreen_saved_color_texture_; |
| 2047 | 2051 |
| 2048 // For simplicity, |offscreen_saved_color_texture_| is always bound to | 2052 // For simplicity, |offscreen_saved_color_texture_| is always bound to |
| 2049 // |offscreen_saved_frame_buffer_|. | 2053 // |offscreen_saved_frame_buffer_|. |
| 2050 std::unique_ptr<BackFramebuffer> offscreen_saved_frame_buffer_; | 2054 std::unique_ptr<BackFramebuffer> offscreen_saved_frame_buffer_; |
| 2051 scoped_refptr<TextureRef> | |
| 2052 offscreen_saved_color_texture_info_; | |
| 2053 | 2055 |
| 2054 // When a client requests ownership of the swapped front buffer, all | 2056 // When a client requests ownership of the swapped front buffer, all |
| 2055 // information is saved in this structure, and |in_use| is set to true. When a | 2057 // information is saved in this structure, and |in_use| is set to true. When a |
| 2056 // client releases ownership, |in_use| is set to false. | 2058 // client releases ownership, |in_use| is set to false. |
| 2057 // | 2059 // |
| 2058 // An instance of this struct, with |in_use| = false may be reused instead of | 2060 // An instance of this struct, with |in_use| = false may be reused instead of |
| 2059 // making a new BackTexture. | 2061 // making a new BackTexture. |
| 2060 struct SavedBackTexture { | 2062 struct SavedBackTexture { |
| 2061 std::unique_ptr<BackTexture> back_texture; | 2063 std::unique_ptr<BackTexture> back_texture; |
| 2062 scoped_refptr<TextureRef> texture_ref; | |
| 2063 bool in_use; | 2064 bool in_use; |
| 2064 }; | 2065 }; |
| 2065 std::vector<SavedBackTexture> saved_back_textures_; | 2066 std::vector<SavedBackTexture> saved_back_textures_; |
| 2066 | 2067 |
| 2067 // If there's a SavedBackTexture that's not in use, takes that. Otherwise, | 2068 // If there's a SavedBackTexture that's not in use, takes that. Otherwise, |
| 2068 // generates a new back texture. | 2069 // generates a new back texture. |
| 2069 void CreateBackTexture(); | 2070 void CreateBackTexture(); |
| 2070 size_t create_back_texture_count_for_test_ = 0; | 2071 size_t create_back_texture_count_for_test_ = 0; |
| 2071 | 2072 |
| 2072 // Releases all saved BackTextures that are not in use by a client. | 2073 // Releases all saved BackTextures that are not in use by a client. |
| 2073 void ReleaseNotInUseBackTextures(); | 2074 void ReleaseNotInUseBackTextures(); |
| 2074 | 2075 |
| 2075 // Releases all saved BackTextures. | 2076 // Releases all saved BackTextures. |
| 2076 void ReleaseAllBackTextures(); | 2077 void ReleaseAllBackTextures(bool have_context); |
| 2077 | 2078 |
| 2078 size_t GetSavedBackTextureCountForTest() override; | 2079 size_t GetSavedBackTextureCountForTest() override; |
| 2079 size_t GetCreatedBackTextureCountForTest() override; | 2080 size_t GetCreatedBackTextureCountForTest() override; |
| 2080 | 2081 |
| 2081 // The copy that is used as the destination for multi-sample resolves. | 2082 // The copy that is used as the destination for multi-sample resolves. |
| 2082 std::unique_ptr<BackFramebuffer> offscreen_resolved_frame_buffer_; | 2083 std::unique_ptr<BackFramebuffer> offscreen_resolved_frame_buffer_; |
| 2083 std::unique_ptr<BackTexture> offscreen_resolved_color_texture_; | 2084 std::unique_ptr<BackTexture> offscreen_resolved_color_texture_; |
| 2084 GLenum offscreen_saved_color_format_; | 2085 GLenum offscreen_saved_color_format_; |
| 2085 | 2086 |
| 2086 std::unique_ptr<QueryManager> query_manager_; | 2087 std::unique_ptr<QueryManager> query_manager_; |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2326 "ScopedResolvedFrameBufferBinder::ctor", decoder_->GetErrorState()); | 2327 "ScopedResolvedFrameBufferBinder::ctor", decoder_->GetErrorState()); |
| 2327 glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, | 2328 glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, |
| 2328 decoder_->offscreen_target_frame_buffer_->id()); | 2329 decoder_->offscreen_target_frame_buffer_->id()); |
| 2329 GLuint targetid; | 2330 GLuint targetid; |
| 2330 if (internal) { | 2331 if (internal) { |
| 2331 if (!decoder_->offscreen_resolved_frame_buffer_.get()) { | 2332 if (!decoder_->offscreen_resolved_frame_buffer_.get()) { |
| 2332 decoder_->offscreen_resolved_frame_buffer_.reset( | 2333 decoder_->offscreen_resolved_frame_buffer_.reset( |
| 2333 new BackFramebuffer(decoder_)); | 2334 new BackFramebuffer(decoder_)); |
| 2334 decoder_->offscreen_resolved_frame_buffer_->Create(); | 2335 decoder_->offscreen_resolved_frame_buffer_->Create(); |
| 2335 decoder_->offscreen_resolved_color_texture_.reset( | 2336 decoder_->offscreen_resolved_color_texture_.reset( |
| 2336 new BackTexture(decoder->memory_tracker(), &decoder->state_)); | 2337 new BackTexture(decoder)); |
| 2337 decoder_->offscreen_resolved_color_texture_->Create(); | 2338 decoder_->offscreen_resolved_color_texture_->Create(); |
| 2338 | 2339 |
| 2339 DCHECK(decoder_->offscreen_saved_color_format_); | 2340 DCHECK(decoder_->offscreen_saved_color_format_); |
| 2340 decoder_->offscreen_resolved_color_texture_->AllocateStorage( | 2341 decoder_->offscreen_resolved_color_texture_->AllocateStorage( |
| 2341 decoder_->offscreen_size_, decoder_->offscreen_saved_color_format_, | 2342 decoder_->offscreen_size_, decoder_->offscreen_saved_color_format_, |
| 2342 false); | 2343 false); |
| 2343 decoder_->offscreen_resolved_frame_buffer_->AttachRenderTexture( | 2344 decoder_->offscreen_resolved_frame_buffer_->AttachRenderTexture( |
| 2344 decoder_->offscreen_resolved_color_texture_.get()); | 2345 decoder_->offscreen_resolved_color_texture_.get()); |
| 2345 if (decoder_->offscreen_resolved_frame_buffer_->CheckStatus() != | 2346 if (decoder_->offscreen_resolved_frame_buffer_->CheckStatus() != |
| 2346 GL_FRAMEBUFFER_COMPLETE) { | 2347 GL_FRAMEBUFFER_COMPLETE) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2410 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, | 2411 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, |
| 2411 temp_texture_id_, 0); | 2412 temp_texture_id_, 0); |
| 2412 } | 2413 } |
| 2413 | 2414 |
| 2414 ScopedFrameBufferReadPixelHelper::~ScopedFrameBufferReadPixelHelper() { | 2415 ScopedFrameBufferReadPixelHelper::~ScopedFrameBufferReadPixelHelper() { |
| 2415 fbo_binder_.reset(); | 2416 fbo_binder_.reset(); |
| 2416 glDeleteTextures(1, &temp_texture_id_); | 2417 glDeleteTextures(1, &temp_texture_id_); |
| 2417 glDeleteFramebuffersEXT(1, &temp_fbo_id_); | 2418 glDeleteFramebuffersEXT(1, &temp_fbo_id_); |
| 2418 } | 2419 } |
| 2419 | 2420 |
| 2420 BackTexture::BackTexture( | 2421 BackTexture::BackTexture(GLES2DecoderImpl* decoder) |
| 2421 MemoryTracker* memory_tracker, | 2422 : memory_tracker_(decoder->memory_tracker()), |
| 2422 ContextState* state) | |
| 2423 : memory_tracker_(memory_tracker), | |
| 2424 state_(state), | |
| 2425 bytes_allocated_(0), | 2423 bytes_allocated_(0), |
| 2426 id_(0) { | 2424 decoder_(decoder) {} |
| 2427 } | |
| 2428 | 2425 |
| 2429 BackTexture::~BackTexture() { | 2426 BackTexture::~BackTexture() { |
| 2430 // This does not destroy the render texture because that would require that | 2427 // This does not destroy the render texture because that would require that |
| 2431 // the associated GL context was current. Just check that it was explicitly | 2428 // the associated GL context was current. Just check that it was explicitly |
| 2432 // destroyed. | 2429 // destroyed. |
| 2433 DCHECK_EQ(id_, 0u); | 2430 DCHECK_EQ(id(), 0u); |
| 2434 } | 2431 } |
| 2435 | 2432 |
| 2436 void BackTexture::Create() { | 2433 void BackTexture::Create() { |
| 2437 DCHECK_EQ(id_, 0u); | 2434 DCHECK_EQ(id(), 0u); |
| 2438 ScopedGLErrorSuppressor suppressor("BackTexture::Create", | 2435 ScopedGLErrorSuppressor suppressor("BackTexture::Create", |
| 2439 state_->GetErrorState()); | 2436 decoder_->state_.GetErrorState()); |
| 2440 glGenTextures(1, &id_); | 2437 GLuint id; |
| 2441 ScopedTextureBinder binder(state_, id_, GL_TEXTURE_2D); | 2438 glGenTextures(1, &id); |
| 2442 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 2439 |
| 2443 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 2440 GLenum target = GL_TEXTURE_2D; |
| 2444 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 2441 ScopedTextureBinder binder(&decoder_->state_, id, target); |
| 2445 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 2442 |
| 2443 // No client id is necessary because this texture will never be directly |
| 2444 // accessed by a client, only indirectly via a mailbox. |
| 2445 texture_ref_ = TextureRef::Create(decoder_->texture_manager(), 0, id); |
| 2446 decoder_->texture_manager()->SetTarget(texture_ref_.get(), target); |
| 2447 decoder_->texture_manager()->SetParameteri( |
| 2448 "BackTexture::Create", |
| 2449 decoder_->GetErrorState(), |
| 2450 texture_ref_.get(), |
| 2451 GL_TEXTURE_MAG_FILTER, |
| 2452 GL_LINEAR); |
| 2453 decoder_->texture_manager()->SetParameteri( |
| 2454 "BackTexture::Create", |
| 2455 decoder_->GetErrorState(), |
| 2456 texture_ref_.get(), |
| 2457 GL_TEXTURE_MIN_FILTER, |
| 2458 GL_LINEAR); |
| 2459 decoder_->texture_manager()->SetParameteri( |
| 2460 "BackTexture::Create", |
| 2461 decoder_->GetErrorState(), |
| 2462 texture_ref_.get(), |
| 2463 GL_TEXTURE_WRAP_S, |
| 2464 GL_CLAMP_TO_EDGE); |
| 2465 decoder_->texture_manager()->SetParameteri( |
| 2466 "BackTexture::Create", |
| 2467 decoder_->GetErrorState(), |
| 2468 texture_ref_.get(), |
| 2469 GL_TEXTURE_WRAP_T, |
| 2470 GL_CLAMP_TO_EDGE); |
| 2446 } | 2471 } |
| 2447 | 2472 |
| 2448 bool BackTexture::AllocateStorage( | 2473 bool BackTexture::AllocateStorage( |
| 2449 const gfx::Size& size, GLenum format, bool zero) { | 2474 const gfx::Size& size, GLenum format, bool zero) { |
| 2450 DCHECK_NE(id_, 0u); | 2475 DCHECK_NE(id(), 0u); |
| 2451 ScopedGLErrorSuppressor suppressor("BackTexture::AllocateStorage", | 2476 ScopedGLErrorSuppressor suppressor("BackTexture::AllocateStorage", |
| 2452 state_->GetErrorState()); | 2477 decoder_->state_.GetErrorState()); |
| 2453 ScopedTextureBinder binder(state_, id_, GL_TEXTURE_2D); | 2478 ScopedTextureBinder binder(&decoder_->state_, id(), GL_TEXTURE_2D); |
| 2454 uint32_t image_size = 0; | 2479 uint32_t image_size = 0; |
| 2455 GLES2Util::ComputeImageDataSizes( | 2480 GLES2Util::ComputeImageDataSizes( |
| 2456 size.width(), size.height(), 1, format, GL_UNSIGNED_BYTE, 8, &image_size, | 2481 size.width(), size.height(), 1, format, GL_UNSIGNED_BYTE, 8, &image_size, |
| 2457 NULL, NULL); | 2482 NULL, NULL); |
| 2458 | 2483 |
| 2459 if (!memory_tracker_.EnsureGPUMemoryAvailable(image_size)) { | 2484 if (!memory_tracker_.EnsureGPUMemoryAvailable(image_size)) { |
| 2460 return false; | 2485 return false; |
| 2461 } | 2486 } |
| 2462 | 2487 |
| 2463 std::unique_ptr<char[]> zero_data; | 2488 std::unique_ptr<char[]> zero_data; |
| 2464 if (zero) { | 2489 if (zero) { |
| 2465 zero_data.reset(new char[image_size]); | 2490 zero_data.reset(new char[image_size]); |
| 2466 memset(zero_data.get(), 0, image_size); | 2491 memset(zero_data.get(), 0, image_size); |
| 2467 } | 2492 } |
| 2468 | 2493 |
| 2469 glTexImage2D(GL_TEXTURE_2D, | 2494 glTexImage2D(GL_TEXTURE_2D, |
| 2470 0, // mip level | 2495 0, // mip level |
| 2471 format, | 2496 format, |
| 2472 size.width(), | 2497 size.width(), |
| 2473 size.height(), | 2498 size.height(), |
| 2474 0, // border | 2499 0, // border |
| 2475 format, | 2500 format, |
| 2476 GL_UNSIGNED_BYTE, | 2501 GL_UNSIGNED_BYTE, |
| 2477 zero_data.get()); | 2502 zero_data.get()); |
| 2478 | 2503 |
| 2479 size_ = size; | 2504 size_ = size; |
| 2505 decoder_->texture_manager()->SetLevelInfo(texture_ref_.get(), GL_TEXTURE_2D, |
| 2506 0, // level |
| 2507 GL_RGBA, size_.width(), size_.height(), |
| 2508 1, // depth |
| 2509 0, // border |
| 2510 GL_RGBA, GL_UNSIGNED_BYTE, gfx::Rect(size_)); |
| 2480 | 2511 |
| 2481 bool success = glGetError() == GL_NO_ERROR; | 2512 bool success = glGetError() == GL_NO_ERROR; |
| 2482 if (success) { | 2513 if (success) { |
| 2483 memory_tracker_.TrackMemFree(bytes_allocated_); | 2514 memory_tracker_.TrackMemFree(bytes_allocated_); |
| 2484 bytes_allocated_ = image_size; | 2515 bytes_allocated_ = image_size; |
| 2485 memory_tracker_.TrackMemAlloc(bytes_allocated_); | 2516 memory_tracker_.TrackMemAlloc(bytes_allocated_); |
| 2486 } | 2517 } |
| 2487 return success; | 2518 return success; |
| 2488 } | 2519 } |
| 2489 | 2520 |
| 2490 void BackTexture::Copy(const gfx::Size& size, GLenum format) { | 2521 void BackTexture::Copy(const gfx::Size& size, GLenum format) { |
| 2491 DCHECK_NE(id_, 0u); | 2522 DCHECK_NE(id(), 0u); |
| 2492 ScopedGLErrorSuppressor suppressor("BackTexture::Copy", | 2523 ScopedGLErrorSuppressor suppressor("BackTexture::Copy", |
| 2493 state_->GetErrorState()); | 2524 decoder_->state_.GetErrorState()); |
| 2494 ScopedTextureBinder binder(state_, id_, GL_TEXTURE_2D); | 2525 ScopedTextureBinder binder(&decoder_->state_, id(), GL_TEXTURE_2D); |
| 2495 glCopyTexImage2D(GL_TEXTURE_2D, | 2526 glCopyTexImage2D(GL_TEXTURE_2D, |
| 2496 0, // level | 2527 0, // level |
| 2497 format, | 2528 format, |
| 2498 0, 0, | 2529 0, 0, |
| 2499 size.width(), | 2530 size.width(), |
| 2500 size.height(), | 2531 size.height(), |
| 2501 0); // border | 2532 0); // border |
| 2502 } | 2533 } |
| 2503 | 2534 |
| 2504 void BackTexture::Destroy() { | 2535 void BackTexture::Destroy() { |
| 2505 if (id_ != 0) { | 2536 if (texture_ref_) { |
| 2506 ScopedGLErrorSuppressor suppressor("BackTexture::Destroy", | 2537 ScopedGLErrorSuppressor suppressor("BackTexture::Destroy", |
| 2507 state_->GetErrorState()); | 2538 decoder_->state_.GetErrorState()); |
| 2508 glDeleteTextures(1, &id_); | 2539 texture_ref_ = nullptr; |
| 2509 id_ = 0; | |
| 2510 } | 2540 } |
| 2511 memory_tracker_.TrackMemFree(bytes_allocated_); | 2541 memory_tracker_.TrackMemFree(bytes_allocated_); |
| 2512 bytes_allocated_ = 0; | 2542 bytes_allocated_ = 0; |
| 2513 } | 2543 } |
| 2514 | 2544 |
| 2515 void BackTexture::Invalidate() { | 2545 void BackTexture::Invalidate() { |
| 2516 id_ = 0; | 2546 if (texture_ref_) { |
| 2547 texture_ref_->ForceContextLost(); |
| 2548 texture_ref_ = nullptr; |
| 2549 } |
| 2517 } | 2550 } |
| 2518 | 2551 |
| 2519 BackRenderbuffer::BackRenderbuffer( | 2552 BackRenderbuffer::BackRenderbuffer( |
| 2520 RenderbufferManager* renderbuffer_manager, | 2553 RenderbufferManager* renderbuffer_manager, |
| 2521 MemoryTracker* memory_tracker, | 2554 MemoryTracker* memory_tracker, |
| 2522 ContextState* state) | 2555 ContextState* state) |
| 2523 : renderbuffer_manager_(renderbuffer_manager), | 2556 : renderbuffer_manager_(renderbuffer_manager), |
| 2524 memory_tracker_(memory_tracker), | 2557 memory_tracker_(memory_tracker), |
| 2525 state_(state), | 2558 state_(state), |
| 2526 bytes_allocated_(0), | 2559 bytes_allocated_(0), |
| (...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2982 offscreen_target_frame_buffer_->Create(); | 3015 offscreen_target_frame_buffer_->Create(); |
| 2983 // Due to GLES2 format limitations, either the color texture (for | 3016 // Due to GLES2 format limitations, either the color texture (for |
| 2984 // non-multisampling) or the color render buffer (for multisampling) will be | 3017 // non-multisampling) or the color render buffer (for multisampling) will be |
| 2985 // attached to the offscreen frame buffer. The render buffer has more | 3018 // attached to the offscreen frame buffer. The render buffer has more |
| 2986 // limited formats available to it, but the texture can't do multisampling. | 3019 // limited formats available to it, but the texture can't do multisampling. |
| 2987 if (IsOffscreenBufferMultisampled()) { | 3020 if (IsOffscreenBufferMultisampled()) { |
| 2988 offscreen_target_color_render_buffer_.reset(new BackRenderbuffer( | 3021 offscreen_target_color_render_buffer_.reset(new BackRenderbuffer( |
| 2989 renderbuffer_manager(), memory_tracker(), &state_)); | 3022 renderbuffer_manager(), memory_tracker(), &state_)); |
| 2990 offscreen_target_color_render_buffer_->Create(); | 3023 offscreen_target_color_render_buffer_->Create(); |
| 2991 } else { | 3024 } else { |
| 2992 offscreen_target_color_texture_.reset(new BackTexture( | 3025 offscreen_target_color_texture_.reset(new BackTexture(this)); |
| 2993 memory_tracker(), &state_)); | |
| 2994 offscreen_target_color_texture_->Create(); | 3026 offscreen_target_color_texture_->Create(); |
| 2995 } | 3027 } |
| 2996 offscreen_target_depth_render_buffer_.reset(new BackRenderbuffer( | 3028 offscreen_target_depth_render_buffer_.reset(new BackRenderbuffer( |
| 2997 renderbuffer_manager(), memory_tracker(), &state_)); | 3029 renderbuffer_manager(), memory_tracker(), &state_)); |
| 2998 offscreen_target_depth_render_buffer_->Create(); | 3030 offscreen_target_depth_render_buffer_->Create(); |
| 2999 offscreen_target_stencil_render_buffer_.reset(new BackRenderbuffer( | 3031 offscreen_target_stencil_render_buffer_.reset(new BackRenderbuffer( |
| 3000 renderbuffer_manager(), memory_tracker(), &state_)); | 3032 renderbuffer_manager(), memory_tracker(), &state_)); |
| 3001 offscreen_target_stencil_render_buffer_->Create(); | 3033 offscreen_target_stencil_render_buffer_->Create(); |
| 3002 | 3034 |
| 3003 // Create the saved offscreen texture. The target frame buffer is copied | 3035 // Create the saved offscreen texture. The target frame buffer is copied |
| 3004 // here when SwapBuffers is called. | 3036 // here when SwapBuffers is called. |
| 3005 offscreen_saved_frame_buffer_.reset(new BackFramebuffer(this)); | 3037 offscreen_saved_frame_buffer_.reset(new BackFramebuffer(this)); |
| 3006 offscreen_saved_frame_buffer_->Create(); | 3038 offscreen_saved_frame_buffer_->Create(); |
| 3007 // | 3039 // |
| 3008 offscreen_saved_color_texture_.reset(new BackTexture( | 3040 offscreen_saved_color_texture_.reset(new BackTexture(this)); |
| 3009 memory_tracker(), &state_)); | |
| 3010 offscreen_saved_color_texture_->Create(); | 3041 offscreen_saved_color_texture_->Create(); |
| 3011 | 3042 |
| 3012 // Allocate the render buffers at their initial size and check the status | 3043 // Allocate the render buffers at their initial size and check the status |
| 3013 // of the frame buffers is okay. | 3044 // of the frame buffers is okay. |
| 3014 if (!ResizeOffscreenFrameBuffer(offscreen_size)) { | 3045 if (!ResizeOffscreenFrameBuffer(offscreen_size)) { |
| 3015 LOG(ERROR) << "Could not allocate offscreen buffer storage."; | 3046 LOG(ERROR) << "Could not allocate offscreen buffer storage."; |
| 3016 Destroy(true); | 3047 Destroy(true); |
| 3017 return false; | 3048 return false; |
| 3018 } | 3049 } |
| 3019 | 3050 |
| (...skipping 1109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4129 break; | 4160 break; |
| 4130 default: | 4161 default: |
| 4131 // Caller is responsible for breaking GL_DEPTH_STENCIL into GL_DEPTH and | 4162 // Caller is responsible for breaking GL_DEPTH_STENCIL into GL_DEPTH and |
| 4132 // GL_STENCIL. | 4163 // GL_STENCIL. |
| 4133 NOTREACHED(); | 4164 NOTREACHED(); |
| 4134 } | 4165 } |
| 4135 framebuffer->MarkAttachmentAsCleared( | 4166 framebuffer->MarkAttachmentAsCleared( |
| 4136 renderbuffer_manager(), texture_manager(), attachment, true); | 4167 renderbuffer_manager(), texture_manager(), attachment, true); |
| 4137 } | 4168 } |
| 4138 | 4169 |
| 4139 void GLES2DecoderImpl::UpdateParentTextureInfo() { | |
| 4140 if (!offscreen_saved_color_texture_info_.get()) | |
| 4141 return; | |
| 4142 GLenum target = offscreen_saved_color_texture_info_->texture()->target(); | |
| 4143 glBindTexture(target, offscreen_saved_color_texture_info_->service_id()); | |
| 4144 texture_manager()->SetLevelInfo( | |
| 4145 offscreen_saved_color_texture_info_.get(), GL_TEXTURE_2D, | |
| 4146 0, // level | |
| 4147 GL_RGBA, offscreen_size_.width(), offscreen_size_.height(), | |
| 4148 1, // depth | |
| 4149 0, // border | |
| 4150 GL_RGBA, GL_UNSIGNED_BYTE, gfx::Rect(offscreen_size_)); | |
| 4151 texture_manager()->SetParameteri( | |
| 4152 "UpdateParentTextureInfo", | |
| 4153 GetErrorState(), | |
| 4154 offscreen_saved_color_texture_info_.get(), | |
| 4155 GL_TEXTURE_MAG_FILTER, | |
| 4156 GL_LINEAR); | |
| 4157 texture_manager()->SetParameteri( | |
| 4158 "UpdateParentTextureInfo", | |
| 4159 GetErrorState(), | |
| 4160 offscreen_saved_color_texture_info_.get(), | |
| 4161 GL_TEXTURE_MIN_FILTER, | |
| 4162 GL_LINEAR); | |
| 4163 texture_manager()->SetParameteri( | |
| 4164 "UpdateParentTextureInfo", | |
| 4165 GetErrorState(), | |
| 4166 offscreen_saved_color_texture_info_.get(), | |
| 4167 GL_TEXTURE_WRAP_S, | |
| 4168 GL_CLAMP_TO_EDGE); | |
| 4169 texture_manager()->SetParameteri( | |
| 4170 "UpdateParentTextureInfo", | |
| 4171 GetErrorState(), | |
| 4172 offscreen_saved_color_texture_info_.get(), | |
| 4173 GL_TEXTURE_WRAP_T, | |
| 4174 GL_CLAMP_TO_EDGE); | |
| 4175 TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( | |
| 4176 &state_, target); | |
| 4177 glBindTexture(target, texture_ref ? texture_ref->service_id() : 0); | |
| 4178 } | |
| 4179 | |
| 4180 Logger* GLES2DecoderImpl::GetLogger() { | 4170 Logger* GLES2DecoderImpl::GetLogger() { |
| 4181 return &logger_; | 4171 return &logger_; |
| 4182 } | 4172 } |
| 4183 | 4173 |
| 4184 void GLES2DecoderImpl::BeginDecoding() { | 4174 void GLES2DecoderImpl::BeginDecoding() { |
| 4185 gpu_tracer_->BeginDecoding(); | 4175 gpu_tracer_->BeginDecoding(); |
| 4186 gpu_trace_commands_ = gpu_tracer_->IsTracing() && *gpu_decoder_category_; | 4176 gpu_trace_commands_ = gpu_tracer_->IsTracing() && *gpu_decoder_category_; |
| 4187 gpu_debug_commands_ = log_commands() || debug() || gpu_trace_commands_; | 4177 gpu_debug_commands_ = log_commands() || debug() || gpu_trace_commands_; |
| 4188 query_manager_->ProcessFrameBeginUpdates(); | 4178 query_manager_->ProcessFrameBeginUpdates(); |
| 4189 } | 4179 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4265 state_.bound_pixel_unpack_buffer = nullptr; | 4255 state_.bound_pixel_unpack_buffer = nullptr; |
| 4266 state_.bound_transform_feedback_buffer = nullptr; | 4256 state_.bound_transform_feedback_buffer = nullptr; |
| 4267 state_.bound_uniform_buffer = nullptr; | 4257 state_.bound_uniform_buffer = nullptr; |
| 4268 framebuffer_state_.bound_read_framebuffer = nullptr; | 4258 framebuffer_state_.bound_read_framebuffer = nullptr; |
| 4269 framebuffer_state_.bound_draw_framebuffer = nullptr; | 4259 framebuffer_state_.bound_draw_framebuffer = nullptr; |
| 4270 state_.bound_renderbuffer = nullptr; | 4260 state_.bound_renderbuffer = nullptr; |
| 4271 state_.bound_transform_feedback = nullptr; | 4261 state_.bound_transform_feedback = nullptr; |
| 4272 state_.default_transform_feedback = nullptr; | 4262 state_.default_transform_feedback = nullptr; |
| 4273 state_.indexed_uniform_buffer_bindings = nullptr; | 4263 state_.indexed_uniform_buffer_bindings = nullptr; |
| 4274 | 4264 |
| 4275 if (offscreen_saved_color_texture_info_.get()) { | 4265 ReleaseAllBackTextures(have_context); |
| 4276 DCHECK(offscreen_saved_color_texture_); | |
| 4277 DCHECK_EQ(offscreen_saved_color_texture_info_->service_id(), | |
| 4278 offscreen_saved_color_texture_->id()); | |
| 4279 offscreen_saved_color_texture_->Invalidate(); | |
| 4280 offscreen_saved_color_texture_info_ = NULL; | |
| 4281 } | |
| 4282 ReleaseAllBackTextures(); | |
| 4283 if (have_context) { | 4266 if (have_context) { |
| 4284 if (apply_framebuffer_attachment_cmaa_intel_.get()) { | 4267 if (apply_framebuffer_attachment_cmaa_intel_.get()) { |
| 4285 apply_framebuffer_attachment_cmaa_intel_->Destroy(); | 4268 apply_framebuffer_attachment_cmaa_intel_->Destroy(); |
| 4286 apply_framebuffer_attachment_cmaa_intel_.reset(); | 4269 apply_framebuffer_attachment_cmaa_intel_.reset(); |
| 4287 } | 4270 } |
| 4288 | 4271 |
| 4289 if (copy_tex_image_blit_.get()) { | 4272 if (copy_tex_image_blit_.get()) { |
| 4290 copy_tex_image_blit_->Destroy(); | 4273 copy_tex_image_blit_->Destroy(); |
| 4291 copy_tex_image_blit_.reset(); | 4274 copy_tex_image_blit_.reset(); |
| 4292 } | 4275 } |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4439 context_->ReleaseCurrent(surface_.get()); | 4422 context_->ReleaseCurrent(surface_.get()); |
| 4440 surface_ = nullptr; | 4423 surface_ = nullptr; |
| 4441 } | 4424 } |
| 4442 | 4425 |
| 4443 void GLES2DecoderImpl::TakeFrontBuffer(const Mailbox& mailbox) { | 4426 void GLES2DecoderImpl::TakeFrontBuffer(const Mailbox& mailbox) { |
| 4444 if (!offscreen_saved_color_texture_.get()) { | 4427 if (!offscreen_saved_color_texture_.get()) { |
| 4445 DLOG(ERROR) << "Called TakeFrontBuffer on a non-offscreen context"; | 4428 DLOG(ERROR) << "Called TakeFrontBuffer on a non-offscreen context"; |
| 4446 return; | 4429 return; |
| 4447 } | 4430 } |
| 4448 | 4431 |
| 4449 if (!offscreen_saved_color_texture_info_.get()) { | |
| 4450 GLuint service_id = offscreen_saved_color_texture_->id(); | |
| 4451 offscreen_saved_color_texture_info_ = TextureRef::Create( | |
| 4452 texture_manager(), 0, service_id); | |
| 4453 texture_manager()->SetTarget(offscreen_saved_color_texture_info_.get(), | |
| 4454 GL_TEXTURE_2D); | |
| 4455 UpdateParentTextureInfo(); | |
| 4456 } | |
| 4457 | |
| 4458 mailbox_manager()->ProduceTexture( | 4432 mailbox_manager()->ProduceTexture( |
| 4459 mailbox, offscreen_saved_color_texture_info_->texture()); | 4433 mailbox, offscreen_saved_color_texture_->texture_ref()->texture()); |
| 4460 | 4434 |
| 4461 // Save the BackTexture and TextureRef. There's no need to update | 4435 // Save the BackTexture and TextureRef. There's no need to update |
| 4462 // |offscreen_saved_frame_buffer_| since CreateBackTexture() will take care of | 4436 // |offscreen_saved_frame_buffer_| since CreateBackTexture() will take care of |
| 4463 // that. | 4437 // that. |
| 4464 SavedBackTexture save; | 4438 SavedBackTexture save; |
| 4465 save.back_texture.swap(offscreen_saved_color_texture_); | 4439 save.back_texture.swap(offscreen_saved_color_texture_); |
| 4466 save.texture_ref = offscreen_saved_color_texture_info_; | |
| 4467 offscreen_saved_color_texture_info_ = nullptr; | |
| 4468 save.in_use = true; | 4440 save.in_use = true; |
| 4469 saved_back_textures_.push_back(std::move(save)); | 4441 saved_back_textures_.push_back(std::move(save)); |
| 4470 | 4442 |
| 4471 CreateBackTexture(); | 4443 CreateBackTexture(); |
| 4472 } | 4444 } |
| 4473 | 4445 |
| 4474 void GLES2DecoderImpl::ReturnFrontBuffer(const Mailbox& mailbox, bool is_lost) { | 4446 void GLES2DecoderImpl::ReturnFrontBuffer(const Mailbox& mailbox, bool is_lost) { |
| 4475 Texture* texture = mailbox_manager()->ConsumeTexture(mailbox); | 4447 Texture* texture = mailbox_manager()->ConsumeTexture(mailbox); |
| 4476 for (auto it = saved_back_textures_.begin(); it != saved_back_textures_.end(); | 4448 for (auto it = saved_back_textures_.begin(); it != saved_back_textures_.end(); |
| 4477 ++it) { | 4449 ++it) { |
| 4478 if (texture != it->texture_ref->texture()) | 4450 if (texture != it->back_texture->texture_ref()->texture()) |
| 4479 continue; | 4451 continue; |
| 4480 | 4452 |
| 4481 if (is_lost || it->back_texture->size() != offscreen_size_) { | 4453 if (is_lost || it->back_texture->size() != offscreen_size_) { |
| 4482 it->back_texture->Invalidate(); | 4454 it->back_texture->Invalidate(); |
| 4483 saved_back_textures_.erase(it); | 4455 saved_back_textures_.erase(it); |
| 4484 return; | 4456 return; |
| 4485 } | 4457 } |
| 4486 | 4458 |
| 4487 it->in_use = false; | 4459 it->in_use = false; |
| 4488 return; | 4460 return; |
| 4489 } | 4461 } |
| 4490 | 4462 |
| 4491 DLOG(ERROR) << "Attempting to return a frontbuffer that was not saved."; | 4463 DLOG(ERROR) << "Attempting to return a frontbuffer that was not saved."; |
| 4492 } | 4464 } |
| 4493 | 4465 |
| 4494 void GLES2DecoderImpl::CreateBackTexture() { | 4466 void GLES2DecoderImpl::CreateBackTexture() { |
| 4495 for (auto it = saved_back_textures_.begin(); it != saved_back_textures_.end(); | 4467 for (auto it = saved_back_textures_.begin(); it != saved_back_textures_.end(); |
| 4496 ++it) { | 4468 ++it) { |
| 4497 if (it->in_use) | 4469 if (it->in_use) |
| 4498 continue; | 4470 continue; |
| 4499 | 4471 |
| 4500 if (it->back_texture->size() != offscreen_size_) | 4472 if (it->back_texture->size() != offscreen_size_) |
| 4501 continue; | 4473 continue; |
| 4502 offscreen_saved_color_texture_ = std::move(it->back_texture); | 4474 offscreen_saved_color_texture_ = std::move(it->back_texture); |
| 4503 offscreen_saved_color_texture_info_ = it->texture_ref; | |
| 4504 offscreen_saved_frame_buffer_->AttachRenderTexture( | 4475 offscreen_saved_frame_buffer_->AttachRenderTexture( |
| 4505 offscreen_saved_color_texture_.get()); | 4476 offscreen_saved_color_texture_.get()); |
| 4506 saved_back_textures_.erase(it); | 4477 saved_back_textures_.erase(it); |
| 4507 return; | 4478 return; |
| 4508 } | 4479 } |
| 4509 | 4480 |
| 4510 ++create_back_texture_count_for_test_; | 4481 ++create_back_texture_count_for_test_; |
| 4511 offscreen_saved_color_texture_.reset( | 4482 offscreen_saved_color_texture_.reset(new BackTexture(this)); |
| 4512 new BackTexture(memory_tracker(), &state_)); | |
| 4513 offscreen_saved_color_texture_->Create(); | 4483 offscreen_saved_color_texture_->Create(); |
| 4514 offscreen_saved_color_texture_->AllocateStorage( | 4484 offscreen_saved_color_texture_->AllocateStorage( |
| 4515 offscreen_size_, offscreen_saved_color_format_, false); | 4485 offscreen_size_, offscreen_saved_color_format_, false); |
| 4516 offscreen_saved_frame_buffer_->AttachRenderTexture( | 4486 offscreen_saved_frame_buffer_->AttachRenderTexture( |
| 4517 offscreen_saved_color_texture_.get()); | 4487 offscreen_saved_color_texture_.get()); |
| 4518 } | 4488 } |
| 4519 | 4489 |
| 4520 void GLES2DecoderImpl::ReleaseNotInUseBackTextures() { | 4490 void GLES2DecoderImpl::ReleaseNotInUseBackTextures() { |
| 4521 for (auto& saved_back_texture : saved_back_textures_) { | 4491 for (auto& saved_back_texture : saved_back_textures_) { |
| 4522 if (!saved_back_texture.in_use) | 4492 if (!saved_back_texture.in_use) |
| 4523 saved_back_texture.back_texture->Invalidate(); | 4493 saved_back_texture.back_texture->Destroy(); |
| 4524 } | 4494 } |
| 4525 | |
| 4526 auto to_remove = | 4495 auto to_remove = |
| 4527 std::remove_if(saved_back_textures_.begin(), saved_back_textures_.end(), | 4496 std::remove_if(saved_back_textures_.begin(), saved_back_textures_.end(), |
| 4528 [](const SavedBackTexture& saved_back_texture) { | 4497 [](const SavedBackTexture& saved_back_texture) { |
| 4529 return !saved_back_texture.in_use; | 4498 return !saved_back_texture.in_use; |
| 4530 }); | 4499 }); |
| 4531 saved_back_textures_.erase(to_remove, saved_back_textures_.end()); | 4500 saved_back_textures_.erase(to_remove, saved_back_textures_.end()); |
| 4532 } | 4501 } |
| 4533 | 4502 |
| 4534 void GLES2DecoderImpl::ReleaseAllBackTextures() { | 4503 void GLES2DecoderImpl::ReleaseAllBackTextures(bool have_context) { |
| 4535 for (auto& saved_back_texture : saved_back_textures_) { | 4504 for (auto& saved_back_texture : saved_back_textures_) { |
| 4536 // The texture will be destroyed by texture_ref's destructor. | 4505 if (have_context) |
| 4537 DCHECK(saved_back_texture.texture_ref); | 4506 saved_back_texture.back_texture->Destroy(); |
| 4538 saved_back_texture.back_texture->Invalidate(); | 4507 else |
| 4508 saved_back_texture.back_texture->Invalidate(); |
| 4539 } | 4509 } |
| 4540 saved_back_textures_.clear(); | 4510 saved_back_textures_.clear(); |
| 4541 } | 4511 } |
| 4542 | 4512 |
| 4543 size_t GLES2DecoderImpl::GetSavedBackTextureCountForTest() { | 4513 size_t GLES2DecoderImpl::GetSavedBackTextureCountForTest() { |
| 4544 return saved_back_textures_.size(); | 4514 return saved_back_textures_.size(); |
| 4545 } | 4515 } |
| 4546 | 4516 |
| 4547 size_t GLES2DecoderImpl::GetCreatedBackTextureCountForTest() { | 4517 size_t GLES2DecoderImpl::GetCreatedBackTextureCountForTest() { |
| 4548 return create_back_texture_count_for_test_; | 4518 return create_back_texture_count_for_test_; |
| (...skipping 8881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13430 { | 13400 { |
| 13431 ScopedFrameBufferBinder binder(this, | 13401 ScopedFrameBufferBinder binder(this, |
| 13432 offscreen_saved_frame_buffer_->id()); | 13402 offscreen_saved_frame_buffer_->id()); |
| 13433 glClearColor(0, 0, 0, 0); | 13403 glClearColor(0, 0, 0, 0); |
| 13434 state_.SetDeviceColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); | 13404 state_.SetDeviceColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
| 13435 state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); | 13405 state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); |
| 13436 glClear(GL_COLOR_BUFFER_BIT); | 13406 glClear(GL_COLOR_BUFFER_BIT); |
| 13437 RestoreClearState(); | 13407 RestoreClearState(); |
| 13438 } | 13408 } |
| 13439 } | 13409 } |
| 13440 | |
| 13441 UpdateParentTextureInfo(); | |
| 13442 } | 13410 } |
| 13443 | 13411 |
| 13444 if (offscreen_size_.width() == 0 || offscreen_size_.height() == 0) | 13412 if (offscreen_size_.width() == 0 || offscreen_size_.height() == 0) |
| 13445 return; | 13413 return; |
| 13446 ScopedGLErrorSuppressor suppressor( | 13414 ScopedGLErrorSuppressor suppressor( |
| 13447 "GLES2DecoderImpl::DoSwapBuffers", GetErrorState()); | 13415 "GLES2DecoderImpl::DoSwapBuffers", GetErrorState()); |
| 13448 | 13416 |
| 13449 if (IsOffscreenBufferMultisampled()) { | 13417 if (IsOffscreenBufferMultisampled()) { |
| 13450 // For multisampled buffers, resolve the frame buffer. | 13418 // For multisampled buffers, resolve the frame buffer. |
| 13451 ScopedResolvedFrameBufferBinder binder(this, true, false); | 13419 ScopedResolvedFrameBufferBinder binder(this, true, false); |
| 13452 } else { | 13420 } else { |
| 13453 ScopedFrameBufferBinder binder(this, | 13421 ScopedFrameBufferBinder binder(this, |
| 13454 offscreen_target_frame_buffer_->id()); | 13422 offscreen_target_frame_buffer_->id()); |
| 13455 | 13423 |
| 13456 if (offscreen_target_buffer_preserved_) { | 13424 if (offscreen_target_buffer_preserved_) { |
| 13457 // Copy the target frame buffer to the saved offscreen texture. | 13425 // Copy the target frame buffer to the saved offscreen texture. |
| 13458 offscreen_saved_color_texture_->Copy( | 13426 offscreen_saved_color_texture_->Copy( |
| 13459 offscreen_saved_color_texture_->size(), | 13427 offscreen_saved_color_texture_->size(), |
| 13460 offscreen_saved_color_format_); | 13428 offscreen_saved_color_format_); |
| 13461 } else { | 13429 } else { |
| 13462 // Flip the textures in the parent context via the texture manager. | |
| 13463 if (!!offscreen_saved_color_texture_info_.get()) | |
| 13464 offscreen_saved_color_texture_info_->texture()-> | |
| 13465 SetServiceId(offscreen_target_color_texture_->id()); | |
| 13466 | |
| 13467 offscreen_saved_color_texture_.swap(offscreen_target_color_texture_); | 13430 offscreen_saved_color_texture_.swap(offscreen_target_color_texture_); |
| 13468 offscreen_target_frame_buffer_->AttachRenderTexture( | 13431 offscreen_target_frame_buffer_->AttachRenderTexture( |
| 13469 offscreen_target_color_texture_.get()); | 13432 offscreen_target_color_texture_.get()); |
| 13470 offscreen_saved_frame_buffer_->AttachRenderTexture( | 13433 offscreen_saved_frame_buffer_->AttachRenderTexture( |
| 13471 offscreen_saved_color_texture_.get()); | 13434 offscreen_saved_color_texture_.get()); |
| 13472 } | 13435 } |
| 13473 | 13436 |
| 13474 // Ensure the side effects of the copy are visible to the parent | 13437 // Ensure the side effects of the copy are visible to the parent |
| 13475 // context. There is no need to do this for ANGLE because it uses a | 13438 // context. There is no need to do this for ANGLE because it uses a |
| 13476 // single D3D device for all contexts. | 13439 // single D3D device for all contexts. |
| (...skipping 3537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17014 } | 16977 } |
| 17015 | 16978 |
| 17016 // Include the auto-generated part of this file. We split this because it means | 16979 // Include the auto-generated part of this file. We split this because it means |
| 17017 // we can easily edit the non-auto generated parts right here in this file | 16980 // we can easily edit the non-auto generated parts right here in this file |
| 17018 // instead of having to edit some template or the code generator. | 16981 // instead of having to edit some template or the code generator. |
| 17019 #include "base/macros.h" | 16982 #include "base/macros.h" |
| 17020 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 16983 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
| 17021 | 16984 |
| 17022 } // namespace gles2 | 16985 } // namespace gles2 |
| 17023 } // namespace gpu | 16986 } // namespace gpu |
| OLD | NEW |