OLD | NEW |
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 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 | 589 |
590 static sk_sp<SkImage> WrapTexture( | 590 static sk_sp<SkImage> WrapTexture( |
591 const ResourceProvider::ScopedReadLockGL& lock, | 591 const ResourceProvider::ScopedReadLockGL& lock, |
592 GrContext* context, | 592 GrContext* context, |
593 bool flip_texture) { | 593 bool flip_texture) { |
594 // Wrap a given texture in a Ganesh platform texture. | 594 // Wrap a given texture in a Ganesh platform texture. |
595 GrBackendTextureDesc backend_texture_description; | 595 GrBackendTextureDesc backend_texture_description; |
596 GrGLTextureInfo texture_info; | 596 GrGLTextureInfo texture_info; |
597 texture_info.fTarget = lock.target(); | 597 texture_info.fTarget = lock.target(); |
598 texture_info.fID = lock.texture_id(); | 598 texture_info.fID = lock.texture_id(); |
599 backend_texture_description.fWidth = lock.texture_size().width(); | 599 backend_texture_description.fWidth = lock.size().width(); |
600 backend_texture_description.fHeight = lock.texture_size().height(); | 600 backend_texture_description.fHeight = lock.size().height(); |
601 backend_texture_description.fConfig = kSkia8888_GrPixelConfig; | 601 backend_texture_description.fConfig = kSkia8888_GrPixelConfig; |
602 backend_texture_description.fTextureHandle = | 602 backend_texture_description.fTextureHandle = |
603 skia::GrGLTextureInfoToGrBackendObject(texture_info); | 603 skia::GrGLTextureInfoToGrBackendObject(texture_info); |
604 backend_texture_description.fOrigin = | 604 backend_texture_description.fOrigin = |
605 flip_texture ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin; | 605 flip_texture ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin; |
606 | 606 |
607 return SkImage::MakeFromTexture(context, backend_texture_description); | 607 return SkImage::MakeFromTexture(context, backend_texture_description); |
608 } | 608 } |
609 | 609 |
610 static sk_sp<SkImage> ApplyImageFilter( | 610 static sk_sp<SkImage> ApplyImageFilter( |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 | 824 |
825 std::unique_ptr<ScopedResource> GLRenderer::GetBackdropTexture( | 825 std::unique_ptr<ScopedResource> GLRenderer::GetBackdropTexture( |
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( |
835 device_background_texture->id()); | 835 resource_provider_, device_background_texture->id(), false); |
836 GetFramebufferTexture(lock.texture_id(), RGBA_8888, bounding_rect); | 836 GetFramebufferTexture(lock.texture_id(), RGBA_8888, 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) { |
(...skipping 1690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2536 draw_cache_.matrix_location = binding.matrix_location; | 2536 draw_cache_.matrix_location = binding.matrix_location; |
2537 draw_cache_.sampler_location = binding.sampler_location; | 2537 draw_cache_.sampler_location = binding.sampler_location; |
2538 } | 2538 } |
2539 | 2539 |
2540 // Generate the uv-transform | 2540 // Generate the uv-transform |
2541 Float4 uv_transform = {{0.0f, 0.0f, 1.0f, 1.0f}}; | 2541 Float4 uv_transform = {{0.0f, 0.0f, 1.0f, 1.0f}}; |
2542 if (!clip_region) | 2542 if (!clip_region) |
2543 uv_transform = UVTransform(quad); | 2543 uv_transform = UVTransform(quad); |
2544 if (sampler == SAMPLER_TYPE_2D_RECT) { | 2544 if (sampler == SAMPLER_TYPE_2D_RECT) { |
2545 // Un-normalize the texture coordiantes for rectangle targets. | 2545 // Un-normalize the texture coordiantes for rectangle targets. |
2546 gfx::Size texture_size = lock.texture_size(); | 2546 gfx::Size texture_size = lock.size(); |
2547 uv_transform.data[0] *= texture_size.width(); | 2547 uv_transform.data[0] *= texture_size.width(); |
2548 uv_transform.data[2] *= texture_size.width(); | 2548 uv_transform.data[2] *= texture_size.width(); |
2549 uv_transform.data[1] *= texture_size.height(); | 2549 uv_transform.data[1] *= texture_size.height(); |
2550 uv_transform.data[3] *= texture_size.height(); | 2550 uv_transform.data[3] *= texture_size.height(); |
2551 } | 2551 } |
2552 draw_cache_.uv_xform_data.push_back(uv_transform); | 2552 draw_cache_.uv_xform_data.push_back(uv_transform); |
2553 | 2553 |
2554 // Generate the vertex opacity | 2554 // Generate the vertex opacity |
2555 const float opacity = quad->shared_quad_state->opacity; | 2555 const float opacity = quad->shared_quad_state->opacity; |
2556 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[0] * opacity); | 2556 draw_cache_.vertex_opacity_data.push_back(quad->vertex_opacity[0] * opacity); |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2800 // |swapped_and_acked_overlay_resources_|, and then erases resources from | 2800 // |swapped_and_acked_overlay_resources_|, and then erases resources from |
2801 // |swapped_and_acked_overlay_resources_| that are no longer in use by the | 2801 // |swapped_and_acked_overlay_resources_| that are no longer in use by the |
2802 // Window Server. On other platforms, since resources are never in use by the | 2802 // Window Server. On other platforms, since resources are never in use by the |
2803 // Window Server, this is equivalent to just erasing all resources from the | 2803 // Window Server, this is equivalent to just erasing all resources from the |
2804 // first element of |swapping_overlay_resources_|. | 2804 // first element of |swapping_overlay_resources_|. |
2805 if (settings_->release_overlay_resources_on_swap_complete) { | 2805 if (settings_->release_overlay_resources_on_swap_complete) { |
2806 // Move resources known to be acked into | 2806 // Move resources known to be acked into |
2807 // |swapped_and_acked_overlay_resources_|. | 2807 // |swapped_and_acked_overlay_resources_|. |
2808 if (!swapping_overlay_resources_.empty()) { | 2808 if (!swapping_overlay_resources_.empty()) { |
2809 for (OverlayResourceLock& lock : swapping_overlay_resources_.front()) { | 2809 for (OverlayResourceLock& lock : swapping_overlay_resources_.front()) { |
2810 swapped_and_acked_overlay_resources_[lock->GetResourceId()] = | 2810 swapped_and_acked_overlay_resources_[lock->resource_id()] = |
2811 std::move(lock); | 2811 std::move(lock); |
2812 } | 2812 } |
2813 swapping_overlay_resources_.pop_front(); | 2813 swapping_overlay_resources_.pop_front(); |
2814 } | 2814 } |
2815 | 2815 |
2816 // Release resources that are no longer in use by the Window Server. | 2816 // Release resources that are no longer in use by the Window Server. |
2817 auto it = swapped_and_acked_overlay_resources_.begin(); | 2817 auto it = swapped_and_acked_overlay_resources_.begin(); |
2818 while (it != swapped_and_acked_overlay_resources_.end()) { | 2818 while (it != swapped_and_acked_overlay_resources_.end()) { |
2819 if (it->second->GetGpuMemoryBuffer() && | 2819 if (it->second->gpu_memory_buffer() && |
2820 it->second->GetGpuMemoryBuffer()->IsInUseByMacOSWindowServer()) { | 2820 it->second->gpu_memory_buffer()->IsInUseByMacOSWindowServer()) { |
2821 ++it; | 2821 ++it; |
2822 continue; | 2822 continue; |
2823 } | 2823 } |
2824 | 2824 |
2825 it = swapped_and_acked_overlay_resources_.erase(it); | 2825 it = swapped_and_acked_overlay_resources_.erase(it); |
2826 } | 2826 } |
2827 } | 2827 } |
2828 } | 2828 } |
2829 | 2829 |
2830 void GLRenderer::EnforceMemoryPolicy() { | 2830 void GLRenderer::EnforceMemoryPolicy() { |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3074 DCHECK(texture->id()); | 3074 DCHECK(texture->id()); |
3075 | 3075 |
3076 // Explicitly release lock, otherwise we can crash when try to lock | 3076 // Explicitly release lock, otherwise we can crash when try to lock |
3077 // same texture again. | 3077 // same texture again. |
3078 current_framebuffer_lock_ = nullptr; | 3078 current_framebuffer_lock_ = nullptr; |
3079 | 3079 |
3080 SetStencilEnabled(false); | 3080 SetStencilEnabled(false); |
3081 gl_->BindFramebuffer(GL_FRAMEBUFFER, offscreen_framebuffer_id_); | 3081 gl_->BindFramebuffer(GL_FRAMEBUFFER, offscreen_framebuffer_id_); |
3082 current_framebuffer_lock_ = | 3082 current_framebuffer_lock_ = |
3083 base::WrapUnique(new ResourceProvider::ScopedWriteLockGL( | 3083 base::WrapUnique(new ResourceProvider::ScopedWriteLockGL( |
3084 resource_provider_, texture->id())); | 3084 resource_provider_, texture->id(), false)); |
3085 unsigned texture_id = current_framebuffer_lock_->texture_id(); | 3085 unsigned texture_id = current_framebuffer_lock_->texture_id(); |
3086 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, | 3086 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, |
3087 texture_id, 0); | 3087 texture_id, 0); |
3088 | 3088 |
3089 DCHECK(gl_->CheckFramebufferStatus(GL_FRAMEBUFFER) == | 3089 DCHECK(gl_->CheckFramebufferStatus(GL_FRAMEBUFFER) == |
3090 GL_FRAMEBUFFER_COMPLETE || | 3090 GL_FRAMEBUFFER_COMPLETE || |
3091 IsContextLost()); | 3091 IsContextLost()); |
3092 return true; | 3092 return true; |
3093 } | 3093 } |
3094 | 3094 |
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3675 return gl_->GetGraphicsResetStatusKHR() != GL_NO_ERROR; | 3675 return gl_->GetGraphicsResetStatusKHR() != GL_NO_ERROR; |
3676 } | 3676 } |
3677 | 3677 |
3678 void GLRenderer::ScheduleCALayers(DrawingFrame* frame) { | 3678 void GLRenderer::ScheduleCALayers(DrawingFrame* frame) { |
3679 for (const CALayerOverlay& ca_layer_overlay : frame->ca_layer_overlay_list) { | 3679 for (const CALayerOverlay& ca_layer_overlay : frame->ca_layer_overlay_list) { |
3680 unsigned texture_id = 0; | 3680 unsigned texture_id = 0; |
3681 if (ca_layer_overlay.contents_resource_id) { | 3681 if (ca_layer_overlay.contents_resource_id) { |
3682 pending_overlay_resources_.push_back( | 3682 pending_overlay_resources_.push_back( |
3683 base::WrapUnique(new ResourceProvider::ScopedReadLockGpuMemoryBuffer( | 3683 base::WrapUnique(new ResourceProvider::ScopedReadLockGpuMemoryBuffer( |
3684 resource_provider_, ca_layer_overlay.contents_resource_id))); | 3684 resource_provider_, ca_layer_overlay.contents_resource_id))); |
3685 texture_id = pending_overlay_resources_.back()->GetTextureId(); | 3685 texture_id = pending_overlay_resources_.back()->texture_id(); |
3686 } | 3686 } |
3687 GLfloat contents_rect[4] = { | 3687 GLfloat contents_rect[4] = { |
3688 ca_layer_overlay.contents_rect.x(), ca_layer_overlay.contents_rect.y(), | 3688 ca_layer_overlay.contents_rect.x(), ca_layer_overlay.contents_rect.y(), |
3689 ca_layer_overlay.contents_rect.width(), | 3689 ca_layer_overlay.contents_rect.width(), |
3690 ca_layer_overlay.contents_rect.height(), | 3690 ca_layer_overlay.contents_rect.height(), |
3691 }; | 3691 }; |
3692 GLfloat bounds_rect[4] = { | 3692 GLfloat bounds_rect[4] = { |
3693 ca_layer_overlay.bounds_rect.x(), ca_layer_overlay.bounds_rect.y(), | 3693 ca_layer_overlay.bounds_rect.x(), ca_layer_overlay.bounds_rect.y(), |
3694 ca_layer_overlay.bounds_rect.width(), | 3694 ca_layer_overlay.bounds_rect.width(), |
3695 ca_layer_overlay.bounds_rect.height(), | 3695 ca_layer_overlay.bounds_rect.height(), |
(...skipping 22 matching lines...) Expand all Loading... |
3718 OverlayCandidateList& overlays = frame->overlay_list; | 3718 OverlayCandidateList& overlays = frame->overlay_list; |
3719 for (const OverlayCandidate& overlay : overlays) { | 3719 for (const OverlayCandidate& overlay : overlays) { |
3720 unsigned texture_id = 0; | 3720 unsigned texture_id = 0; |
3721 if (overlay.use_output_surface_for_resource) { | 3721 if (overlay.use_output_surface_for_resource) { |
3722 texture_id = output_surface_->GetOverlayTextureId(); | 3722 texture_id = output_surface_->GetOverlayTextureId(); |
3723 DCHECK(texture_id || IsContextLost()); | 3723 DCHECK(texture_id || IsContextLost()); |
3724 } else { | 3724 } else { |
3725 pending_overlay_resources_.push_back( | 3725 pending_overlay_resources_.push_back( |
3726 base::WrapUnique(new ResourceProvider::ScopedReadLockGpuMemoryBuffer( | 3726 base::WrapUnique(new ResourceProvider::ScopedReadLockGpuMemoryBuffer( |
3727 resource_provider_, overlay.resource_id))); | 3727 resource_provider_, overlay.resource_id))); |
3728 texture_id = pending_overlay_resources_.back()->GetTextureId(); | 3728 texture_id = pending_overlay_resources_.back()->texture_id(); |
3729 } | 3729 } |
3730 | 3730 |
3731 context_support_->ScheduleOverlayPlane( | 3731 context_support_->ScheduleOverlayPlane( |
3732 overlay.plane_z_order, overlay.transform, texture_id, | 3732 overlay.plane_z_order, overlay.transform, texture_id, |
3733 ToNearestRect(overlay.display_rect), overlay.uv_rect); | 3733 ToNearestRect(overlay.display_rect), overlay.uv_rect); |
3734 } | 3734 } |
3735 } | 3735 } |
3736 | 3736 |
3737 } // namespace cc | 3737 } // namespace cc |
OLD | NEW |