From 211fb8b5e6d4a167d28f28774070e10b845951bf Mon Sep 17 00:00:00 2001 From: Robert Kroeger Date: Tue, 18 Jul 2017 00:18:13 +0000 Subject: [PATCH] mojo struct_traits for ozone OverlaySurfaceCandidate Add struct_traits for OverlaySurfaceCandidate to enable mojo IPC in ozone. BUG=620927 Change-Id: I16a6058f6ef411ab7acfeedc8ba35d080baed674 Reviewed-on: https://chromium-review.googlesource.com/571980 Commit-Queue: Robert Kroeger Reviewed-by: Sadrul Chowdhury Reviewed-by: Daniel Nicoara Reviewed-by: Yuzhu Shen Reviewed-by: Tom Sepez Cr-Commit-Position: refs/heads/master@{#487315} --- .../chromium_bindings_configuration.gni | 1 + ui/gfx/BUILD.gn | 1 + ui/gfx/mojo/BUILD.gn | 1 + ui/gfx/mojo/overlay_transform.mojom | 17 ++++ ui/gfx/mojo/overlay_transform.typemap | 11 +++ ui/gfx/mojo/overlay_transform_struct_traits.h | 68 ++++++++++++++++ ui/gfx/typemaps.gni | 1 + ui/ozone/BUILD.gn | 14 ++-- ui/ozone/DEPS | 5 ++ .../common/gpu/ozone_gpu_message_params.cc | 12 ++- .../common/gpu/ozone_gpu_message_params.h | 4 +- ui/ozone/demo/surfaceless_gl_renderer.cc | 2 +- .../platform/drm/host/drm_overlay_manager.cc | 6 +- .../platform/drm/host/drm_overlay_manager.h | 6 +- ui/ozone/public/interfaces/BUILD.gn | 35 ++++++-- ui/ozone/public/interfaces/DEPS | 3 + ui/ozone/public/interfaces/OWNERS | 4 + .../overlay_surface_candidate.mojom | 37 +++++++++ .../overlay_surface_candidate.typemap | 13 +++ .../overlay_surface_candidate_struct_traits.h | 80 +++++++++++++++++++ ...urface_candidate_struct_traits_unittest.cc | 73 +++++++++++++++++ ui/ozone/public/interfaces/typemaps.gni | 5 ++ ui/ozone/public/overlay_candidates_ozone.cc | 12 +-- ui/ozone/public/overlay_candidates_ozone.h | 38 +-------- ui/ozone/public/overlay_surface_candidate.cc | 16 ++++ ui/ozone/public/overlay_surface_candidate.h | 52 ++++++++++++ ui/ozone/run_all_unittests.cc | 46 ----------- 27 files changed, 442 insertions(+), 121 deletions(-) create mode 100644 ui/gfx/mojo/overlay_transform.mojom create mode 100644 ui/gfx/mojo/overlay_transform.typemap create mode 100644 ui/gfx/mojo/overlay_transform_struct_traits.h create mode 100644 ui/ozone/public/interfaces/DEPS create mode 100644 ui/ozone/public/interfaces/overlay_surface_candidate.mojom create mode 100644 ui/ozone/public/interfaces/overlay_surface_candidate.typemap create mode 100644 ui/ozone/public/interfaces/overlay_surface_candidate_struct_traits.h create mode 100644 ui/ozone/public/interfaces/overlay_surface_candidate_struct_traits_unittest.cc create mode 100644 ui/ozone/public/interfaces/typemaps.gni create mode 100644 ui/ozone/public/overlay_surface_candidate.cc create mode 100644 ui/ozone/public/overlay_surface_candidate.h delete mode 100644 ui/ozone/run_all_unittests.cc diff --git a/mojo/public/tools/bindings/chromium_bindings_configuration.gni b/mojo/public/tools/bindings/chromium_bindings_configuration.gni index 42b107dcc8a69c..cd8f0f8f89f19b 100644 --- a/mojo/public/tools/bindings/chromium_bindings_configuration.gni +++ b/mojo/public/tools/bindings/chromium_bindings_configuration.gni @@ -43,6 +43,7 @@ _typemap_imports = [ "//ui/events/mojo/typemaps.gni", "//ui/gfx/typemaps.gni", "//ui/latency/mojo/typemaps.gni", + "//ui/ozone/public/interfaces/typemaps.gni", "//ui/message_center/mojo/typemaps.gni", "//url/mojo/typemaps.gni", ] diff --git a/ui/gfx/BUILD.gn b/ui/gfx/BUILD.gn index e369ae8339f268..e579efd759a21b 100644 --- a/ui/gfx/BUILD.gn +++ b/ui/gfx/BUILD.gn @@ -522,6 +522,7 @@ source_set("memory_buffer_sources") { "native_pixmap.h", "native_pixmap_handle.cc", "native_pixmap_handle.h", + "overlay_transform.h", ] if (!is_ios) { diff --git a/ui/gfx/mojo/BUILD.gn b/ui/gfx/mojo/BUILD.gn index 7a90efbd9c118c..9722968cbd9e37 100644 --- a/ui/gfx/mojo/BUILD.gn +++ b/ui/gfx/mojo/BUILD.gn @@ -10,6 +10,7 @@ mojom("mojo") { "buffer_types.mojom", "color_space.mojom", "icc_profile.mojom", + "overlay_transform.mojom", "selection_bound.mojom", "transform.mojom", ] diff --git a/ui/gfx/mojo/overlay_transform.mojom b/ui/gfx/mojo/overlay_transform.mojom new file mode 100644 index 00000000000000..af64e3629a1fc0 --- /dev/null +++ b/ui/gfx/mojo/overlay_transform.mojom @@ -0,0 +1,17 @@ +// Copyright 2017 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. + +module gfx.mojom; + +// gfx::OverlayTransform +enum OverlayTransform { + OVERLAY_TRANSFORM_INVALID, + OVERLAY_TRANSFORM_NONE, + OVERLAY_TRANSFORM_FLIP_HORIZONTAL, + OVERLAY_TRANSFORM_FLIP_VERTICAL, + OVERLAY_TRANSFORM_ROTATE_90, + OVERLAY_TRANSFORM_ROTATE_180, + OVERLAY_TRANSFORM_ROTATE_270, + OVERLAY_TRANSFORM_LAST = OVERLAY_TRANSFORM_ROTATE_270 +}; diff --git a/ui/gfx/mojo/overlay_transform.typemap b/ui/gfx/mojo/overlay_transform.typemap new file mode 100644 index 00000000000000..8dd9e1b967bb0a --- /dev/null +++ b/ui/gfx/mojo/overlay_transform.typemap @@ -0,0 +1,11 @@ +# Copyright 2017 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. + +mojom = "//ui/gfx/mojo/overlay_transform.mojom" +public_headers = [ "//ui/gfx/overlay_transform.h" ] +traits_headers = [ "//ui/gfx/mojo/overlay_transform_struct_traits.h" ] +public_deps = [ + "//ui/gfx", +] +type_mappings = [ "gfx.mojom.OverlayTransform=gfx::OverlayTransform" ] diff --git a/ui/gfx/mojo/overlay_transform_struct_traits.h b/ui/gfx/mojo/overlay_transform_struct_traits.h new file mode 100644 index 00000000000000..e26f2db4598c3a --- /dev/null +++ b/ui/gfx/mojo/overlay_transform_struct_traits.h @@ -0,0 +1,68 @@ +// Copyright 2017 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_MOJO_OVERLAY_TRANSFORM_STRUCT_TRAITS_H_ +#define UI_GFX_MOJO_OVERLAY_TRANSFORM_STRUCT_TRAITS_H_ + +#include "ui/gfx/mojo/overlay_transform.mojom.h" +#include "ui/gfx/overlay_transform.h" + +namespace mojo { + +template <> +struct EnumTraits { + static gfx::mojom::OverlayTransform ToMojom(gfx::OverlayTransform format) { + switch (format) { + case gfx::OverlayTransform::OVERLAY_TRANSFORM_INVALID: + return gfx::mojom::OverlayTransform::OVERLAY_TRANSFORM_INVALID; + case gfx::OverlayTransform::OVERLAY_TRANSFORM_NONE: + return gfx::mojom::OverlayTransform::OVERLAY_TRANSFORM_NONE; + case gfx::OverlayTransform::OVERLAY_TRANSFORM_FLIP_HORIZONTAL: + return gfx::mojom::OverlayTransform::OVERLAY_TRANSFORM_FLIP_HORIZONTAL; + case gfx::OverlayTransform::OVERLAY_TRANSFORM_FLIP_VERTICAL: + return gfx::mojom::OverlayTransform::OVERLAY_TRANSFORM_FLIP_VERTICAL; + case gfx::OverlayTransform::OVERLAY_TRANSFORM_ROTATE_90: + return gfx::mojom::OverlayTransform::OVERLAY_TRANSFORM_ROTATE_90; + case gfx::OverlayTransform::OVERLAY_TRANSFORM_ROTATE_180: + return gfx::mojom::OverlayTransform::OVERLAY_TRANSFORM_ROTATE_180; + case gfx::OverlayTransform::OVERLAY_TRANSFORM_ROTATE_270: + return gfx::mojom::OverlayTransform::OVERLAY_TRANSFORM_ROTATE_270; + } + NOTREACHED(); + return gfx::mojom::OverlayTransform::OVERLAY_TRANSFORM_INVALID; + } + + static bool FromMojom(gfx::mojom::OverlayTransform input, + gfx::OverlayTransform* out) { + switch (input) { + case gfx::mojom::OverlayTransform::OVERLAY_TRANSFORM_INVALID: + *out = gfx::OverlayTransform::OVERLAY_TRANSFORM_INVALID; + return true; + case gfx::mojom::OverlayTransform::OVERLAY_TRANSFORM_NONE: + *out = gfx::OverlayTransform::OVERLAY_TRANSFORM_NONE; + return true; + case gfx::mojom::OverlayTransform::OVERLAY_TRANSFORM_FLIP_HORIZONTAL: + *out = gfx::OverlayTransform::OVERLAY_TRANSFORM_FLIP_HORIZONTAL; + return true; + case gfx::mojom::OverlayTransform::OVERLAY_TRANSFORM_FLIP_VERTICAL: + *out = gfx::OverlayTransform::OVERLAY_TRANSFORM_FLIP_VERTICAL; + return true; + case gfx::mojom::OverlayTransform::OVERLAY_TRANSFORM_ROTATE_90: + *out = gfx::OverlayTransform::OVERLAY_TRANSFORM_ROTATE_90; + return true; + case gfx::mojom::OverlayTransform::OVERLAY_TRANSFORM_ROTATE_180: + *out = gfx::OverlayTransform::OVERLAY_TRANSFORM_ROTATE_180; + return true; + case gfx::mojom::OverlayTransform::OVERLAY_TRANSFORM_ROTATE_270: + *out = gfx::OverlayTransform::OVERLAY_TRANSFORM_ROTATE_270; + return true; + } + NOTREACHED(); + return false; + } +}; + +} // namespace mojo + +#endif // UI_GFX_MOJO_OVERLAY_TRANSFORM_STRUCT_TRAITS_H_ diff --git a/ui/gfx/typemaps.gni b/ui/gfx/typemaps.gni index d86ae08cc797aa..375f74db5a7037 100644 --- a/ui/gfx/typemaps.gni +++ b/ui/gfx/typemaps.gni @@ -9,6 +9,7 @@ typemaps = [ "//ui/gfx/mojo/buffer_types.typemap", "//ui/gfx/mojo/color_space.typemap", "//ui/gfx/mojo/icc_profile.typemap", + "//ui/gfx/mojo/overlay_transform.typemap", "//ui/gfx/mojo/selection_bound.typemap", "//ui/gfx/mojo/transform.typemap", "//ui/gfx/range/mojo/range.typemap", diff --git a/ui/ozone/BUILD.gn b/ui/ozone/BUILD.gn index 5047e94a0f0208..815c7858fef909 100644 --- a/ui/ozone/BUILD.gn +++ b/ui/ozone/BUILD.gn @@ -65,6 +65,8 @@ component("ozone_base") { "public/overlay_candidates_ozone.cc", "public/overlay_candidates_ozone.h", "public/overlay_manager_ozone.h", + "public/overlay_surface_candidate.cc", + "public/overlay_surface_candidate.h", "public/ozone_switches.cc", "public/ozone_switches.h", "public/surface_factory_ozone.cc", @@ -97,8 +99,9 @@ component("ozone_base") { # things that would otherwise create a cycle. "//ui/base", "//ui/events/ozone/*", - "//ui/ozone/platform/*", "//ui/ozone/common/*", + "//ui/ozone/public/interfaces", + "//ui/ozone/platform/*", ] } @@ -145,7 +148,6 @@ source_set("platform") { deps = [ ":generate_constructor_list", ":generate_ozone_platform_list", - "//ui/ozone/public/interfaces", ] deps += ozone_platform_deps @@ -162,6 +164,7 @@ component("ozone") { visibility = [ "*" ] public_deps = [ ":platform", + "//ui/ozone/public/interfaces", ] } @@ -211,15 +214,14 @@ action("generate_constructor_list") { } test("ozone_unittests") { - sources = [ - "run_all_unittests.cc", - ] - deps = [ "//base/test:test_support", + "//mojo/edk/test:run_all_unittests", + "//mojo/public/cpp/bindings", "//testing/gtest", "//ui/gfx:test_support", "//ui/gfx/geometry", + "//ui/ozone/public/interfaces:struct_trait_unit_test", ] # Add tests of platform internals. diff --git a/ui/ozone/DEPS b/ui/ozone/DEPS index 1ac3a7ae1f00ce..bcaff46ed217b4 100644 --- a/ui/ozone/DEPS +++ b/ui/ozone/DEPS @@ -10,3 +10,8 @@ include_rules = [ "+ui/gl", "+ui/platform_window", ] +specific_include_rules = { + "run_all_unittests\.cc": [ + "+mojo/edk/embedder/embedder.h", + ], +} diff --git a/ui/ozone/common/gpu/ozone_gpu_message_params.cc b/ui/ozone/common/gpu/ozone_gpu_message_params.cc index 7924ee040b0542..29692cacea4504 100644 --- a/ui/ozone/common/gpu/ozone_gpu_message_params.cc +++ b/ui/ozone/common/gpu/ozone_gpu_message_params.cc @@ -7,16 +7,15 @@ #include "ui/gfx/geometry/rect_conversions.h" #include "ui/gfx/ipc/gfx_param_traits.h" #include "ui/gfx/ipc/skia/gfx_skia_param_traits.h" +#include "ui/ozone/public/overlay_surface_candidate.h" namespace ui { -DisplayMode_Params::DisplayMode_Params() { -} +DisplayMode_Params::DisplayMode_Params() {} DisplayMode_Params::~DisplayMode_Params() {} -DisplaySnapshot_Params::DisplaySnapshot_Params() { -} +DisplaySnapshot_Params::DisplaySnapshot_Params() {} DisplaySnapshot_Params::DisplaySnapshot_Params( const DisplaySnapshot_Params& other) = default; @@ -26,7 +25,7 @@ DisplaySnapshot_Params::~DisplaySnapshot_Params() {} OverlayCheck_Params::OverlayCheck_Params() {} OverlayCheck_Params::OverlayCheck_Params( - const OverlayCandidatesOzone::OverlaySurfaceCandidate& candidate) + const ui::OverlaySurfaceCandidate& candidate) : buffer_size(candidate.buffer_size), transform(candidate.transform), format(candidate.format), @@ -37,8 +36,7 @@ OverlayCheck_Params::OverlayCheck_Params( OverlayCheck_Params::OverlayCheck_Params(const OverlayCheck_Params& other) = default; -OverlayCheck_Params::~OverlayCheck_Params() { -} +OverlayCheck_Params::~OverlayCheck_Params() {} bool OverlayCheck_Params::operator<(const OverlayCheck_Params& param) const { int lwidth = buffer_size.width(); diff --git a/ui/ozone/common/gpu/ozone_gpu_message_params.h b/ui/ozone/common/gpu/ozone_gpu_message_params.h index 0d2e8e31dd7d61..0ad90a8a98e70d 100644 --- a/ui/ozone/common/gpu/ozone_gpu_message_params.h +++ b/ui/ozone/common/gpu/ozone_gpu_message_params.h @@ -19,6 +19,7 @@ #include "ui/ozone/public/overlay_candidates_ozone.h" namespace ui { +class OverlaySurfaceCandidate; struct DisplayMode_Params { DisplayMode_Params(); @@ -56,8 +57,7 @@ struct DisplaySnapshot_Params { struct OverlayCheck_Params { OverlayCheck_Params(); - OverlayCheck_Params( - const OverlayCandidatesOzone::OverlaySurfaceCandidate& candidate); + OverlayCheck_Params(const OverlaySurfaceCandidate& candidate); OverlayCheck_Params(const OverlayCheck_Params& other); ~OverlayCheck_Params(); diff --git a/ui/ozone/demo/surfaceless_gl_renderer.cc b/ui/ozone/demo/surfaceless_gl_renderer.cc index 549c7ace125702..7930d0174599cb 100644 --- a/ui/ozone/demo/surfaceless_gl_renderer.cc +++ b/ui/ozone/demo/surfaceless_gl_renderer.cc @@ -131,7 +131,7 @@ void SurfacelessGlRenderer::OverlayChecker(int z_order, gfx::RectF display_rect(bounds_rect.x(), bounds_rect.y(), bounds_rect.width(), bounds_rect.height()); - OverlayCandidatesOzone::OverlaySurfaceCandidate overlay_candidate; + OverlaySurfaceCandidate overlay_candidate; // The bounds rectangle of the candidate overlay buffer. overlay_candidate.buffer_size = bounds_rect.size(); diff --git a/ui/ozone/platform/drm/host/drm_overlay_manager.cc b/ui/ozone/platform/drm/host/drm_overlay_manager.cc index 9d5a968998ac55..b03f6f3ed349f2 100644 --- a/ui/ozone/platform/drm/host/drm_overlay_manager.cc +++ b/ui/ozone/platform/drm/host/drm_overlay_manager.cc @@ -15,13 +15,13 @@ #include "ui/ozone/platform/drm/host/drm_overlay_candidates_host.h" #include "ui/ozone/platform/drm/host/drm_window_host.h" #include "ui/ozone/platform/drm/host/drm_window_host_manager.h" +#include "ui/ozone/public/overlay_surface_candidate.h" #include "ui/ozone/public/ozone_switches.h" namespace ui { -typedef OverlayCandidatesOzone::OverlaySurfaceCandidateList - OverlaySurfaceCandidateList; -typedef OverlayCandidatesOzone::OverlaySurfaceCandidate OverlaySurfaceCandidate; +using OverlaySurfaceCandidateList = + OverlayCandidatesOzone::OverlaySurfaceCandidateList; namespace { const size_t kMaxCacheSize = 200; diff --git a/ui/ozone/platform/drm/host/drm_overlay_manager.h b/ui/ozone/platform/drm/host/drm_overlay_manager.h index 6e5a0acedda236..de51495a2c7b4b 100644 --- a/ui/ozone/platform/drm/host/drm_overlay_manager.h +++ b/ui/ozone/platform/drm/host/drm_overlay_manager.h @@ -17,6 +17,7 @@ namespace ui { class DrmWindowHostManager; +class OverlaySurfaceCandidate; class DrmOverlayManager : public OverlayManagerOzone { public: @@ -48,9 +49,8 @@ class DrmOverlayManager : public OverlayManagerOzone { void SendOverlayValidationRequest( const std::vector& new_params, gfx::AcceleratedWidget widget) const; - bool CanHandleCandidate( - const OverlayCandidatesOzone::OverlaySurfaceCandidate& candidate, - gfx::AcceleratedWidget widget) const; + bool CanHandleCandidate(const OverlaySurfaceCandidate& candidate, + gfx::AcceleratedWidget widget) const; GpuThreadAdapter* proxy_; // Not owned. DrmWindowHostManager* window_manager_; // Not owned. diff --git a/ui/ozone/public/interfaces/BUILD.gn b/ui/ozone/public/interfaces/BUILD.gn index 7c9d6e99578153..48221f5185c80c 100644 --- a/ui/ozone/public/interfaces/BUILD.gn +++ b/ui/ozone/public/interfaces/BUILD.gn @@ -7,11 +7,7 @@ import("//mojo/public/tools/bindings/mojom.gni") mojom("interfaces") { sources = [ "device_cursor.mojom", - ] - - import_dirs = [ - get_path_info("../../../..", "abspath"), - "//mojo/services", + "overlay_surface_candidate.mojom", ] public_deps = [ @@ -20,3 +16,32 @@ mojom("interfaces") { "//ui/gfx/mojo", ] } + +source_set("struct_traits") { + sources = [ + "overlay_surface_candidate_struct_traits.h", + ] + deps = [ + "//ui/gfx/geometry/mojo:mojo", + "//ui/gfx/mojo:mojo", + ] + public_deps = [ + ":interfaces", + ":interfaces_shared_cpp_sources", + "//mojo/public/cpp/bindings", + ] +} + +source_set("struct_trait_unit_test") { + testonly = true + + sources = [ + "overlay_surface_candidate_struct_traits_unittest.cc", + ] + + deps = [ + ":interfaces", + "//testing/gtest", + "//ui/gfx/geometry", + ] +} diff --git a/ui/ozone/public/interfaces/DEPS b/ui/ozone/public/interfaces/DEPS new file mode 100644 index 00000000000000..ef8ad28d9d44b3 --- /dev/null +++ b/ui/ozone/public/interfaces/DEPS @@ -0,0 +1,3 @@ +include_rules = [ + "+mojo/public", +] diff --git a/ui/ozone/public/interfaces/OWNERS b/ui/ozone/public/interfaces/OWNERS index 08850f421205f8..2c44a463856dd1 100644 --- a/ui/ozone/public/interfaces/OWNERS +++ b/ui/ozone/public/interfaces/OWNERS @@ -1,2 +1,6 @@ per-file *.mojom=set noparent per-file *.mojom=file://ipc/SECURITY_OWNERS +per-file *_struct_traits*.*=set noparent +per-file *_struct_traits*.*=file://ipc/SECURITY_OWNERS +per-file *.typemap=set noparent +per-file *.typemap=file://ipc/SECURITY_OWNERS diff --git a/ui/ozone/public/interfaces/overlay_surface_candidate.mojom b/ui/ozone/public/interfaces/overlay_surface_candidate.mojom new file mode 100644 index 00000000000000..4903dce624ef33 --- /dev/null +++ b/ui/ozone/public/interfaces/overlay_surface_candidate.mojom @@ -0,0 +1,37 @@ +// Copyright 2017 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. + +module ui.ozone.mojom; + +import "ui/gfx/geometry/mojo/geometry.mojom"; +import "ui/gfx/mojo/buffer_types.mojom"; +import "ui/gfx/mojo/overlay_transform.mojom"; + +struct OverlaySurfaceCandidate { + // Transformation to apply to layer during composition. + gfx.mojom.OverlayTransform transform; + // Format of the buffer to composite. + gfx.mojom.BufferFormat format; + // Size of the buffer, in pixels. + gfx.mojom.Size buffer_size; + // Rect on the display to position the overlay to. Input rectangle may + // not have integer coordinates, but when accepting for overlay, must + // be modified by CheckOverlaySupport to output integer values. + gfx.mojom.RectF display_rect; + // Crop within the buffer to be placed inside |display_rect|. + gfx.mojom.RectF crop_rect; + // Quad geometry rect after applying the quad_transform(). + gfx.mojom.Rect quad_rect_in_target_space; + // Clip rect in the target content space after composition. + gfx.mojom.Rect clip_rect; + // If the quad is clipped after composition. + bool is_clipped; + // Stacking order of the overlay plane relative to the main surface, + // which is 0. Signed to allow for "underlays". + int32 plane_z_order = 0; + + // To be modified by the implementer if this candidate can go into + // an overlay. + bool overlay_handled; +}; diff --git a/ui/ozone/public/interfaces/overlay_surface_candidate.typemap b/ui/ozone/public/interfaces/overlay_surface_candidate.typemap new file mode 100644 index 00000000000000..6c9f3473b9e932 --- /dev/null +++ b/ui/ozone/public/interfaces/overlay_surface_candidate.typemap @@ -0,0 +1,13 @@ +# Copyright 2017 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. + +mojom = "//ui/ozone/public/interfaces/overlay_surface_candidate.mojom" +public_headers = [ "//ui/ozone/public/overlay_surface_candidate.h" ] +public_deps = [ + "//ui/ozone:ozone_base", +] +traits_headers = + [ "//ui/ozone/public/interfaces/overlay_surface_candidate_struct_traits.h" ] +type_mappings = + [ "ui.ozone.mojom.OverlaySurfaceCandidate=ui::OverlaySurfaceCandidate" ] diff --git a/ui/ozone/public/interfaces/overlay_surface_candidate_struct_traits.h b/ui/ozone/public/interfaces/overlay_surface_candidate_struct_traits.h new file mode 100644 index 00000000000000..53c268391a1564 --- /dev/null +++ b/ui/ozone/public/interfaces/overlay_surface_candidate_struct_traits.h @@ -0,0 +1,80 @@ +// Copyright 2017 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_OZONE_PUBLIC_INTERFACES_OVERLAY_SURFACE_CANDIDATE_STRUCT_TRAITS_H_ +#define UI_OZONE_PUBLIC_INTERFACES_OVERLAY_SURFACE_CANDIDATE_STRUCT_TRAITS_H_ + +#include "ui/gfx/geometry/mojo/geometry_struct_traits.h" +#include "ui/gfx/mojo/buffer_types_struct_traits.h" +#include "ui/gfx/mojo/overlay_transform_struct_traits.h" +#include "ui/ozone/public/interfaces/overlay_surface_candidate.mojom.h" +#include "ui/ozone/public/overlay_surface_candidate.h" + +namespace mojo { + +template <> +struct StructTraits { + static const gfx::OverlayTransform& transform( + const ui::OverlaySurfaceCandidate& osc) { + return osc.transform; + } + + static const gfx::BufferFormat& format( + const ui::OverlaySurfaceCandidate& osc) { + return osc.format; + } + + static const gfx::Size& buffer_size(const ui::OverlaySurfaceCandidate& osc) { + return osc.buffer_size; + } + + static const gfx::RectF& display_rect( + const ui::OverlaySurfaceCandidate& osc) { + return osc.display_rect; + } + + static const gfx::RectF& crop_rect(const ui::OverlaySurfaceCandidate& osc) { + return osc.crop_rect; + } + + static const gfx::Rect& quad_rect_in_target_space( + const ui::OverlaySurfaceCandidate& osc) { + return osc.quad_rect_in_target_space; + } + + static const gfx::Rect& clip_rect(const ui::OverlaySurfaceCandidate& osc) { + return osc.clip_rect; + } + + static bool is_clipped(const ui::OverlaySurfaceCandidate& osc) { + return osc.is_clipped; + } + + static int plane_z_order(const ui::OverlaySurfaceCandidate& osc) { + return osc.plane_z_order; + } + + static bool overlay_handled(const ui::OverlaySurfaceCandidate& osc) { + return osc.overlay_handled; + } + + static bool Read(ui::ozone::mojom::OverlaySurfaceCandidateDataView data, + ui::OverlaySurfaceCandidate* out) { + out->is_clipped = data.is_clipped(); + out->plane_z_order = data.plane_z_order(); + out->overlay_handled = data.overlay_handled(); + return data.ReadTransform(&out->transform) && + data.ReadFormat(&out->format) && + data.ReadBufferSize(&out->buffer_size) && + data.ReadDisplayRect(&out->display_rect) && + data.ReadCropRect(&out->crop_rect) && + data.ReadQuadRectInTargetSpace(&out->quad_rect_in_target_space) && + data.ReadClipRect(&out->clip_rect); + } +}; + +} // namespace mojo + +#endif // UI_OZONE_PUBLIC_INTERFACES_OVERLAY_SURFACE_CANDIDATE_STRUCT_TRAITS_H_ diff --git a/ui/ozone/public/interfaces/overlay_surface_candidate_struct_traits_unittest.cc b/ui/ozone/public/interfaces/overlay_surface_candidate_struct_traits_unittest.cc new file mode 100644 index 00000000000000..8ec1fd0c20fe6c --- /dev/null +++ b/ui/ozone/public/interfaces/overlay_surface_candidate_struct_traits_unittest.cc @@ -0,0 +1,73 @@ +// Copyright 2017 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 + +#include "testing/gtest/include/gtest/gtest.h" +#include "ui/gfx/geometry/point.h" +#include "ui/ozone/public/interfaces/overlay_surface_candidate.mojom.h" +#include "ui/ozone/public/interfaces/overlay_surface_candidate_struct_traits.h" +#include "ui/ozone/public/overlay_surface_candidate.h" + +namespace ui { + +namespace { + +class OverlaySurfaceCandidateStructTraitsTest : public testing::Test { + public: + OverlaySurfaceCandidateStructTraitsTest() {} +}; + +} // namespace + +TEST_F(OverlaySurfaceCandidateStructTraitsTest, FieldsEqual) { + ui::OverlaySurfaceCandidate input; + + input.transform = gfx::OVERLAY_TRANSFORM_FLIP_HORIZONTAL; + input.format = gfx::BufferFormat::YUV_420_BIPLANAR; + input.buffer_size = gfx::Size(6, 7); + input.display_rect = gfx::RectF(1., 2., 3., 4.); + input.crop_rect = gfx::RectF(10., 20., 30., 40.); + input.quad_rect_in_target_space = gfx::Rect(101, 201, 301, 401); + input.clip_rect = gfx::Rect(11, 21, 31, 41); + input.is_clipped = true; + input.plane_z_order = 42; + input.overlay_handled = true; + + ui::OverlaySurfaceCandidate output; + + bool success = ui::ozone::mojom::OverlaySurfaceCandidate::Deserialize( + ui::ozone::mojom::OverlaySurfaceCandidate::Serialize(&input), &output); + + EXPECT_TRUE(success); + + EXPECT_EQ(input.transform, output.transform); + EXPECT_EQ(input.format, output.format); + EXPECT_EQ(input.buffer_size, output.buffer_size); + EXPECT_EQ(input.display_rect, output.display_rect); + EXPECT_EQ(input.crop_rect, output.crop_rect); + EXPECT_EQ(input.quad_rect_in_target_space, output.quad_rect_in_target_space); + EXPECT_EQ(input.clip_rect, output.clip_rect); + EXPECT_EQ(input.is_clipped, output.is_clipped); + EXPECT_EQ(input.plane_z_order, output.plane_z_order); + EXPECT_EQ(input.overlay_handled, output.overlay_handled); +} + +TEST_F(OverlaySurfaceCandidateStructTraitsTest, FalseBools) { + ui::OverlaySurfaceCandidate input; + + input.is_clipped = false; + input.overlay_handled = false; + + ui::OverlaySurfaceCandidate output; + + bool success = ui::ozone::mojom::OverlaySurfaceCandidate::Deserialize( + ui::ozone::mojom::OverlaySurfaceCandidate::Serialize(&input), &output); + + EXPECT_TRUE(success); + EXPECT_EQ(input.is_clipped, output.is_clipped); + EXPECT_EQ(input.overlay_handled, output.overlay_handled); +} + +} // namespace ui diff --git a/ui/ozone/public/interfaces/typemaps.gni b/ui/ozone/public/interfaces/typemaps.gni new file mode 100644 index 00000000000000..860a0b36be447c --- /dev/null +++ b/ui/ozone/public/interfaces/typemaps.gni @@ -0,0 +1,5 @@ +# Copyright 2017 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. + +typemaps = [ "//ui/ozone/public/interfaces/overlay_surface_candidate.typemap" ] diff --git a/ui/ozone/public/overlay_candidates_ozone.cc b/ui/ozone/public/overlay_candidates_ozone.cc index d6fdc009edba82..e6cc3c8d833a91 100644 --- a/ui/ozone/public/overlay_candidates_ozone.cc +++ b/ui/ozone/public/overlay_candidates_ozone.cc @@ -8,21 +8,11 @@ namespace ui { -OverlayCandidatesOzone::OverlaySurfaceCandidate::OverlaySurfaceCandidate() - : is_clipped(false) {} - -OverlayCandidatesOzone::OverlaySurfaceCandidate::OverlaySurfaceCandidate( - const OverlaySurfaceCandidate& other) = default; - -OverlayCandidatesOzone::OverlaySurfaceCandidate::~OverlaySurfaceCandidate() { -} - void OverlayCandidatesOzone::CheckOverlaySupport( OverlaySurfaceCandidateList* surfaces) { NOTREACHED(); } -OverlayCandidatesOzone::~OverlayCandidatesOzone() { -} +OverlayCandidatesOzone::~OverlayCandidatesOzone() {} } // namespace ui diff --git a/ui/ozone/public/overlay_candidates_ozone.h b/ui/ozone/public/overlay_candidates_ozone.h index 6637e8657dff87..760721feea05d6 100644 --- a/ui/ozone/public/overlay_candidates_ozone.h +++ b/ui/ozone/public/overlay_candidates_ozone.h @@ -7,12 +7,8 @@ #include -#include "ui/gfx/buffer_types.h" -#include "ui/gfx/geometry/rect.h" -#include "ui/gfx/geometry/rect_f.h" -#include "ui/gfx/geometry/size.h" -#include "ui/gfx/overlay_transform.h" #include "ui/ozone/ozone_base_export.h" +#include "ui/ozone/public/overlay_surface_candidate.h" namespace ui { @@ -21,38 +17,6 @@ namespace ui { // class from SurfaceFactoryOzone given an AcceleratedWidget. class OZONE_BASE_EXPORT OverlayCandidatesOzone { public: - struct OverlaySurfaceCandidate { - OverlaySurfaceCandidate(); - OverlaySurfaceCandidate(const OverlaySurfaceCandidate& other); - ~OverlaySurfaceCandidate(); - - // Transformation to apply to layer during composition. - gfx::OverlayTransform transform = gfx::OVERLAY_TRANSFORM_NONE; - // Format of the buffer to composite. - gfx::BufferFormat format = gfx::BufferFormat::BGRA_8888; - // Size of the buffer, in pixels. - gfx::Size buffer_size; - // Rect on the display to position the overlay to. Input rectangle may - // not have integer coordinates, but when accepting for overlay, must - // be modified by CheckOverlaySupport to output integer values. - gfx::RectF display_rect; - // Crop within the buffer to be placed inside |display_rect|. - gfx::RectF crop_rect; - // Quad geometry rect after applying the quad_transform(). - gfx::Rect quad_rect_in_target_space; - // Clip rect in the target content space after composition. - gfx::Rect clip_rect; - // If the quad is clipped after composition. - bool is_clipped; - // Stacking order of the overlay plane relative to the main surface, - // which is 0. Signed to allow for "underlays". - int plane_z_order = 0; - - // To be modified by the implementer if this candidate can go into - // an overlay. - bool overlay_handled = false; - }; - typedef std::vector OverlaySurfaceCandidateList; // A list of possible overlay candidates is presented to this function. diff --git a/ui/ozone/public/overlay_surface_candidate.cc b/ui/ozone/public/overlay_surface_candidate.cc new file mode 100644 index 00000000000000..3612d21810fa45 --- /dev/null +++ b/ui/ozone/public/overlay_surface_candidate.cc @@ -0,0 +1,16 @@ +// Copyright 2017 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/ozone/public/overlay_surface_candidate.h" + +namespace ui { + +OverlaySurfaceCandidate::OverlaySurfaceCandidate() : is_clipped(false) {} + +OverlaySurfaceCandidate::OverlaySurfaceCandidate( + const OverlaySurfaceCandidate& other) = default; + +OverlaySurfaceCandidate::~OverlaySurfaceCandidate() {} + +} // namespace ui diff --git a/ui/ozone/public/overlay_surface_candidate.h b/ui/ozone/public/overlay_surface_candidate.h new file mode 100644 index 00000000000000..349ec1bdb09b23 --- /dev/null +++ b/ui/ozone/public/overlay_surface_candidate.h @@ -0,0 +1,52 @@ +// Copyright 2017 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_OZONE_PUBLIC_OVERLAY_SURFACE_CANDIDATE_H_ +#define UI_OZONE_PUBLIC_OVERLAY_SURFACE_CANDIDATE_H_ + +#include "ui/gfx/buffer_types.h" +#include "ui/gfx/geometry/rect.h" +#include "ui/gfx/geometry/rect_f.h" +#include "ui/gfx/geometry/size.h" +#include "ui/gfx/overlay_transform.h" +#include "ui/ozone/ozone_base_export.h" + +namespace ui { + +class OZONE_BASE_EXPORT OverlaySurfaceCandidate { + public: + OverlaySurfaceCandidate(); + OverlaySurfaceCandidate(const OverlaySurfaceCandidate& other); + ~OverlaySurfaceCandidate(); + + // Transformation to apply to layer during composition. + gfx::OverlayTransform transform = gfx::OVERLAY_TRANSFORM_NONE; + // Format of the buffer to composite. + gfx::BufferFormat format = gfx::BufferFormat::BGRA_8888; + // Size of the buffer, in pixels. + gfx::Size buffer_size; + // Rect on the display to position the overlay to. Input rectangle may + // not have integer coordinates, but when accepting for overlay, must + // be modified by CheckOverlaySupport to output integer values. + gfx::RectF display_rect; + // Crop within the buffer to be placed inside |display_rect|. + gfx::RectF crop_rect; + // Quad geometry rect after applying the quad_transform(). + gfx::Rect quad_rect_in_target_space; + // Clip rect in the target content space after composition. + gfx::Rect clip_rect; + // If the quad is clipped after composition. + bool is_clipped; + // Stacking order of the overlay plane relative to the main surface, + // which is 0. Signed to allow for "underlays". + int plane_z_order = 0; + + // To be modified by the implementer if this candidate can go into + // an overlay. + bool overlay_handled = false; +}; + +} // namespace ui + +#endif // UI_OZONE_PUBLIC_OVERLAY_SURFACE_CANDIDATE_H_ \ No newline at end of file diff --git a/ui/ozone/run_all_unittests.cc b/ui/ozone/run_all_unittests.cc deleted file mode 100644 index 9f2ad71aae192e..00000000000000 --- a/ui/ozone/run_all_unittests.cc +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2014 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 "base/bind.h" -#include "base/macros.h" -#include "base/test/launcher/unit_test_launcher.h" -#include "base/test/test_suite.h" -#include "build/build_config.h" - -namespace { - -class OzoneTestSuite : public base::TestSuite { - public: - OzoneTestSuite(int argc, char** argv); - - protected: - // base::TestSuite: - void Initialize() override; - void Shutdown() override; - - private: - DISALLOW_COPY_AND_ASSIGN(OzoneTestSuite); -}; - -OzoneTestSuite::OzoneTestSuite(int argc, char** argv) - : base::TestSuite(argc, argv) {} - -void OzoneTestSuite::Initialize() { - base::TestSuite::Initialize(); -} - -void OzoneTestSuite::Shutdown() { - base::TestSuite::Shutdown(); -} - -} // namespace - -int main(int argc, char** argv) { - OzoneTestSuite test_suite(argc, argv); - - return base::LaunchUnitTests(argc, - argv, - base::Bind(&OzoneTestSuite::Run, - base::Unretained(&test_suite))); -}