[CodeHealth] Use std::array in DecomposedTransform
Convert T[N]->std::array<T, N>. This will allow removing more
`allow_unsafe_buffer` pragmas in files that consume decomposed_transform
as well as matching it to the new recommended guidance from:
https://chromium.googlesource.com/chromium/src/+/main/docs/unsafe_buffers.md#use-of-std_array
Bug: 351564777
Change-Id: Id37b986cfb1f3b2f4ba565e317530cf780f1db24
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6148932
Reviewed-by: Ian Vollick <[email protected]>
Commit-Queue: Alexander Cooper <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1402606}
diff --git a/device/vr/util/transform_utils.cc b/device/vr/util/transform_utils.cc
index 2c41681..92b9dec4 100644
--- a/device/vr/util/transform_utils.cc
+++ b/device/vr/util/transform_utils.cc
@@ -2,11 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifdef UNSAFE_BUFFERS_BUILD
-// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
-#pragma allow_unsafe_buffers
-#endif
-
#include "device/vr/util/transform_utils.h"
#include "ui/gfx/geometry/decomposed_transform.h"
diff --git a/ui/gfx/geometry/decomposed_transform.h b/ui/gfx/geometry/decomposed_transform.h
index e93a5dc..d134ad5 100644
--- a/ui/gfx/geometry/decomposed_transform.h
+++ b/ui/gfx/geometry/decomposed_transform.h
@@ -5,6 +5,8 @@
#ifndef UI_GFX_GEOMETRY_DECOMPOSED_TRANSFORM_H_
#define UI_GFX_GEOMETRY_DECOMPOSED_TRANSFORM_H_
+#include <array>
+
#include "base/component_export.h"
#include "base/dcheck_is_on.h"
#include "ui/gfx/geometry/quaternion.h"
@@ -16,10 +18,10 @@
struct COMPONENT_EXPORT(GEOMETRY) DecomposedTransform {
// The default constructor initializes the components in such a way that
// will compose the identity transform.
- double translate[3] = {0, 0, 0};
- double scale[3] = {1, 1, 1};
- double skew[3] = {0, 0, 0};
- double perspective[4] = {0, 0, 0, 1};
+ std::array<double, 3u> translate = {0, 0, 0};
+ std::array<double, 3u> scale = {1, 1, 1};
+ std::array<double, 3u> skew = {0, 0, 0};
+ std::array<double, 4u> perspective = {0, 0, 0, 1};
Quaternion quaternion;
std::string ToString() const;
diff --git a/ui/gfx/geometry/matrix44.cc b/ui/gfx/geometry/matrix44.cc
index d573e7e2..9f0f930 100644
--- a/ui/gfx/geometry/matrix44.cc
+++ b/ui/gfx/geometry/matrix44.cc
@@ -266,7 +266,7 @@
SetCol(1, c1 + c0 * tan_skew_x);
}
-void Matrix44::ApplyDecomposedSkews(const double skews[3]) {
+void Matrix44::ApplyDecomposedSkews(base::span<const double, 3> skews) {
Double4 c0 = Col(0);
Double4 c1 = Col(1);
Double4 c2 = Col(2);
diff --git a/ui/gfx/geometry/matrix44.h b/ui/gfx/geometry/matrix44.h
index ffe82221..b3a342a 100644
--- a/ui/gfx/geometry/matrix44.h
+++ b/ui/gfx/geometry/matrix44.h
@@ -14,6 +14,7 @@
#include "base/check_op.h"
#include "base/component_export.h"
+#include "base/containers/span.h"
#include "ui/gfx/geometry/double4.h"
namespace gfx {
@@ -157,7 +158,7 @@
// this = this * |0 1 skew[2] 0|
// |0 0 1 0|
// |0 0 0 1|
- void ApplyDecomposedSkews(const double skews[3]);
+ void ApplyDecomposedSkews(base::span<const double, 3> skews);
// this = this * perspective.
void ApplyPerspectiveDepth(double perspective);
diff --git a/ui/gfx/geometry/transform_util.cc b/ui/gfx/geometry/transform_util.cc
index 4829035..9ea598f 100644
--- a/ui/gfx/geometry/transform_util.cc
+++ b/ui/gfx/geometry/transform_util.cc
@@ -25,9 +25,9 @@
namespace {
template <int n>
-void Combine(double* out,
- const double* a,
- const double* b,
+void Combine(std::array<double, n>& out,
+ const std::array<double, n> a,
+ const std::array<double, n> b,
double scale_a,
double scale_b) {
for (int i = 0; i < n; ++i)