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

Side by Side Diff: cc/output/gl_renderer.cc

Issue 2089753003: cc: Use the correct internal format for glCopyTexImage2D calls. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: copytextureformat: comments 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
« no previous file with comments | « cc/output/gl_renderer.h ('k') | cc/output/gl_renderer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 The Chromium Authors. All rights reserved. 1 // Copyright 2010 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 "cc/output/gl_renderer.h" 5 #include "cc/output/gl_renderer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 const gfx::Rect& bounding_rect) { 826 const gfx::Rect& bounding_rect) {
827 std::unique_ptr<ScopedResource> device_background_texture = 827 std::unique_ptr<ScopedResource> device_background_texture =
828 ScopedResource::Create(resource_provider_); 828 ScopedResource::Create(resource_provider_);
829 // CopyTexImage2D fails when called on a texture having immutable storage. 829 // CopyTexImage2D fails when called on a texture having immutable storage.
830 device_background_texture->Allocate( 830 device_background_texture->Allocate(
831 bounding_rect.size(), ResourceProvider::TEXTURE_HINT_DEFAULT, 831 bounding_rect.size(), ResourceProvider::TEXTURE_HINT_DEFAULT,
832 resource_provider_->best_texture_format()); 832 resource_provider_->best_texture_format());
833 { 833 {
834 ResourceProvider::ScopedWriteLockGL lock(resource_provider_, 834 ResourceProvider::ScopedWriteLockGL lock(resource_provider_,
835 device_background_texture->id()); 835 device_background_texture->id());
836 GetFramebufferTexture(lock.texture_id(), RGBA_8888, bounding_rect); 836 GetFramebufferTexture(lock.texture_id(), bounding_rect);
837 } 837 }
838 return device_background_texture; 838 return device_background_texture;
839 } 839 }
840 840
841 sk_sp<SkImage> GLRenderer::ApplyBackgroundFilters( 841 sk_sp<SkImage> GLRenderer::ApplyBackgroundFilters(
842 DrawingFrame* frame, 842 DrawingFrame* frame,
843 const RenderPassDrawQuad* quad, 843 const RenderPassDrawQuad* quad,
844 ScopedResource* background_texture, 844 ScopedResource* background_texture,
845 const gfx::RectF& rect) { 845 const gfx::RectF& rect) {
846 DCHECK(ShouldApplyBackgroundFilters(quad)); 846 DCHECK(ShouldApplyBackgroundFilters(quad));
(...skipping 2015 matching lines...) Expand 10 before | Expand all | Expand 10 after
2862 request->texture_mailbox().target()); 2862 request->texture_mailbox().target());
2863 DCHECK(!mailbox.IsZero()); 2863 DCHECK(!mailbox.IsZero());
2864 const gpu::SyncToken& incoming_sync_token = 2864 const gpu::SyncToken& incoming_sync_token =
2865 request->texture_mailbox().sync_token(); 2865 request->texture_mailbox().sync_token();
2866 if (incoming_sync_token.HasData()) 2866 if (incoming_sync_token.HasData())
2867 gl_->WaitSyncTokenCHROMIUM(incoming_sync_token.GetConstData()); 2867 gl_->WaitSyncTokenCHROMIUM(incoming_sync_token.GetConstData());
2868 2868
2869 texture_id = 2869 texture_id =
2870 gl_->CreateAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); 2870 gl_->CreateAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
2871 } 2871 }
2872 GetFramebufferTexture(texture_id, RGBA_8888, window_rect); 2872 GetFramebufferTexture(texture_id, window_rect);
2873 2873
2874 const GLuint64 fence_sync = gl_->InsertFenceSyncCHROMIUM(); 2874 const GLuint64 fence_sync = gl_->InsertFenceSyncCHROMIUM();
2875 gl_->ShallowFlushCHROMIUM(); 2875 gl_->ShallowFlushCHROMIUM();
2876 2876
2877 gpu::SyncToken sync_token; 2877 gpu::SyncToken sync_token;
2878 gl_->GenSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); 2878 gl_->GenSyncTokenCHROMIUM(fence_sync, sync_token.GetData());
2879 2879
2880 TextureMailbox texture_mailbox(mailbox, sync_token, GL_TEXTURE_2D); 2880 TextureMailbox texture_mailbox(mailbox, sync_token, GL_TEXTURE_2D);
2881 2881
2882 std::unique_ptr<SingleReleaseCallback> release_callback; 2882 std::unique_ptr<SingleReleaseCallback> release_callback;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
3002 current_read->copy_request->SendBitmapResult(std::move(bitmap)); 3002 current_read->copy_request->SendBitmapResult(std::move(bitmap));
3003 3003
3004 // Conversion from reverse iterator to iterator: 3004 // Conversion from reverse iterator to iterator:
3005 // Iterator |iter.base() - 1| points to the same element with reverse iterator 3005 // Iterator |iter.base() - 1| points to the same element with reverse iterator
3006 // |iter|. The difference |-1| is due to the fact of correspondence of end() 3006 // |iter|. The difference |-1| is due to the fact of correspondence of end()
3007 // with rbegin(). 3007 // with rbegin().
3008 pending_async_read_pixels_.erase(iter.base() - 1); 3008 pending_async_read_pixels_.erase(iter.base() - 1);
3009 } 3009 }
3010 3010
3011 void GLRenderer::GetFramebufferTexture(unsigned texture_id, 3011 void GLRenderer::GetFramebufferTexture(unsigned texture_id,
3012 ResourceFormat texture_format,
3013 const gfx::Rect& window_rect) { 3012 const gfx::Rect& window_rect) {
3014 DCHECK(texture_id); 3013 DCHECK(texture_id);
3015 DCHECK_GE(window_rect.x(), 0); 3014 DCHECK_GE(window_rect.x(), 0);
3016 DCHECK_GE(window_rect.y(), 0); 3015 DCHECK_GE(window_rect.y(), 0);
3017 DCHECK_LE(window_rect.right(), current_surface_size_.width()); 3016 DCHECK_LE(window_rect.right(), current_surface_size_.width());
3018 DCHECK_LE(window_rect.bottom(), current_surface_size_.height()); 3017 DCHECK_LE(window_rect.bottom(), current_surface_size_.height());
3019 3018
3019 // If copying a non-root renderpass then use the format of the bound
3020 // texture. Otherwise, we use the format of the default framebuffer.
3021 GLenum format = current_framebuffer_lock_
3022 ? GLCopyTextureInternalFormat(current_framebuffer_format_)
3023 : output_surface_->GetFramebufferCopyTextureFormat();
3024 // Verify the format is valid for GLES2's glCopyTexImage2D.
3025 DCHECK(format == GL_ALPHA || format == GL_LUMINANCE ||
3026 format == GL_LUMINANCE_ALPHA || format == GL_RGB || format == GL_RGBA)
3027 << format;
3028
3020 gl_->BindTexture(GL_TEXTURE_2D, texture_id); 3029 gl_->BindTexture(GL_TEXTURE_2D, texture_id);
3021 gl_->CopyTexImage2D(GL_TEXTURE_2D, 0, GLDataFormat(texture_format), 3030 gl_->CopyTexImage2D(GL_TEXTURE_2D, 0, format, window_rect.x(),
3022 window_rect.x(), window_rect.y(), window_rect.width(), 3031 window_rect.y(), window_rect.width(),
3023 window_rect.height(), 0); 3032 window_rect.height(), 0);
3024 gl_->BindTexture(GL_TEXTURE_2D, 0); 3033 gl_->BindTexture(GL_TEXTURE_2D, 0);
3025 } 3034 }
3026 3035
3027 void GLRenderer::BindFramebufferToOutputSurface(DrawingFrame* frame) { 3036 void GLRenderer::BindFramebufferToOutputSurface(DrawingFrame* frame) {
3028 current_framebuffer_lock_ = nullptr; 3037 current_framebuffer_lock_ = nullptr;
3029 output_surface_->BindFramebuffer(); 3038 output_surface_->BindFramebuffer();
3030 3039
3031 if (output_surface_->HasExternalStencilTest()) { 3040 if (output_surface_->HasExternalStencilTest()) {
3032 output_surface_->ApplyExternalStencil(); 3041 output_surface_->ApplyExternalStencil();
3033 SetStencilEnabled(true); 3042 SetStencilEnabled(true);
3034 } else { 3043 } else {
3035 SetStencilEnabled(false); 3044 SetStencilEnabled(false);
3036 } 3045 }
3037 } 3046 }
3038 3047
3039 bool GLRenderer::BindFramebufferToTexture(DrawingFrame* frame, 3048 bool GLRenderer::BindFramebufferToTexture(DrawingFrame* frame,
3040 const ScopedResource* texture) { 3049 const ScopedResource* texture) {
3041 DCHECK(texture->id()); 3050 DCHECK(texture->id());
3042 3051
3043 // Explicitly release lock, otherwise we can crash when try to lock 3052 // Explicitly release lock, otherwise we can crash when try to lock
3044 // same texture again. 3053 // same texture again.
3045 current_framebuffer_lock_ = nullptr; 3054 current_framebuffer_lock_ = nullptr;
3046 3055
3047 SetStencilEnabled(false); 3056 SetStencilEnabled(false);
3048 gl_->BindFramebuffer(GL_FRAMEBUFFER, offscreen_framebuffer_id_); 3057 gl_->BindFramebuffer(GL_FRAMEBUFFER, offscreen_framebuffer_id_);
3049 current_framebuffer_lock_ = 3058 current_framebuffer_lock_ =
3050 base::WrapUnique(new ResourceProvider::ScopedWriteLockGL( 3059 base::WrapUnique(new ResourceProvider::ScopedWriteLockGL(
3051 resource_provider_, texture->id())); 3060 resource_provider_, texture->id()));
3061 current_framebuffer_format_ = texture->format();
3052 unsigned texture_id = current_framebuffer_lock_->texture_id(); 3062 unsigned texture_id = current_framebuffer_lock_->texture_id();
3053 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 3063 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
3054 texture_id, 0); 3064 texture_id, 0);
3055 3065
3056 DCHECK(gl_->CheckFramebufferStatus(GL_FRAMEBUFFER) == 3066 DCHECK(gl_->CheckFramebufferStatus(GL_FRAMEBUFFER) ==
3057 GL_FRAMEBUFFER_COMPLETE || 3067 GL_FRAMEBUFFER_COMPLETE ||
3058 IsContextLost()); 3068 IsContextLost());
3059 return true; 3069 return true;
3060 } 3070 }
3061 3071
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
3669 texture_id = pending_overlay_resources_.back()->texture_id(); 3679 texture_id = pending_overlay_resources_.back()->texture_id();
3670 } 3680 }
3671 3681
3672 context_support_->ScheduleOverlayPlane( 3682 context_support_->ScheduleOverlayPlane(
3673 overlay.plane_z_order, overlay.transform, texture_id, 3683 overlay.plane_z_order, overlay.transform, texture_id,
3674 ToNearestRect(overlay.display_rect), overlay.uv_rect); 3684 ToNearestRect(overlay.display_rect), overlay.uv_rect);
3675 } 3685 }
3676 } 3686 }
3677 3687
3678 } // namespace cc 3688 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/gl_renderer.h ('k') | cc/output/gl_renderer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698