diff options
Diffstat (limited to 'chromium/components/viz/common')
25 files changed, 255 insertions, 40 deletions
diff --git a/chromium/components/viz/common/BUILD.gn b/chromium/components/viz/common/BUILD.gn index e98ecb33505..926d753ad76 100644 --- a/chromium/components/viz/common/BUILD.gn +++ b/chromium/components/viz/common/BUILD.gn @@ -19,6 +19,7 @@ viz_component("resource_format_utils") { sources = [ "resources/resource_format_utils.cc", "resources/resource_format_utils.h", + "resources/resource_format_utils_mac.mm", "resources/resource_sizes.h", "viz_resource_format_export.h", ] @@ -141,6 +142,7 @@ viz_component("common") { sources = [ "constants.cc", "constants.h", + "delegated_ink_metadata.h", "display/de_jelly.cc", "display/de_jelly.h", "display/overlay_strategy.cc", diff --git a/chromium/components/viz/common/DEPS b/chromium/components/viz/common/DEPS index 71bb14cbcb1..f40bbfd2a81 100644 --- a/chromium/components/viz/common/DEPS +++ b/chromium/components/viz/common/DEPS @@ -7,12 +7,12 @@ include_rules = [ # Exception is struct_traits.h which is used for defining friends only. "+mojo/public/cpp/bindings/struct_traits.h", "+third_party/perfetto/protos/perfetto/trace/track_event", + "+third_party/skia", ] specific_include_rules = { "skia_helper.(cc|h)": [ "+cc/base", - "+third_party/skia", ], # DEPS for GLHelper and friends which are in the root common/ directory. "(yuv_readback|gl_helper|gl_scaler).*\.(cc|h)": [ @@ -21,7 +21,6 @@ specific_include_rules = { "+gpu/command_buffer/common", "+gpu/command_buffer/service", "+gpu/ipc/common", - "+third_party/skia", ], ".*(_unittest|_pixeltest|test_util)\.cc": [ "+cc/test", @@ -29,7 +28,6 @@ specific_include_rules = { "+gpu/ipc/gl_in_process_context.h", "+gpu/ipc/test_gpu_thread_holder.h", "+media/base", - "+third_party/skia/include/core", "+ui/gl", ], ".*_benchmark\.cc": [ diff --git a/chromium/components/viz/common/delegated_ink_metadata.h b/chromium/components/viz/common/delegated_ink_metadata.h new file mode 100644 index 00000000000..3f0584444f0 --- /dev/null +++ b/chromium/components/viz/common/delegated_ink_metadata.h @@ -0,0 +1,62 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_VIZ_COMMON_DELEGATED_INK_METADATA_H_ +#define COMPONENTS_VIZ_COMMON_DELEGATED_INK_METADATA_H_ + +#include "base/time/time.h" +#include "components/viz/common/viz_common_export.h" +#include "third_party/skia/include/core/SkColor.h" +#include "ui/gfx/geometry/rect_f.h" + +namespace viz { + +// This class stores all the metadata that is gathered when the WebAPI +// updateInkTrailStartPoint is called. This metadata flows from blink, +// through cc, and into viz in order to produce a delegated ink trail on the +// end of what was already rendered. +// +// Explainer for the feature: +// https://github.com/WICG/ink-enhancement/blob/master/README.md +class VIZ_COMMON_EXPORT DelegatedInkMetadata { + public: + DelegatedInkMetadata() = default; + DelegatedInkMetadata(const gfx::PointF& pt, + double diameter, + SkColor color, + base::TimeTicks timestamp, + const gfx::RectF& area) + : point_(pt), + diameter_(diameter), + color_(color), + timestamp_(timestamp), + presentation_area_(area) {} + DelegatedInkMetadata(const DelegatedInkMetadata& other) = default; + + const gfx::PointF& point() const { return point_; } + double diameter() const { return diameter_; } + SkColor color() const { return color_; } + base::TimeTicks timestamp() const { return timestamp_; } + const gfx::RectF& presentation_area() const { return presentation_area_; } + + private: + // Location of the pointerevent relative to the root frame. + gfx::PointF point_; + + // Width of the trail, in physical pixels. + double diameter_ = 0; + + // Color to draw the ink trail. + SkColor color_ = 0; + + // Timestamp from the pointerevent for the ink point. + base::TimeTicks timestamp_; + + // The rect to clip the ink trail to, defaults to the containing viewport. + gfx::RectF presentation_area_; +}; + +} // namespace viz + +#endif // COMPONENTS_VIZ_COMMON_DELEGATED_INK_METADATA_H_ diff --git a/chromium/components/viz/common/features.cc b/chromium/components/viz/common/features.cc index 23722815a87..ba807b6597c 100644 --- a/chromium/components/viz/common/features.cc +++ b/chromium/components/viz/common/features.cc @@ -53,18 +53,24 @@ const base::Feature kVizForWebView{"VizForWebView", const base::Feature kVizFrameSubmissionForWebView{ "VizFrameSubmissionForWebView", base::FEATURE_DISABLED_BY_DEFAULT}; +const base::Feature kUsePreferredIntervalForVideo{ + "UsePreferredIntervalForVideo", base::FEATURE_DISABLED_BY_DEFAULT}; + // Whether we should use the real buffers corresponding to overlay candidates in // order to do a pageflip test rather than allocating test buffers. const base::Feature kUseRealBuffersForPageFlipTest{ "UseRealBuffersForPageFlipTest", base::FEATURE_DISABLED_BY_DEFAULT}; +#if defined(OS_FUCHSIA) +// Enables SkiaOutputDeviceBufferQueue instead of Vulkan swapchain on Fuchsia. +const base::Feature kUseSkiaOutputDeviceBufferQueue{ + "UseSkiaOutputDeviceBufferQueue", base::FEATURE_DISABLED_BY_DEFAULT}; +#endif + // Whether we should split partially occluded quads to reduce overdraw. const base::Feature kSplitPartiallyOccludedQuads{ "SplitPartiallyOccludedQuads", base::FEATURE_ENABLED_BY_DEFAULT}; -const base::Feature kUsePreferredIntervalForVideo{ - "UsePreferredIntervalForVideo", base::FEATURE_DISABLED_BY_DEFAULT}; - // Whether we should log extra debug information to webrtc native log. const base::Feature kWebRtcLogCapturePipeline{ "WebRtcLogCapturePipeline", base::FEATURE_DISABLED_BY_DEFAULT}; diff --git a/chromium/components/viz/common/features.h b/chromium/components/viz/common/features.h index 2a42f537bfd..1b077aa7ab7 100644 --- a/chromium/components/viz/common/features.h +++ b/chromium/components/viz/common/features.h @@ -24,6 +24,9 @@ VIZ_COMMON_EXPORT extern const base::Feature kVizForWebView; VIZ_COMMON_EXPORT extern const base::Feature kVizFrameSubmissionForWebView; VIZ_COMMON_EXPORT extern const base::Feature kUsePreferredIntervalForVideo; VIZ_COMMON_EXPORT extern const base::Feature kUseRealBuffersForPageFlipTest; +#if defined(OS_FUCHSIA) +VIZ_COMMON_EXPORT extern const base::Feature kUseSkiaOutputDeviceBufferQueue; +#endif VIZ_COMMON_EXPORT extern const base::Feature kSplitPartiallyOccludedQuads; VIZ_COMMON_EXPORT extern const base::Feature kWebRtcLogCapturePipeline; diff --git a/chromium/components/viz/common/frame_sinks/begin_frame_source.h b/chromium/components/viz/common/frame_sinks/begin_frame_source.h index 8be3ad72924..2ca5c252021 100644 --- a/chromium/components/viz/common/frame_sinks/begin_frame_source.h +++ b/chromium/components/viz/common/frame_sinks/begin_frame_source.h @@ -10,8 +10,8 @@ #include <string> +#include "base/check.h" #include "base/containers/flat_set.h" -#include "base/logging.h" #include "base/macros.h" #include "base/trace_event/trace_event.h" #include "build/build_config.h" diff --git a/chromium/components/viz/common/frame_sinks/copy_output_request.cc b/chromium/components/viz/common/frame_sinks/copy_output_request.cc index 1a10284b8af..ef836fb3a44 100644 --- a/chromium/components/viz/common/frame_sinks/copy_output_request.cc +++ b/chromium/components/viz/common/frame_sinks/copy_output_request.cc @@ -6,6 +6,8 @@ #include "base/bind.h" #include "base/check_op.h" +#include "base/task/task_traits.h" +#include "base/task/thread_pool.h" #include "base/trace_event/trace_event.h" #include "components/viz/common/frame_sinks/copy_output_result.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -53,20 +55,24 @@ void CopyOutputRequest::SetUniformScaleRatio(int scale_from, int scale_to) { } void CopyOutputRequest::SendResult(std::unique_ptr<CopyOutputResult> result) { - TRACE_EVENT_NESTABLE_ASYNC_END1("viz", "CopyOutputRequest", this, "success", - !result->IsEmpty()); - if (result_task_runner_) { - result_task_runner_->PostTask( - FROM_HERE, - base::BindOnce(std::move(result_callback_), std::move(result))); - result_task_runner_ = nullptr; - } else { - std::move(result_callback_).Run(std::move(result)); - } + TRACE_EVENT_NESTABLE_ASYNC_END2( + "viz", "CopyOutputRequest", this, "success", !result->IsEmpty(), + "has_provided_task_runner", !!result_task_runner_); + // Serializing the result requires an expensive copy, so to not block the + // any important thread we PostTask onto the threadpool by default, but if the + // user has provided a task runner use that instead. + auto runner = + result_task_runner_ + ? result_task_runner_ + : base::ThreadPool::CreateSequencedTaskRunner({base::MayBlock()}); + runner->PostTask(FROM_HERE, base::BindOnce(std::move(result_callback_), + std::move(result))); + // Remove the reference to the task runner (no-op if we didn't have one). + result_task_runner_ = nullptr; } bool CopyOutputRequest::SendsResultsInCurrentSequence() const { - return !result_task_runner_ || + return result_task_runner_ && result_task_runner_->RunsTasksInCurrentSequence(); } diff --git a/chromium/components/viz/common/gl_scaler_test_util.cc b/chromium/components/viz/common/gl_scaler_test_util.cc index 62560e8755a..9a1754e7492 100644 --- a/chromium/components/viz/common/gl_scaler_test_util.cc +++ b/chromium/components/viz/common/gl_scaler_test_util.cc @@ -9,6 +9,7 @@ #include "base/files/file_path.h" #include "base/logging.h" +#include "base/notreached.h" #include "base/path_service.h" #include "cc/test/pixel_test_utils.h" #include "components/viz/test/paths.h" diff --git a/chromium/components/viz/common/gpu/context_cache_controller_unittest.cc b/chromium/components/viz/common/gpu/context_cache_controller_unittest.cc index c380ea621e7..03696829f15 100644 --- a/chromium/components/viz/common/gpu/context_cache_controller_unittest.cc +++ b/chromium/components/viz/common/gpu/context_cache_controller_unittest.cc @@ -177,7 +177,7 @@ TEST(ContextCacheControllerTest, CheckSkiaResourcePurgeAPI) { SkPixmap pixmap(image_info, image_data.data(), image_info.minRowBytes()); auto image = SkImage::MakeRasterCopy(pixmap); auto image_gpu = image->makeTextureImage(gr_context); - gr_context->flush(); + gr_context->flushAndSubmit(); } // Ensure we see size taken up for the image (now released, but cached for diff --git a/chromium/components/viz/common/gpu/context_lost_reason.h b/chromium/components/viz/common/gpu/context_lost_reason.h index 823b5c5b822..9a4ea393e59 100644 --- a/chromium/components/viz/common/gpu/context_lost_reason.h +++ b/chromium/components/viz/common/gpu/context_lost_reason.h @@ -26,12 +26,14 @@ enum ContextLostReason { CONTEXT_LOST_OUT_OF_MEMORY = 10, CONTEXT_LOST_MAKECURRENT_FAILED = 11, CONTEXT_LOST_INVALID_GPU_MESSAGE = 12, - // SkiaRenderer marked context as lost because of failed Reshape call CONTEXT_LOST_RESHAPE_FAILED = 13, - // Update kMaxValue and //tools/metrics/histograms/histograms.xml when adding - // new values. - kMaxValue = CONTEXT_LOST_RESHAPE_FAILED + CONTEXT_LOST_SET_DRAW_RECTANGLE_FAILED = 14, + CONTEXT_LOST_DIRECT_COMPOSITION_OVERLAY_FAILED = 15, + CONTEXT_LOST_SWAP_FAILED = 16, + // Update kMaxValue here and <enum name="ContextLostReason"> in + // tools/metrics/histograms/enum.xml when adding new values. + kMaxValue = CONTEXT_LOST_SWAP_FAILED }; VIZ_COMMON_EXPORT ContextLostReason diff --git a/chromium/components/viz/common/gpu/metal_api_proxy.h b/chromium/components/viz/common/gpu/metal_api_proxy.h index 39c1a1a2a03..c32a55c3ea1 100644 --- a/chromium/components/viz/common/gpu/metal_api_proxy.h +++ b/chromium/components/viz/common/gpu/metal_api_proxy.h @@ -5,6 +5,9 @@ #ifndef COMPONENTS_VIZ_COMMON_GPU_METAL_API_PROXY_H_ #define COMPONENTS_VIZ_COMMON_GPU_METAL_API_PROXY_H_ +#include <memory> +#include <string> + #import <Metal/Metal.h> #include <os/availability.h> diff --git a/chromium/components/viz/common/gpu/metal_context_provider.mm b/chromium/components/viz/common/gpu/metal_context_provider.mm index f3d7e1d49f9..40e0c5c2390 100644 --- a/chromium/components/viz/common/gpu/metal_context_provider.mm +++ b/chromium/components/viz/common/gpu/metal_context_provider.mm @@ -7,6 +7,7 @@ #import <Metal/Metal.h> #include "base/bind.h" +#include "base/logging.h" #include "base/mac/scoped_nsobject.h" #include "base/memory/ref_counted.h" #include "base/metrics/histogram_macros.h" diff --git a/chromium/components/viz/common/gpu/vulkan_in_process_context_provider.cc b/chromium/components/viz/common/gpu/vulkan_in_process_context_provider.cc index 204fea1b374..4d098c579d1 100644 --- a/chromium/components/viz/common/gpu/vulkan_in_process_context_provider.cc +++ b/chromium/components/viz/common/gpu/vulkan_in_process_context_provider.cc @@ -4,6 +4,8 @@ #include "components/viz/common/gpu/vulkan_in_process_context_provider.h" +#include "base/task/thread_pool.h" +#include "base/task/thread_pool/thread_pool_instance.h" #include "gpu/vulkan/buildflags.h" #include "gpu/vulkan/init/gr_vk_memory_allocator_impl.h" #include "gpu/vulkan/vulkan_device_queue.h" @@ -12,9 +14,30 @@ #include "gpu/vulkan/vulkan_implementation.h" #include "gpu/vulkan/vulkan_instance.h" #include "gpu/vulkan/vulkan_util.h" +#include "third_party/skia/include/core/SkExecutor.h" #include "third_party/skia/include/gpu/GrContext.h" #include "third_party/skia/include/gpu/vk/GrVkExtensions.h" +namespace { + +class VizExecutor : public SkExecutor { + public: + VizExecutor() = default; + ~VizExecutor() override = default; + VizExecutor(const VizExecutor&) = delete; + VizExecutor& operator=(const VizExecutor&) = delete; + + // std::function is used by SkExecutor in //third_party/skia. nocheck + using Fn = std::function<void(void)>; // nocheck + // SkExecutor: + void add(Fn task) override { + base::ThreadPool::PostTask( + FROM_HERE, base::BindOnce([](Fn task) { task(); }, std::move(task))); + } +}; + +} // namespace + namespace viz { // static @@ -102,7 +125,16 @@ bool VulkanInProcessContextProvider::Initialize( vulkan_implementation_->enforce_protected_memory() ? GrProtected::kYes : GrProtected::kNo; - gr_context_ = GrContext::MakeVulkan(backend_context, context_options); + GrContextOptions options; + if (base::ThreadPoolInstance::Get()) { + // For some tests, ThreadPoolInstance is not initialized. VizExecutor will + // not be used for this case. + // TODO(penghuang): Make sure ThreadPoolInstance is initialized for related + // tests. + executor_ = std::make_unique<VizExecutor>(); + options.fExecutor = executor_.get(); + } + gr_context_ = GrContext::MakeVulkan(backend_context, options); return gr_context_ != nullptr; } @@ -122,6 +154,8 @@ void VulkanInProcessContextProvider::Destroy() { gr_context_.reset(); } + executor_.reset(); + if (device_queue_) { device_queue_->Destroy(); device_queue_.reset(); diff --git a/chromium/components/viz/common/gpu/vulkan_in_process_context_provider.h b/chromium/components/viz/common/gpu/vulkan_in_process_context_provider.h index 1215dff230d..05ea0a5c815 100644 --- a/chromium/components/viz/common/gpu/vulkan_in_process_context_provider.h +++ b/chromium/components/viz/common/gpu/vulkan_in_process_context_provider.h @@ -16,6 +16,8 @@ #include "third_party/skia/include/gpu/vk/GrVkBackendContext.h" #endif +class SkExecutor; + namespace gpu { class VulkanImplementation; class VulkanDeviceQueue; @@ -53,6 +55,7 @@ class VIZ_VULKAN_CONTEXT_PROVIDER_EXPORT VulkanInProcessContextProvider #if BUILDFLAG(ENABLE_VULKAN) sk_sp<GrContext> gr_context_; + std::unique_ptr<SkExecutor> executor_; gpu::VulkanImplementation* vulkan_implementation_; std::unique_ptr<gpu::VulkanDeviceQueue> device_queue_; #endif diff --git a/chromium/components/viz/common/quads/compositor_frame_metadata.cc b/chromium/components/viz/common/quads/compositor_frame_metadata.cc index 96c246eeb84..c9709eae9de 100644 --- a/chromium/components/viz/common/quads/compositor_frame_metadata.cc +++ b/chromium/components/viz/common/quads/compositor_frame_metadata.cc @@ -22,6 +22,32 @@ CompositorFrameMetadata CompositorFrameMetadata::Clone() const { } CompositorFrameMetadata::CompositorFrameMetadata( - const CompositorFrameMetadata& other) = default; + const CompositorFrameMetadata& other) + : device_scale_factor(other.device_scale_factor), + root_scroll_offset(other.root_scroll_offset), + page_scale_factor(other.page_scale_factor), + scrollable_viewport_size(other.scrollable_viewport_size), + content_color_usage(other.content_color_usage), + may_contain_video(other.may_contain_video), + is_resourceless_software_draw_with_scroll_or_animation( + other.is_resourceless_software_draw_with_scroll_or_animation), + root_background_color(other.root_background_color), + latency_info(other.latency_info), + referenced_surfaces(other.referenced_surfaces), + activation_dependencies(other.activation_dependencies), + deadline(other.deadline), + begin_frame_ack(other.begin_frame_ack), + frame_token(other.frame_token), + send_frame_token_to_embedder(other.send_frame_token_to_embedder), + min_page_scale_factor(other.min_page_scale_factor), + top_controls_visible_height(other.top_controls_visible_height), + local_surface_id_allocation_time(other.local_surface_id_allocation_time), + preferred_frame_interval(other.preferred_frame_interval), + display_transform_hint(other.display_transform_hint) { + if (other.delegated_ink_metadata) { + delegated_ink_metadata = std::make_unique<DelegatedInkMetadata>( + *other.delegated_ink_metadata.get()); + } +} } // namespace viz diff --git a/chromium/components/viz/common/quads/compositor_frame_metadata.h b/chromium/components/viz/common/quads/compositor_frame_metadata.h index de4513fe572..06b680d5de5 100644 --- a/chromium/components/viz/common/quads/compositor_frame_metadata.h +++ b/chromium/components/viz/common/quads/compositor_frame_metadata.h @@ -11,6 +11,7 @@ #include "base/optional.h" #include "base/time/time.h" #include "build/build_config.h" +#include "components/viz/common/delegated_ink_metadata.h" #include "components/viz/common/frame_sinks/begin_frame_args.h" #include "components/viz/common/quads/frame_deadline.h" #include "components/viz/common/surfaces/surface_id.h" @@ -152,6 +153,19 @@ class VIZ_COMMON_EXPORT CompositorFrameMetadata { // applicable to frames of the root surface. gfx::OverlayTransform display_transform_hint = gfx::OVERLAY_TRANSFORM_NONE; + // Contains the metadata required for drawing a delegated ink trail onto the + // end of a rendered ink stroke. This should only be present when two + // conditions are met: + // 1. The JS API |updateInkTrailStartPoint| is used - This gathers the + // metadata and puts it onto a compositor frame to be sent to viz. + // 2. This frame will not be submitted to the root surface - The browser UI + // does not use this, and the frame must be contained within a + // SurfaceDrawQuad. + // The ink trail created with this metadata will only last for a single frame + // before it disappears, regardless of whether or not the next frame contains + // delegated ink metadata. + std::unique_ptr<DelegatedInkMetadata> delegated_ink_metadata; + private: CompositorFrameMetadata(const CompositorFrameMetadata& other); CompositorFrameMetadata operator=(const CompositorFrameMetadata&) = delete; diff --git a/chromium/components/viz/common/quads/draw_quad.cc b/chromium/components/viz/common/quads/draw_quad.cc index a0b0255820d..7de9198ef27 100644 --- a/chromium/components/viz/common/quads/draw_quad.cc +++ b/chromium/components/viz/common/quads/draw_quad.cc @@ -27,7 +27,9 @@ void DrawQuad::SetAll(const SharedQuadState* shared_quad_state, const gfx::Rect& rect, const gfx::Rect& visible_rect, bool needs_blending) { - DCHECK(rect.Contains(visible_rect)) + // TODO(boliu): Temporarily making this a release check to catch + // crbug.com/1072407. + CHECK(rect.Contains(visible_rect)) << "rect: " << rect.ToString() << " visible_rect: " << visible_rect.ToString(); diff --git a/chromium/components/viz/common/quads/draw_quad_unittest.cc b/chromium/components/viz/common/quads/draw_quad_unittest.cc index 32e4828180d..4ddc34dde7d 100644 --- a/chromium/components/viz/common/quads/draw_quad_unittest.cc +++ b/chromium/components/viz/common/quads/draw_quad_unittest.cc @@ -11,6 +11,7 @@ #include "base/bind.h" #include "base/compiler_specific.h" +#include "base/logging.h" #include "base/unguessable_token.h" #include "cc/base/math_util.h" #include "cc/paint/filter_operations.h" diff --git a/chromium/components/viz/common/quads/render_pass.cc b/chromium/components/viz/common/quads/render_pass.cc index 2e08e454b64..9ff21584a2f 100644 --- a/chromium/components/viz/common/quads/render_pass.cc +++ b/chromium/components/viz/common/quads/render_pass.cc @@ -229,7 +229,9 @@ void RenderPass::SetNew(uint64_t id, const gfx::Rect& output_rect, const gfx::Rect& damage_rect, const gfx::Transform& transform_to_root_target) { - DCHECK(id); + // TODO(boliu): Temporarily making this a release check to catch + // crbug.com/1072407. + CHECK(id); DCHECK(damage_rect.IsEmpty() || output_rect.Contains(damage_rect)) << "damage_rect: " << damage_rect.ToString() << " output_rect: " << output_rect.ToString(); @@ -256,7 +258,9 @@ void RenderPass::SetAll( bool cache_render_pass, bool has_damage_from_contributing_content, bool generate_mipmap) { - DCHECK(id); + // TODO(boliu): Temporarily making this a release check to catch + // crbug.com/1072407. + CHECK(id); this->id = id; this->output_rect = output_rect; diff --git a/chromium/components/viz/common/resources/platform_color.h b/chromium/components/viz/common/resources/platform_color.h index 6e8790d0a06..3d573570d8c 100644 --- a/chromium/components/viz/common/resources/platform_color.h +++ b/chromium/components/viz/common/resources/platform_color.h @@ -5,8 +5,8 @@ #ifndef COMPONENTS_VIZ_COMMON_RESOURCES_PLATFORM_COLOR_H_ #define COMPONENTS_VIZ_COMMON_RESOURCES_PLATFORM_COLOR_H_ -#include "base/logging.h" #include "base/macros.h" +#include "base/notreached.h" #include "components/viz/common/resources/resource_format.h" #include "gpu/command_buffer/common/capabilities.h" #include "third_party/skia/include/core/SkTypes.h" diff --git a/chromium/components/viz/common/resources/resource_format_utils.cc b/chromium/components/viz/common/resources/resource_format_utils.cc index ea1ae8de815..2bfdfd5d2e4 100644 --- a/chromium/components/viz/common/resources/resource_format_utils.cc +++ b/chromium/components/viz/common/resources/resource_format_utils.cc @@ -4,6 +4,8 @@ #include "components/viz/common/resources/resource_format_utils.h" +#include <ostream> + #include "base/check_op.h" #include "base/notreached.h" #include "base/stl_util.h" @@ -324,10 +326,11 @@ unsigned int TextureStorageFormat(ResourceFormat format) { case RGBA_1010102: case BGRA_1010102: return GL_RGB10_A2_EXT; - case BGR_565: - case BGRX_8888: case YVU_420: case YUV_420_BIPLANAR: + return GL_RGB8_OES; + case BGR_565: + case BGRX_8888: case P010: break; } diff --git a/chromium/components/viz/common/resources/resource_format_utils.h b/chromium/components/viz/common/resources/resource_format_utils.h index ca10863b695..ce691952e0a 100644 --- a/chromium/components/viz/common/resources/resource_format_utils.h +++ b/chromium/components/viz/common/resources/resource_format_utils.h @@ -5,6 +5,7 @@ #ifndef COMPONENTS_VIZ_COMMON_RESOURCES_RESOURCE_FORMAT_UTILS_H_ #define COMPONENTS_VIZ_COMMON_RESOURCES_RESOURCE_FORMAT_UTILS_H_ +#include "build/build_config.h" #include "components/viz/common/resources/resource_format.h" #include "components/viz/common/viz_resource_format_export.h" #include "gpu/vulkan/buildflags.h" @@ -73,6 +74,10 @@ VIZ_RESOURCE_FORMAT_EXPORT wgpu::TextureFormat ToDawnFormat( VIZ_RESOURCE_FORMAT_EXPORT WGPUTextureFormat ToWGPUFormat(ResourceFormat format); +#if defined(OS_MACOSX) +VIZ_RESOURCE_FORMAT_EXPORT unsigned int ToMTLPixelFormat(ResourceFormat format); +#endif + } // namespace viz #endif // COMPONENTS_VIZ_COMMON_RESOURCES_RESOURCE_FORMAT_UTILS_H_ diff --git a/chromium/components/viz/common/resources/resource_format_utils_mac.mm b/chromium/components/viz/common/resources/resource_format_utils_mac.mm new file mode 100644 index 00000000000..5a095e7f30d --- /dev/null +++ b/chromium/components/viz/common/resources/resource_format_utils_mac.mm @@ -0,0 +1,40 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/viz/common/resources/resource_format_utils.h" + +#include <Metal/MTLPixelFormat.h> + +#include "base/logging.h" + +namespace viz { + +unsigned int ToMTLPixelFormat(ResourceFormat format) { + if (@available(macOS 10.11, *)) { + MTLPixelFormat mtl_pixel_format = MTLPixelFormatInvalid; + switch (format) { + case RED_8: + case ALPHA_8: + case LUMINANCE_8: + mtl_pixel_format = MTLPixelFormatR8Unorm; + break; + case RG_88: + mtl_pixel_format = MTLPixelFormatRG8Unorm; + break; + case RGBA_8888: + mtl_pixel_format = MTLPixelFormatRGBA8Unorm; + break; + case BGRA_8888: + mtl_pixel_format = MTLPixelFormatBGRA8Unorm; + break; + default: + DLOG(ERROR) << "Invalid Metal pixel format."; + break; + } + return static_cast<unsigned int>(mtl_pixel_format); + } + return 0; +} + +} // namespace viz diff --git a/chromium/components/viz/common/resources/resource_sizes.h b/chromium/components/viz/common/resources/resource_sizes.h index 9c4d9eee7b7..f2745793207 100644 --- a/chromium/components/viz/common/resources/resource_sizes.h +++ b/chromium/components/viz/common/resources/resource_sizes.h @@ -9,7 +9,7 @@ #include <limits> -#include "base/logging.h" +#include "base/check_op.h" #include "base/macros.h" #include "base/numerics/safe_math.h" #include "cc/base/math_util.h" diff --git a/chromium/components/viz/common/yuv_readback_unittest.cc b/chromium/components/viz/common/yuv_readback_unittest.cc index ab37ff6fd71..c1d7f1be9eb 100644 --- a/chromium/components/viz/common/yuv_readback_unittest.cc +++ b/chromium/components/viz/common/yuv_readback_unittest.cc @@ -102,16 +102,15 @@ class YUVReadbackTest : public testing::Test { run_loop.Run(); json_data.append("]"); - std::string error_msg; - std::unique_ptr<base::Value> trace_data = - base::JSONReader::ReadAndReturnErrorDeprecated(json_data, 0, nullptr, - &error_msg); - CHECK(trace_data) << "JSON parsing failed (" << error_msg - << ") JSON data:" << std::endl - << json_data; + base::JSONReader::ValueWithError parsed_json = + base::JSONReader::ReadAndReturnValueWithError(json_data); + CHECK(parsed_json.value) + << "JSON parsing failed (" << parsed_json.error_message + << ") JSON data:" << std::endl + << json_data; base::ListValue* list; - CHECK(trace_data->GetAsList(&list)); + CHECK(parsed_json.value->GetAsList(&list)); for (size_t i = 0; i < list->GetSize(); i++) { base::Value* item = nullptr; if (list->Get(i, &item)) { |