Commit 80dee2b3 authored by Christopher Cameron's avatar Christopher Cameron Committed by Commit Bot

Add IOSurfaceSet/GetHDRMetadata

This adds a side-channel through which a gfx::HDRMetadata can be
attached to an IOSurface. In practice this can be written
by the software decoder in the renderer process and read by the
compositor in the GPU process.

Bug: 1101041
Change-Id: I36a8f0cc8562fe1daa2e3e4c131aa7f305644aa5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2531655
Commit-Queue: ccameron <ccameron@chromium.org>
Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827187}
parent 9ae1ae37
......@@ -660,6 +660,27 @@ static_library("test_support") {
}
}
if (is_mac) {
component("gfx_io_surface_hdr_metadata") {
sources = [
"mac/io_surface_hdr_metadata.cc",
"mac/io_surface_hdr_metadata.h",
]
defines = [ "IS_GFX_IO_SURFACE_HDR_METADATA_IMPL" ]
# This is a separate component from the other sources because it depends on
# the mojo serialize and deserialize methods.
deps = [
":gfx",
"//ui/gfx/mojom:mojom",
]
frameworks = [
"CoreFoundation.framework",
"IOSurface.framework",
]
}
}
test("gfx_unittests") {
sources = [
"font_names_testing.cc",
......@@ -684,6 +705,7 @@ test("gfx_unittests") {
"font_fallback_mac_unittest.cc",
"image/image_mac_unittest.mm",
"mac/coordinate_conversion_unittest.mm",
"mac/io_surface_unittest.cc",
"path_mac_unittest.mm",
"platform_font_mac_unittest.mm",
"range/range_mac_unittest.mm",
......@@ -798,6 +820,10 @@ test("gfx_unittests") {
deps += [ "//ui/resources:ui_test_pak_bundle_data" ]
}
if (is_mac) {
deps += [ ":gfx_io_surface_hdr_metadata" ]
}
if (!is_apple) {
sources += [
"interpolated_transform_unittest.cc",
......
// 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 "ui/gfx/mac/io_surface_hdr_metadata.h"
#include "base/mac/foundation_util.h"
#include "base/mac/scoped_cftyperef.h"
#include "ui/gfx/mojom/hdr_metadata.mojom.h"
namespace gfx {
namespace {
// The key under which HDR metadata is attached to an IOSurface.
const CFStringRef kCrIOSurfaceHDRMetadataKey =
CFSTR("CrIOSurfaceHDRMetadataKey");
} // namespace
void IOSurfaceSetHDRMetadata(IOSurfaceRef io_surface,
gfx::HDRMetadata hdr_metadata) {
std::vector<uint8_t> std_data =
gfx::mojom::HDRMetadata::Serialize(&hdr_metadata);
base::ScopedCFTypeRef<CFDataRef> cf_data(
CFDataCreate(nullptr, std_data.data(), std_data.size()));
IOSurfaceSetValue(io_surface, kCrIOSurfaceHDRMetadataKey, cf_data);
}
bool IOSurfaceGetHDRMetadata(IOSurfaceRef io_surface,
gfx::HDRMetadata& hdr_metadata) {
base::ScopedCFTypeRef<CFTypeRef> cf_untyped(
IOSurfaceCopyValue(io_surface, kCrIOSurfaceHDRMetadataKey));
CFDataRef cf_data = base::mac::CFCast<CFDataRef>(cf_untyped);
if (!cf_data)
return false;
const UInt8* raw_data = CFDataGetBytePtr(cf_data);
std::vector<uint8_t> std_data(raw_data, raw_data + CFDataGetLength(cf_data));
return gfx::mojom::HDRMetadata::Deserialize(std_data, &hdr_metadata);
}
} // namespace gfx
// 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 UI_GFX_MAC_IO_SURFACE_HDR_METADATA_H_
#define UI_GFX_MAC_IO_SURFACE_HDR_METADATA_H_
#include <IOSurface/IOSurface.h>
#include "base/component_export.h"
namespace gfx {
struct HDRMetadata;
// Attach |hdr_metadata| to |io_surface|. After this is called, any other
// process that has opened |io_surface| will be able to read |hdr_metadata|
// using the function IOSurfaceGetHDRMetadata.
void COMPONENT_EXPORT(GFX_IO_SURFACE_HDR_METADATA)
IOSurfaceSetHDRMetadata(IOSurfaceRef io_surface,
gfx::HDRMetadata hdr_metadata);
// Retrieve in |hdr_metadata| the value that was attached to |io_surface|. This
// will return false on failure.
bool COMPONENT_EXPORT(GFX_IO_SURFACE_HDR_METADATA)
IOSurfaceGetHDRMetadata(IOSurfaceRef io_surface,
gfx::HDRMetadata& hdr_metadata);
} // namespace gfx
#endif // UI_GFX_MAC_IO_SURFACE_HDR_METADATA_H_
// 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 "ui/gfx/mac/io_surface.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/hdr_metadata.h"
#include "ui/gfx/mac/io_surface_hdr_metadata.h"
namespace gfx {
namespace {
// Check that empty NSBezierPath is returned for empty SkPath.
TEST(IOSurface, HDRMetadata) {
gfx::HDRMetadata in;
in.mastering_metadata.primary_r = PointF(1.0, 2.0);
in.mastering_metadata.primary_g = PointF(4.0, 5.0);
in.mastering_metadata.primary_b = PointF(7.0, 8.0);
in.mastering_metadata.white_point = PointF(10.0, 11.0);
in.mastering_metadata.luminance_max = 13;
in.mastering_metadata.luminance_min = 14;
in.max_content_light_level = 15;
in.max_frame_average_light_level = 16;
base::ScopedCFTypeRef<IOSurfaceRef> io_surface(
CreateIOSurface(gfx::Size(100, 100), gfx::BufferFormat::BGRA_8888));
gfx::HDRMetadata out;
EXPECT_FALSE(IOSurfaceGetHDRMetadata(io_surface, out));
IOSurfaceSetHDRMetadata(io_surface, in);
EXPECT_TRUE(IOSurfaceGetHDRMetadata(io_surface, out));
EXPECT_EQ(in, out);
}
} // namespace
} // namespace gfx
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment