0

C++11 std::array rewrite for memory safety [12/19]

Split from:
https://chromium-review.googlesource.com/c/chromium/src/+/6004959/21

Generated patch
---------------
- Tool: ./tool/clang/spanify/rewrite-multiple-platform.sh
- Platform: Linux.
- Filter: This includes 2400/4222 patches. I included the std::array
      ones and excluded build errors.

Google announcement:
--------------------
https://groups.google.com/a/google.com/g/chrome-memory-safety/c/RMiO4gaVLQA/m/Yz-3NCObAgAJ

Benchmarks:
----------
See design doc and
https://chromium-review.googlesource.com/c/chromium/src/+/6004959/21

Description
-----------
The consensus during the memory safety summit was to begin rewriting
relevant C-style arrays to C++11 std::array. It can be done immediately,
offers better developer ergonomics, and fix large chunks of the
-Wunsafe-buffer-usage errors in Chrome.

To clarify, this effort is complementary to the longer plan work with
enabling -fsanitize=array-bounds, and we plan to leverage both,
especially for protecting 3p code.

[Attached] is a document detailing the rationale, benefits, and
considerations for potential compile-time and performance impacts.

[Attached]:https://docs.google.com/document/d/1z5aBDg26lHmNDjXRCysElWKx7E4PAJXqykI_k7ondJI/edit?tab=t.0#heading=h.cqgo7wvp0kzt

NO_IFTTT=No need to update base/debug/stack_trace.h

Bug: 378069401
Change-Id: I9a0271e4b45a2be44dfbb30e95d267745765b5fa
R: dcheng@chromium.org
AX-Relnotes: n/a.
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6044118
Auto-Submit: Arthur Sonzogni <arthursonzogni@chromium.org>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Owners-Override: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1395060}
This commit is contained in:
Arthur Sonzogni
2024-12-11 13:06:30 -08:00
committed by Chromium LUCI CQ
parent 3addb4952a
commit 91423838c1
26 changed files with 239 additions and 256 deletions

@ -2,13 +2,10 @@
// 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 "cc/base/index_rect.h"
#include <array>
#include "testing/gtest/include/gtest/gtest.h"
namespace cc {
@ -21,11 +18,14 @@ TEST(IndexRectTest, NumIndices) {
int bottom;
int num_indices_x;
int num_indices_y;
} num_indices_cases[] = {{-10, 10, -10, 10, 21, 21},
{0, 5, 0, 10, 6, 11},
{1, 2, 3, 4, 2, 2},
{0, 0, 0, 0, 1, 1},
{10, 10, 10, 10, 1, 1}};
};
auto num_indices_cases = std::to_array<NumIndicesCase>({
{-10, 10, -10, 10, 21, 21},
{0, 5, 0, 10, 6, 11},
{1, 2, 3, 4, 2, 2},
{0, 0, 0, 0, 1, 1},
{10, 10, 10, 10, 1, 1},
});
for (size_t i = 0; i < std::size(num_indices_cases); ++i) {
const NumIndicesCase& value = num_indices_cases[i];
@ -48,11 +48,14 @@ TEST(IndexRectTest, ClampTo) {
Indices second;
Indices expected;
bool valid;
} clamp_to_cases[] = {{{0, 5, 0, 5}, {0, 5, 0, 5}, {0, 5, 0, 5}, true},
{{0, 10, 0, 10}, {0, 5, 0, 5}, {0, 5, 0, 5}, true},
{{0, 5, 0, 5}, {0, 10, 0, 10}, {0, 5, 0, 5}, true},
{{-10, 5, -10, 5}, {0, 10, 0, 10}, {0, 5, 0, 5}, true},
{{0, 5, 0, 5}, {10, 20, 10, 20}, {0, 0, 0, 0}, false}};
};
auto clamp_to_cases = std::to_array<ClampToCase>({
{{0, 5, 0, 5}, {0, 5, 0, 5}, {0, 5, 0, 5}, true},
{{0, 10, 0, 10}, {0, 5, 0, 5}, {0, 5, 0, 5}, true},
{{0, 5, 0, 5}, {0, 10, 0, 10}, {0, 5, 0, 5}, true},
{{-10, 5, -10, 5}, {0, 10, 0, 10}, {0, 5, 0, 5}, true},
{{0, 5, 0, 5}, {10, 20, 10, 20}, {0, 0, 0, 0}, false},
});
for (size_t i = 0; i < std::size(clamp_to_cases); ++i) {
const ClampToCase& value = clamp_to_cases[i];
@ -80,12 +83,18 @@ TEST(IndexRectTest, Contains) {
int index_x;
int index_y;
bool contained;
} contains_cases[] = {
{-10, 10, -10, 10, -10, -10, true}, {-10, 10, -10, 10, 0, 0, true},
{-10, 10, -10, 10, 10, 10, true}, {-10, 10, -10, 10, 5, 5, true},
{-10, 10, -10, 10, -5, -5, true}, {-10, 10, -10, 10, -20, -20, false},
{-10, 10, -10, 10, 20, 20, false}, {-10, 10, -10, 10, 20, 5, false},
{-10, 10, -10, 10, 5, 20, false}};
};
auto contains_cases = std::to_array<ContainsCase>({
{-10, 10, -10, 10, -10, -10, true},
{-10, 10, -10, 10, 0, 0, true},
{-10, 10, -10, 10, 10, 10, true},
{-10, 10, -10, 10, 5, 5, true},
{-10, 10, -10, 10, -5, -5, true},
{-10, 10, -10, 10, -20, -20, false},
{-10, 10, -10, 10, 20, 20, false},
{-10, 10, -10, 10, 20, 5, false},
{-10, 10, -10, 10, 5, 20, false},
});
for (size_t i = 0; i < std::size(contains_cases); ++i) {
const ContainsCase& value = contains_cases[i];

@ -2,16 +2,12 @@
// 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 "cc/base/list_container.h"
#include <stddef.h>
#include <algorithm>
#include <array>
#include <vector>
#include "base/memory/raw_ptr.h"
@ -737,7 +733,7 @@ TEST(ListContainerTest, InsertCopyBeforeBegin) {
auto iter = list.InsertBeforeAndInvalidateAllPointers<SimpleDerivedElement>(
list.begin(), count, insert_element);
const int expected_result[] = {100, 100, 0, 1, 2, 3};
const auto expected_result = std::to_array<int>({100, 100, 0, 1, 2, 3});
int iter_index = 0;
for (iter = list.begin(); iter != list.end(); ++iter) {
EXPECT_EQ(expected_result[iter_index],
@ -763,7 +759,7 @@ TEST(ListContainerTest, InsertCopyBeforeEnd) {
auto iter = list.InsertBeforeAndInvalidateAllPointers<SimpleDerivedElement>(
list.end(), count, insert_element);
const int expected_result[] = {0, 1, 2, 3, 100, 100, 100};
const auto expected_result = std::to_array<int>({0, 1, 2, 3, 100, 100, 100});
int iter_index = 0;
for (iter = list.begin(); iter != list.end(); ++iter) {
EXPECT_EQ(expected_result[iter_index],
@ -782,7 +778,7 @@ TEST(ListContainerTest, InsertCopyBeforeEmpty) {
auto iter = list.InsertBeforeAndInvalidateAllPointers<SimpleDerivedElement>(
list.end(), count, insert_element);
const int expected_result[] = {100, 100, 100};
const auto expected_result = std::to_array<int>({100, 100, 100});
int iter_index = 0;
for (iter = list.begin(); iter != list.end(); ++iter) {
EXPECT_EQ(expected_result[iter_index],
@ -822,7 +818,8 @@ TEST(ListContainerTest, InsertCopyBeforeMany) {
iter++;
}
const int expected_result[] = {0, 1, 100, 100, 4, 5, 100, 7, 100, 9};
const auto expected_result =
std::to_array<int>({0, 1, 100, 100, 4, 5, 100, 7, 100, 9});
int iter_index = 0;
for (iter = list.begin(); iter != list.end(); ++iter) {
EXPECT_EQ(expected_result[iter_index],
@ -851,7 +848,7 @@ TEST(ListContainerTest, InsertBeforeBegin) {
++iter;
}
const int expected_result[] = {100, 101, 0, 1, 2, 3};
const auto expected_result = std::to_array<int>({100, 101, 0, 1, 2, 3});
int iter_index = 0;
for (iter = list.begin(); iter != list.end(); ++iter) {
EXPECT_EQ(expected_result[iter_index],
@ -880,7 +877,7 @@ TEST(ListContainerTest, InsertBeforeEnd) {
++iter;
}
const int expected_result[] = {0, 1, 2, 3, 100, 101, 102};
const auto expected_result = std::to_array<int>({0, 1, 2, 3, 100, 101, 102});
int iter_index = 0;
for (iter = list.begin(); iter != list.end(); ++iter) {
EXPECT_EQ(expected_result[iter_index],
@ -902,7 +899,7 @@ TEST(ListContainerTest, InsertBeforeEmpty) {
++iter;
}
const int expected_result[] = {100, 101, 102};
const auto expected_result = std::to_array<int>({100, 101, 102});
int iter_index = 0;
for (iter = list.begin(); iter != list.end(); ++iter) {
EXPECT_EQ(expected_result[iter_index],
@ -916,11 +913,11 @@ TEST(ListContainerTest, InsertBeforeMany) {
ListContainer<DerivedElement> list(kCurrentLargestDerivedElementAlign,
kCurrentLargestDerivedElementSize, 0);
// Create a partial list of 1,...,99.
int initial_list[] = {
auto initial_list = std::to_array<int>({
0, 1, 4, 5, 6, 7, 8, 9, 11, 12, 17, 18, 19, 20, 21, 22,
23, 24, 25, 26, 27, 28, 29, 30, 32, 34, 36, 37, 51, 52, 54, 56,
60, 64, 65, 70, 75, 76, 80, 81, 83, 86, 87, 90, 93, 95, 97, 98,
};
});
const size_t size = std::size(initial_list);
for (size_t i = 0; i < size; ++i) {
SimpleDerivedElement* element =
@ -978,7 +975,7 @@ TEST(ListContainerTest, InsertAfterBegin) {
++iter;
}
const int expected_result[] = {0, 100, 101, 1, 2, 3};
const auto expected_result = std::to_array<int>({0, 100, 101, 1, 2, 3});
int iter_index = 0;
for (iter = list.begin(); iter != list.end(); ++iter) {
EXPECT_EQ(expected_result[iter_index],
@ -1007,7 +1004,7 @@ TEST(ListContainerTest, InsertAfterEnd) {
++iter;
}
const int expected_result[] = {0, 1, 2, 3, 100, 101, 102};
const auto expected_result = std::to_array<int>({0, 1, 2, 3, 100, 101, 102});
int iter_index = 0;
for (iter = list.begin(); iter != list.end(); ++iter) {
EXPECT_EQ(expected_result[iter_index],
@ -1029,7 +1026,7 @@ TEST(ListContainerTest, InsertAfterEmpty) {
++iter;
}
const int expected_result[] = {100, 101, 102};
const auto expected_result = std::to_array<int>({100, 101, 102});
int iter_index = 0;
for (iter = list.begin(); iter != list.end(); ++iter) {
EXPECT_EQ(expected_result[iter_index],
@ -1043,11 +1040,11 @@ TEST(ListContainerTest, InsertAfterMany) {
ListContainer<DerivedElement> list(kCurrentLargestDerivedElementAlign,
kCurrentLargestDerivedElementSize, 0);
// Create a partial list of 1,...,99.
int initial_list[] = {
auto initial_list = std::to_array<int>({
0, 1, 4, 5, 6, 7, 8, 9, 11, 12, 17, 18, 19, 20, 21, 22,
23, 24, 25, 26, 27, 28, 29, 30, 32, 34, 36, 37, 51, 52, 54, 56,
60, 64, 65, 70, 75, 76, 80, 81, 83, 86, 87, 90, 93, 95, 97, 98,
};
});
const size_t size = std::size(initial_list);
for (size_t i = 0; i < size; ++i) {
SimpleDerivedElement* element =

@ -2,16 +2,12 @@
// 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 "cc/layers/picture_layer_impl.h"
#include <stddef.h>
#include <algorithm>
#include <array>
#include <limits>
#include <memory>
#include <set>
@ -3677,7 +3673,7 @@ TEST_F(LegacySWPictureLayerImplTest, TilingSetEvictionQueue) {
all_tiles);
std::set<Tile*> unique_tiles;
float expected_scales[] = {low_res_factor, 1.f};
auto expected_scales = std::to_array<float>({low_res_factor, 1.f});
size_t scale_index = 0;
bool reached_visible = false;
PrioritizedTile last_tile;
@ -4970,9 +4966,12 @@ TEST_F(OcclusionTrackingPictureLayerImplTest,
// The expected number of occluded tiles on each of the 2 tilings for each of
// the 3 tree priorities.
size_t expected_occluded_tile_count_on_pending[] = {4u, 0u};
size_t expected_occluded_tile_count_on_active[] = {12u, 3u};
size_t total_expected_occluded_tile_count_on_trees[] = {15u, 4u};
auto expected_occluded_tile_count_on_pending =
std::to_array<size_t>({4u, 0u});
auto expected_occluded_tile_count_on_active =
std::to_array<size_t>({12u, 3u});
auto total_expected_occluded_tile_count_on_trees =
std::to_array<size_t>({15u, 4u});
// Verify number of occluded tiles on the pending layer for each tiling.
for (size_t i = 0; i < pending_layer()->num_tilings(); ++i) {

@ -2,11 +2,7 @@
// 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 <array>
#include <vector>
#include "cc/base/region.h"
@ -23,7 +19,7 @@ namespace {
TEST(RecordingSourceTest, DiscardableImagesWithTransform) {
FakeRecordingSource recording_source(gfx::Size(256, 256));
PaintImage discardable_image[2][2];
std::array<std::array<PaintImage, 2>, 2> discardable_image;
gfx::Transform identity_transform;
discardable_image[0][0] = CreateDiscardablePaintImage(gfx::Size(32, 32));
// Translate transform is equivalent to moving using point.
@ -183,7 +179,7 @@ TEST(RecordingSourceTest, NoDiscardableImages) {
TEST(RecordingSourceTest, DiscardableImages) {
FakeRecordingSource recording_source(gfx::Size(256, 256));
PaintImage discardable_image[2][2];
std::array<std::array<PaintImage, 2>, 2> discardable_image;
discardable_image[0][0] = CreateDiscardablePaintImage(gfx::Size(32, 32));
discardable_image[1][0] = CreateDiscardablePaintImage(gfx::Size(32, 32));
discardable_image[1][1] = CreateDiscardablePaintImage(gfx::Size(32, 32));
@ -249,7 +245,7 @@ TEST(RecordingSourceTest, DiscardableImagesBaseNonDiscardable) {
PaintImage non_discardable_image =
CreateNonDiscardablePaintImage(gfx::Size(512, 512));
PaintImage discardable_image[2][2];
std::array<std::array<PaintImage, 2>, 2> discardable_image;
discardable_image[0][0] = CreateDiscardablePaintImage(gfx::Size(128, 128));
discardable_image[0][1] = CreateDiscardablePaintImage(gfx::Size(128, 128));
discardable_image[1][1] = CreateDiscardablePaintImage(gfx::Size(128, 128));

@ -9,6 +9,7 @@
#include <stddef.h>
#include <array>
#include <memory>
#include <unordered_map>
@ -1178,8 +1179,8 @@ TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbPosition) {
}
TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbVerticalAdjust) {
SolidColorScrollbarLayerImpl* layers[2] =
{ horizontal_scrollbar_layer_.get(), vertical_scrollbar_layer_.get() };
std::array<SolidColorScrollbarLayerImpl*, 2> layers = {
horizontal_scrollbar_layer_.get(), vertical_scrollbar_layer_.get()};
for (size_t i = 0; i < 2; ++i) {
layers[i]->SetCurrentPos(25.f);
layers[i]->SetClipLayerLength(25.f);
@ -1263,7 +1264,7 @@ class ScrollbarLayerTestResourceCreationAndRelease : public ScrollbarLayerTest {
TEST_F(ScrollbarLayerTestResourceCreationAndRelease, ResourceUpload) {
bool use_solid_color_scrollbars = false;
TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars);
int num_updates[3] = {1, 5, 10};
std::array<int, 3> num_updates = {1, 5, 10};
int created = 0;
int deleted = 0;
for (int j = 0; j < 3; j++) {

@ -4,6 +4,7 @@
#include "cc/metrics/compositor_frame_reporter.h"
#include <array>
#include <memory>
#include <utility>
#include <vector>
@ -746,11 +747,11 @@ TEST_F(CompositorFrameReporterTest, PartialUpdateDependentQueues) {
const size_t kMaxOwnedPartialUpdateDependents = 300u;
// The first three dependent reporters for the front of the queue.
std::unique_ptr<CompositorFrameReporter> deps[] = {
auto deps = std::to_array<std::unique_ptr<CompositorFrameReporter>>({
CreatePipelineReporter(),
CreatePipelineReporter(),
CreatePipelineReporter(),
};
});
// Set `deps[0]` as a dependent of the main reporter and adopt it at the same
// time. This should enqueue it in both non-owned and owned dependents queues.

@ -2,13 +2,9 @@
// 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 "cc/metrics/events_metrics_manager.h"
#include <array>
#include <utility>
#include <vector>
@ -82,7 +78,8 @@ TEST_F(EventsMetricsManagerTest, EventsMetricsSaved) {
kSaveOutsideScope,
};
std::pair<std::unique_ptr<EventMetrics>, Behavior> events[] = {
auto events = std::to_array<
std::pair<std::unique_ptr<EventMetrics>, Behavior>>({
// An interesting event type for which SaveActiveEventMetrics() is not
// called.
{CreateEventMetrics(ui::EventType::kMousePressed), Behavior::kDoNotSave},
@ -101,7 +98,7 @@ TEST_F(EventsMetricsManagerTest, EventsMetricsSaved) {
// called inside its monitor scope.
{CreateEventMetrics(ui::EventType::kMouseEntered),
Behavior::kSaveInsideScope},
};
});
EXPECT_NE(events[0].first, nullptr);
EXPECT_NE(events[1].first, nullptr);
EXPECT_NE(events[2].first, nullptr);
@ -138,7 +135,7 @@ TEST_F(EventsMetricsManagerTest, EventsMetricsSaved) {
// Tests that metrics for nested event loops are handled properly in a few
// different configurations.
TEST_F(EventsMetricsManagerTest, NestedEventsMetrics) {
struct {
struct Configs {
// Type of event to use for the outer scope. `ui::EventType::kUnknown` if
// no event should be used.
ui::EventType outer_event_type;
@ -155,7 +152,8 @@ TEST_F(EventsMetricsManagerTest, NestedEventsMetrics) {
// Whether to save the outer scope metrics after the inner scope ended.
bool save_outer_metrics_after_inner;
} configs[] = {
};
auto configs = std::to_array<Configs>({
// Config #0.
{
/*outer_event_type=*/ui::EventType::kMousePressed,
@ -200,7 +198,7 @@ TEST_F(EventsMetricsManagerTest, NestedEventsMetrics) {
/*save_inner_metrics=*/true,
/*save_outer_metrics_after_inner=*/false,
},
};
});
for (size_t i = 0; i < std::size(configs); i++) {
auto& config = configs[i];

@ -2,13 +2,9 @@
// 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 "cc/metrics/predictor_jank_tracker.h"
#include <array>
#include <memory>
#include <string>
#include <vector>
@ -202,7 +198,7 @@ TEST_F(PredictorJankTrackerTest, JankyFramePercentageEmitted) {
// a sequence of 50 frames, with 10 irregular jumps means 20%
// of the frames were janky, and should be reported since frame count
// is more than 50.
double pattern[5] = {50, 50, 50, 50, 10};
std::array<double, 5> pattern = {50, 50, 50, 50, 10};
for (int i = 1; i <= 64; i++, base_presentation_ts_ += vsync_interval) {
MockFrameProduction(pattern[i % 5], base_presentation_ts_);
}
@ -215,7 +211,7 @@ TEST_F(PredictorJankTrackerTest, JankyFramePercentageNotEmitted) {
// a sequence of 49 frames with 20% janky jumps, but the percentage isn't
// reported because we only report the percentage when more than 50 frames
// exist in the sequence.
double pattern[5] = {50, 50, 50, 50, 10};
std::array<double, 5> pattern = {50, 50, 50, 50, 10};
for (int i = 1; i <= 63; i++, base_presentation_ts_ += vsync_interval) {
MockFrameProduction(pattern[i % 5], base_presentation_ts_);
}
@ -225,7 +221,7 @@ TEST_F(PredictorJankTrackerTest, JankyFramePercentageNotEmitted) {
TEST_F(PredictorJankTrackerTest, JankyFramePercentageEmittedTwice) {
// Janky frames percentage should be emitted twice, 20% each
// since we have 100 frames with 20% jank in each scroll.
double pattern[5] = {50, 50, 50, 50, 10};
std::array<double, 5> pattern = {50, 50, 50, 50, 10};
for (int i = 1; i <= 128; i++, base_presentation_ts_ += vsync_interval) {
MockFrameProduction(pattern[i % 5], base_presentation_ts_);
}
@ -237,7 +233,7 @@ TEST_F(PredictorJankTrackerTest, JankyFramePercentageEmittedWhenReset) {
// Janky sequence with 20% janky frames, reporting should happen even if
// the scroll was reset to catch smaller scrolls and residue frames from
// previous scrolls.
double pattern[5] = {50, 50, 50, 50, 10};
std::array<double, 5> pattern = {50, 50, 50, 50, 10};
for (int i = 1; i <= 64; i++, base_presentation_ts_ += vsync_interval) {
MockFrameProduction(pattern[i % 5], base_presentation_ts_);
if (i == 25) {

@ -2,16 +2,12 @@
// 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 "cc/paint/discardable_image_map.h"
#include <stddef.h>
#include <algorithm>
#include <array>
#include <limits>
#include <memory>
@ -153,7 +149,7 @@ TEST_F(DiscardableImageMapTest, GetDiscardableImagesInRectTest) {
// |---|---|---|---|
// | x | | x | |
// |---|---|---|---|
PaintImage discardable_image[4][4];
std::array<std::array<PaintImage, 4>, 4> discardable_image;
for (int y = 0; y < 4; ++y) {
for (int x = 0; x < 4; ++x) {
if ((x + y) & 1) {
@ -223,7 +219,7 @@ TEST_F(DiscardableImageMapTest, GetDiscardableImagesInRectNonZeroLayer) {
// |---|---|---|---|
// | x | | x | |
// |---|---|---|---|
PaintImage discardable_image[4][4];
std::array<std::array<PaintImage, 4>, 4> discardable_image;
for (int y = 0; y < 4; ++y) {
for (int x = 0; x < 4; ++x) {
if ((x + y) & 1) {
@ -323,7 +319,7 @@ TEST_F(DiscardableImageMapTest, GetDiscardableImagesInRectOnePixelQuery) {
// |---|---|---|---|
// | x | | x | |
// |---|---|---|---|
PaintImage discardable_image[4][4];
std::array<std::array<PaintImage, 4>, 4> discardable_image;
for (int y = 0; y < 4; ++y) {
for (int x = 0; x < 4; ++x) {
if ((x + y) & 1) {
@ -628,7 +624,7 @@ TEST_F(DiscardableImageMapTest, GetDiscardableImagesInShader) {
// |---|---|---|---|
// | x | | x | |
// |---|---|---|---|
PaintImage discardable_image[4][4];
std::array<std::array<PaintImage, 4>, 4> discardable_image;
// Skia doesn't allow shader instantiation with non-invertible local
// transforms, so we can't let the scale drop all the way to 0.

@ -2,15 +2,11 @@
// 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 "cc/paint/display_item_list.h"
#include <stddef.h>
#include <array>
#include <vector>
#include "base/logging.h"
@ -575,10 +571,24 @@ TEST_F(DisplayItemListTest, AsValueWithOps) {
ASSERT_NE(nullptr, items);
ASSERT_EQ(7u, items->size());
const char* expected_names[] = {
"SaveOp", "ConcatOp", "SaveLayerOp", "TranslateOp",
"DrawRectOp", "RestoreOp", "RestoreOp"};
bool expected_has_skp[] = {false, true, true, true, true, false, false};
auto expected_names = std::to_array<const char*>({
"SaveOp",
"ConcatOp",
"SaveLayerOp",
"TranslateOp",
"DrawRectOp",
"RestoreOp",
"RestoreOp",
});
auto expected_has_skp = std::to_array<bool>({
false,
true,
true,
true,
true,
false,
false,
});
for (int i = 0; i < 7; ++i) {
const base::Value& item_value = (*items)[i];

@ -2,13 +2,9 @@
// 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 "cc/paint/solid_color_analyzer.h"
#include <array>
#include <optional>
#include "base/memory/ref_counted.h"
@ -328,11 +324,12 @@ TEST_F(SolidColorAnalyzerTest, ClipRRectCoversCanvas) {
PaintFlags flags;
flags.setColor(SkColors::kWhite);
struct {
struct Cases {
SkVector offset;
SkVector offset_scale;
bool expected;
} cases[] = {
};
auto cases = std::to_array<Cases>({
// Not within bounding box of |rr|.
{SkVector::Make(100, 100), SkVector::Make(100, 100), false},
@ -367,7 +364,7 @@ TEST_F(SolidColorAnalyzerTest, ClipRRectCoversCanvas) {
// In center
{SkVector::Make(-100, -100), SkVector::Make(-100, -100), true},
};
});
for (int case_scale = 0; case_scale < 2; ++case_scale) {
bool scaled = case_scale > 0;

@ -12,6 +12,8 @@
#include <stddef.h>
#include <stdint.h>
#include <array>
#include "base/containers/contains.h"
#include "base/memory/raw_ptr.h"
#include "base/test/test_simple_task_runner.h"
@ -465,8 +467,8 @@ class RasterBufferProviderPerfTest
unsigned num_raster_tasks,
unsigned num_image_decode_tasks) {
const size_t kNumVersions = 2;
TileTask::Vector image_decode_tasks[kNumVersions];
RasterTaskVector raster_tasks[kNumVersions];
std::array<TileTask::Vector, kNumVersions> image_decode_tasks;
std::array<RasterTaskVector, kNumVersions> raster_tasks;
for (size_t i = 0; i < kNumVersions; ++i) {
CreateImageDecodeTasks(num_image_decode_tasks, &image_decode_tasks[i]);
CreateRasterTasks(this, num_raster_tasks, image_decode_tasks[i],

@ -2,15 +2,11 @@
// 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 "cc/raster/raster_source.h"
#include <stddef.h>
#include <array>
#include <memory>
#include "base/memory/scoped_refptr.h"
@ -209,7 +205,7 @@ TEST(RasterSourceTest, PixelRefIteratorDiscardableRefsOneTile) {
FakeRecordingSource recording_source(layer_bounds);
PaintImage discardable_image[2][2];
std::array<std::array<PaintImage, 2>, 2> discardable_image;
discardable_image[0][0] = CreateDiscardablePaintImage(gfx::Size(32, 32));
discardable_image[0][1] = CreateDiscardablePaintImage(gfx::Size(32, 32));
discardable_image[1][1] = CreateDiscardablePaintImage(gfx::Size(32, 32));

@ -2,14 +2,10 @@
// 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 <stddef.h>
#include <stdint.h>
#include <array>
#include <memory>
#include <vector>
@ -130,9 +126,9 @@ class TaskGraphRunnerPerfTest : public testing::Test {
int num_tasks,
int num_leaf_tasks) {
const size_t kNumVersions = 2;
PerfTaskImpl::Vector top_level_tasks[kNumVersions];
PerfTaskImpl::Vector tasks[kNumVersions];
PerfTaskImpl::Vector leaf_tasks[kNumVersions];
std::array<PerfTaskImpl::Vector, kNumVersions> top_level_tasks;
std::array<PerfTaskImpl::Vector, kNumVersions> tasks;
std::array<PerfTaskImpl::Vector, kNumVersions> leaf_tasks;
for (size_t i = 0; i < kNumVersions; ++i) {
CreateTasks(num_top_level_tasks, &top_level_tasks[i]);
CreateTasks(num_tasks, &tasks[i]);

@ -6,6 +6,7 @@
#include <stddef.h>
#include <array>
#include <limits>
#include <vector>
@ -386,7 +387,7 @@ TEST_F(ResourcePoolTest, UpdateContentIdAndInvalidatedRect) {
gfx::Size size(100, 100);
viz::SharedImageFormat format = viz::SinglePlaneFormat::kRGBA_8888;
gfx::ColorSpace color_space;
uint64_t content_ids[] = {42, 43, 44};
auto content_ids = std::to_array<uint64_t>({42, 43, 44});
gfx::Rect invalidated_rect(20, 20, 10, 10);
gfx::Rect second_invalidated_rect(25, 25, 10, 10);
gfx::Rect expected_total_invalidated_rect(20, 20, 15, 15);
@ -432,7 +433,7 @@ TEST_F(ResourcePoolTest, LargeInvalidatedRect) {
gfx::Size size(100, 100);
viz::SharedImageFormat format = viz::SinglePlaneFormat::kRGBA_8888;
gfx::ColorSpace color_space;
uint64_t content_ids[] = {42, 43, 44};
auto content_ids = std::to_array<uint64_t>({42, 43, 44});
// This rect is too large to take the area of it.
gfx::Rect large_invalidated_rect(0, 0, std::numeric_limits<int>::max() / 2,
std::numeric_limits<int>::max() / 2);

@ -2,15 +2,12 @@
// 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 "cc/scheduler/scheduler_state_machine.h"
#include <stddef.h>
#include <array>
#include "base/test/gtest_util.h"
#include "base/test/scoped_feature_list.h"
#include "base/trace_event/trace_event.h"
@ -138,17 +135,19 @@ const char* ActionToString(SchedulerStateMachine::Action action) {
const bool kAnimateOnly = false;
const SchedulerStateMachine::BeginImplFrameState all_begin_impl_frame_states[] =
{
const auto all_begin_impl_frame_states =
std::to_array<SchedulerStateMachine::BeginImplFrameState>({
SchedulerStateMachine::BeginImplFrameState::IDLE,
SchedulerStateMachine::BeginImplFrameState::INSIDE_BEGIN_FRAME,
SchedulerStateMachine::BeginImplFrameState::INSIDE_DEADLINE,
};
});
const SchedulerStateMachine::BeginMainFrameState begin_main_frame_states[] = {
SchedulerStateMachine::BeginMainFrameState::IDLE,
SchedulerStateMachine::BeginMainFrameState::SENT,
SchedulerStateMachine::BeginMainFrameState::READY_TO_COMMIT};
const auto begin_main_frame_states =
std::to_array<SchedulerStateMachine::BeginMainFrameState>({
SchedulerStateMachine::BeginMainFrameState::IDLE,
SchedulerStateMachine::BeginMainFrameState::SENT,
SchedulerStateMachine::BeginMainFrameState::READY_TO_COMMIT,
});
// Exposes the protected state fields of the SchedulerStateMachine for testing
class StateMachine : public SchedulerStateMachine {
@ -897,14 +896,8 @@ TEST(SchedulerStateMachineTest, TestNextActionDrawsOnBeginImplFrame) {
// When not in BeginImplFrame deadline, or in BeginImplFrame deadline
// but not visible, don't draw.
size_t num_begin_main_frame_states =
sizeof(begin_main_frame_states) /
sizeof(SchedulerStateMachine::BeginMainFrameState);
size_t num_begin_impl_frame_states =
sizeof(all_begin_impl_frame_states) /
sizeof(SchedulerStateMachine::BeginImplFrameState);
for (size_t i = 0; i < num_begin_main_frame_states; ++i) {
for (size_t j = 0; j < num_begin_impl_frame_states; ++j) {
for (size_t i = 0; i < begin_main_frame_states.size(); ++i) {
for (size_t j = 0; j < all_begin_impl_frame_states.size(); ++j) {
StateMachine state(default_scheduler_settings);
state.SetVisible(true);
EXPECT_ACTION_UPDATE_STATE(
@ -931,7 +924,7 @@ TEST(SchedulerStateMachineTest, TestNextActionDrawsOnBeginImplFrame) {
// When in BeginImplFrame deadline we should always draw for SetNeedsRedraw
// except if we're ready to commit, in which case we expect a commit first.
for (size_t i = 0; i < num_begin_main_frame_states; ++i) {
for (size_t i = 0; i < begin_main_frame_states.size(); ++i) {
StateMachine state(default_scheduler_settings);
state.SetVisible(true);
EXPECT_ACTION_UPDATE_STATE(
@ -965,10 +958,7 @@ TEST(SchedulerStateMachineTest, TestNextActionDrawsOnBeginImplFrame) {
TEST(SchedulerStateMachineTest, TestNoBeginMainFrameStatesRedrawWhenInvisible) {
SchedulerSettings default_scheduler_settings;
size_t num_begin_main_frame_states =
sizeof(begin_main_frame_states) /
sizeof(SchedulerStateMachine::BeginMainFrameState);
for (size_t i = 0; i < num_begin_main_frame_states; ++i) {
for (size_t i = 0; i < begin_main_frame_states.size(); ++i) {
// There shouldn't be any drawing regardless of BeginImplFrame.
for (size_t j = 0; j < 2; ++j) {
StateMachine state(default_scheduler_settings);
@ -1000,10 +990,7 @@ TEST(SchedulerStateMachineTest, TestNoBeginMainFrameStatesRedrawWhenInvisible) {
TEST(SchedulerStateMachineTest, TestCanRedraw_StopsDraw) {
SchedulerSettings default_scheduler_settings;
size_t num_begin_main_frame_states =
sizeof(begin_main_frame_states) /
sizeof(SchedulerStateMachine::BeginMainFrameState);
for (size_t i = 0; i < num_begin_main_frame_states; ++i) {
for (size_t i = 0; i < begin_main_frame_states.size(); ++i) {
// There shouldn't be any drawing regardless of BeginImplFrame.
for (size_t j = 0; j < 2; ++j) {
StateMachine state(default_scheduler_settings);

@ -2,11 +2,7 @@
// 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 <array>
#include <memory>
#include <utility>
@ -249,12 +245,13 @@ TEST_F(SlimLayerTreeCompositorFrameTest, ChildOrder) {
auto root_layer = CreateSolidColorLayer(viewport_.size(), SkColors::kGray);
layer_tree_->SetRoot(root_layer);
scoped_refptr<SolidColorLayer> children[] = {
auto children = std::to_array<scoped_refptr<SolidColorLayer>>({
CreateSolidColorLayer(gfx::Size(10, 10), SkColors::kBlue),
CreateSolidColorLayer(gfx::Size(10, 10), SkColors::kGreen),
CreateSolidColorLayer(gfx::Size(10, 10), SkColors::kMagenta),
CreateSolidColorLayer(gfx::Size(10, 10), SkColors::kRed),
CreateSolidColorLayer(gfx::Size(10, 10), SkColors::kYellow)};
CreateSolidColorLayer(gfx::Size(10, 10), SkColors::kYellow),
});
// Build tree such that quads appear in child order.
// Quads are appended post order depth first, in reverse child order.
@ -273,10 +270,13 @@ TEST_F(SlimLayerTreeCompositorFrameTest, ChildOrder) {
children[1]->SetPosition(gfx::PointF(30.0f, 30.0f));
children[0]->SetPosition(gfx::PointF(10.0f, 10.0f));
gfx::Point expected_origins[] = {
gfx::Point(40.0f, 40.0f), gfx::Point(30.0f, 30.0f),
gfx::Point(20.0f, 20.0f), gfx::Point(10.0f, 10.0f),
gfx::Point(00.0f, 00.0f)};
auto expected_origins = std::to_array<gfx::Point>({
gfx::Point(40.0f, 40.0f),
gfx::Point(30.0f, 30.0f),
gfx::Point(20.0f, 20.0f),
gfx::Point(10.0f, 10.0f),
gfx::Point(00.0f, 00.0f),
});
viz::CompositorFrame frame = ProduceFrame();
ASSERT_EQ(frame.render_pass_list.size(), 1u);
@ -742,7 +742,7 @@ TEST_F(SlimLayerTreeCompositorFrameTest, NinePatchLayerAppendQuads) {
// Center.
AllOf(viz::IsTextureQuad(),
viz::HasRect(gfx::Rect(10, 10, 80, 80)))));
gfx::PointF expected_uv_top_left[] = {
auto expected_uv_top_left = std::to_array<gfx::PointF>({
gfx::PointF(0.0f, 0.0f), // Top left.
gfx::PointF(0.8f, 0.0f), // Top right.
gfx::PointF(0.0f, 0.8f), // Bottom left.
@ -752,8 +752,8 @@ TEST_F(SlimLayerTreeCompositorFrameTest, NinePatchLayerAppendQuads) {
gfx::PointF(0.8f, 0.2f), // Right.
gfx::PointF(0.2f, 0.8f), // Bottom.
gfx::PointF(0.2f, 0.2f), // Center.
};
gfx::PointF expected_uv_bottom_right[] = {
});
auto expected_uv_bottom_right = std::to_array<gfx::PointF>({
gfx::PointF(0.2f, 0.2f), // Top left.
gfx::PointF(1.0f, 0.2f), // Top right.
gfx::PointF(0.2f, 1.0f), // Bottom left.
@ -763,7 +763,7 @@ TEST_F(SlimLayerTreeCompositorFrameTest, NinePatchLayerAppendQuads) {
gfx::PointF(1.0f, 0.8f), // Right.
gfx::PointF(0.8f, 1.0f), // Bottom.
gfx::PointF(0.8f, 0.8f), // Center.
};
});
for (size_t i = 0; i < std::size(expected_uv_top_left); ++i) {
const viz::TextureDrawQuad* texture_quad =
viz::TextureDrawQuad::MaterialCast(pass->quad_list.ElementAt(i));

@ -2,13 +2,9 @@
// 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 "cc/tiles/mipmap_util.h"
#include <array>
#include <limits>
#include "testing/gtest/include/gtest/gtest.h"
@ -121,8 +117,12 @@ TEST(MipMapUtilTest, Rounding) {
// Ensures that we round up during mip calculation.
TEST(MipMapUtilTest, RoundUp) {
const gfx::Size src_sizes[] = {gfx::Size(3, 3), gfx::Size(5, 7),
gfx::Size(11, 14), gfx::Size(17, 31)};
const auto src_sizes = std::to_array<gfx::Size>({
gfx::Size(3, 3),
gfx::Size(5, 7),
gfx::Size(11, 14),
gfx::Size(17, 31),
});
for (int i = 0; i < 4; ++i) {
EXPECT_EQ(MipMapUtil::GetSizeForLevel(src_sizes[i], i + 1),
gfx::Size(2, 2));

@ -2,14 +2,11 @@
// 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 <stddef.h>
#include <stdint.h>
#include <array>
#include "base/lazy_instance.h"
#include "base/location.h"
#include "base/time/time.h"
@ -82,9 +79,11 @@ class TileManagerPerfTest : public TestLayerTreeHostBase {
void RunRasterQueueConstructTest(const std::string& test_name,
int layer_count) {
TreePriority priorities[] = {SAME_PRIORITY_FOR_BOTH_TREES,
SMOOTHNESS_TAKES_PRIORITY,
NEW_CONTENT_TAKES_PRIORITY};
auto priorities = std::to_array<TreePriority>({
SAME_PRIORITY_FOR_BOTH_TREES,
SMOOTHNESS_TAKES_PRIORITY,
NEW_CONTENT_TAKES_PRIORITY,
});
int priority_count = 0;
std::vector<FakePictureLayerImpl*> layers = CreateLayers(layer_count, 10);
@ -107,9 +106,11 @@ class TileManagerPerfTest : public TestLayerTreeHostBase {
void RunRasterQueueConstructAndIterateTest(const std::string& test_name,
int layer_count,
int tile_count) {
TreePriority priorities[] = {SAME_PRIORITY_FOR_BOTH_TREES,
SMOOTHNESS_TAKES_PRIORITY,
NEW_CONTENT_TAKES_PRIORITY};
auto priorities = std::to_array<TreePriority>({
SAME_PRIORITY_FOR_BOTH_TREES,
SMOOTHNESS_TAKES_PRIORITY,
NEW_CONTENT_TAKES_PRIORITY,
});
std::vector<FakePictureLayerImpl*> layers = CreateLayers(layer_count, 100);
for (auto* layer : layers)
@ -138,9 +139,11 @@ class TileManagerPerfTest : public TestLayerTreeHostBase {
void RunEvictionQueueConstructTest(const std::string& test_name,
int layer_count) {
TreePriority priorities[] = {SAME_PRIORITY_FOR_BOTH_TREES,
SMOOTHNESS_TAKES_PRIORITY,
NEW_CONTENT_TAKES_PRIORITY};
auto priorities = std::to_array<TreePriority>({
SAME_PRIORITY_FOR_BOTH_TREES,
SMOOTHNESS_TAKES_PRIORITY,
NEW_CONTENT_TAKES_PRIORITY,
});
int priority_count = 0;
std::vector<FakePictureLayerImpl*> layers = CreateLayers(layer_count, 10);
@ -168,9 +171,11 @@ class TileManagerPerfTest : public TestLayerTreeHostBase {
void RunEvictionQueueConstructAndIterateTest(const std::string& test_name,
int layer_count,
int tile_count) {
TreePriority priorities[] = {SAME_PRIORITY_FOR_BOTH_TREES,
SMOOTHNESS_TAKES_PRIORITY,
NEW_CONTENT_TAKES_PRIORITY};
auto priorities = std::to_array<TreePriority>({
SAME_PRIORITY_FOR_BOTH_TREES,
SMOOTHNESS_TAKES_PRIORITY,
NEW_CONTENT_TAKES_PRIORITY,
});
int priority_count = 0;
std::vector<FakePictureLayerImpl*> layers =

@ -2,14 +2,10 @@
// 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 <stddef.h>
#include <stdint.h>
#include <array>
#include <utility>
#include "base/containers/contains.h"
@ -1393,7 +1389,7 @@ TEST_F(TileManagerTilePriorityQueueTest,
EXPECT_TRUE(queue);
// There are 3 bins in TilePriority.
bool have_tiles[3] = {};
std::array<bool, 3> have_tiles = {};
// On the third iteration, we should get no tiles since everything was
// marked as ready to draw.
@ -1497,7 +1493,7 @@ TEST_F(TileManagerTilePriorityQueueTest,
soon_rect.Inset(-soon_border_outset);
// There are 3 bins in TilePriority.
bool have_tiles[3] = {};
std::array<bool, 3> have_tiles = {};
PrioritizedTile last_tile;
int eventually_bin_order_correct_count = 0;
int eventually_bin_order_incorrect_count = 0;
@ -2099,7 +2095,8 @@ class PixelInspectTileManagerTest : public TileManagerTest {
TEST_F(PixelInspectTileManagerTest, LowResHasNoImage) {
gfx::Size size(10, 12);
TileResolution resolutions[] = {HIGH_RESOLUTION, LOW_RESOLUTION};
auto resolutions =
std::to_array<TileResolution>({HIGH_RESOLUTION, LOW_RESOLUTION});
host_impl()->CreatePendingTree();
for (size_t i = 0; i < std::size(resolutions); ++i) {

@ -2,13 +2,9 @@
// 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 "cc/trees/frame_rate_estimator.h"
#include <array>
#include <memory>
#include "base/test/scoped_feature_list.h"
@ -90,11 +86,16 @@ TEST_F(FrameRateEstimatorTest, InputPriorityMode) {
TEST_F(FrameRateEstimatorTest, RafAtHalfFps) {
estimator_->SetVideoConferenceMode(true);
// Recorded rAF intervals at 30 fps.
const base::TimeDelta kIntervals[] = {
base::Microseconds(33425), base::Microseconds(33298),
base::Microseconds(33396), base::Microseconds(33339),
base::Microseconds(33431), base::Microseconds(33320),
base::Microseconds(33364), base::Microseconds(33360)};
const auto kIntervals = std::to_array<base::TimeDelta>({
base::Microseconds(33425),
base::Microseconds(33298),
base::Microseconds(33396),
base::Microseconds(33339),
base::Microseconds(33431),
base::Microseconds(33320),
base::Microseconds(33364),
base::Microseconds(33360),
});
const base::TimeDelta kIntervalForHalfFps =
viz::BeginFrameArgs::DefaultInterval() * 2;
base::TimeTicks time;

@ -2,15 +2,11 @@
// 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 "cc/trees/layer_tree_host_impl.h"
#include <stddef.h>
#include <array>
#include <cmath>
#include <memory>
#include <optional>
@ -9221,13 +9217,13 @@ TEST_F(CommitToActiveTreeLayerTreeHostImplTest,
std::unique_ptr<CompositorCommitData> commit_data;
gfx::Vector2dF gesture_scroll_deltas[4];
std::array<gfx::Vector2dF, 4> gesture_scroll_deltas;
gesture_scroll_deltas[0] = gfx::Vector2dF(4, 10);
gesture_scroll_deltas[1] = gfx::Vector2dF(4, 10);
gesture_scroll_deltas[2] = gfx::Vector2dF(10, 0);
gesture_scroll_deltas[3] = gfx::Vector2dF(10, 0);
gfx::Vector2dF expected_scroll_deltas[4];
std::array<gfx::Vector2dF, 4> expected_scroll_deltas;
// Perspective affects the vertical delta by a different
// amount depending on the vertical position of the |viewport_point|.
expected_scroll_deltas[0] = gfx::Vector2dF(2, 9);

@ -2,13 +2,10 @@
// 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 <stdint.h>
#include <array>
#include "build/build_config.h"
#include "cc/layers/solid_color_layer.h"
#include "cc/paint/paint_image.h"
@ -39,7 +36,7 @@ SkBlendMode const kBlendModes[] = {
SkBlendMode::kHue, SkBlendMode::kSaturation,
SkBlendMode::kColor, SkBlendMode::kLuminosity};
SkColor kCSSTestColors[] = {
auto kCSSTestColors = std::to_array<SkColor>({
0xffff0000, // red
0xff00ff00, // lime
0xff0000ff, // blue
@ -59,8 +56,8 @@ SkColor kCSSTestColors[] = {
0x80000000, // black with transparency
0xffffffff, // white
0x80ffffff, // white with transparency
0x00000000 // transparent
};
0x00000000, // transparent
});
const int kCSSTestColorsCount = std::size(kCSSTestColors);

@ -2,13 +2,10 @@
// 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 <stddef.h>
#include <array>
#include "build/build_config.h"
#include "cc/layers/content_layer_client.h"
#include "cc/layers/picture_layer.h"
@ -821,11 +818,12 @@ class LayerTreeHostMaskAsBlendingPixelTest
// Creates a layer consists of solid grids. The grids are in a mix of
// different transparency and colors (1 transparent, 3 semi-transparent,
// and 3 opaque).
static SkColor test_colors[7] = {
static std::array<SkColor, 7> test_colors = {
SkColorSetARGB(128, 255, 0, 0), SkColorSetARGB(255, 0, 0, 255),
SkColorSetARGB(128, 0, 255, 0), SkColorSetARGB(128, 0, 0, 255),
SkColorSetARGB(255, 0, 255, 0), SkColorSetARGB(0, 0, 0, 0),
SkColorSetARGB(255, 255, 0, 0)};
SkColorSetARGB(255, 255, 0, 0),
};
auto display_list = base::MakeRefCounted<DisplayItemList>();
display_list->StartPaint();

@ -2,14 +2,11 @@
// 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 <stddef.h>
#include <stdint.h>
#include <array>
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "build/build_config.h"
@ -242,7 +239,7 @@ class LayerTreeHostContextTestLostContextSucceeds
}
bool NextTestCase() {
static const TestCase kTests[] = {
static const auto kTests = std::to_array<TestCase>({
// Losing the context and failing to recreate it (or losing it again
// immediately) a small number of times should succeed.
{
@ -326,7 +323,7 @@ class LayerTreeHostContextTestLostContextSucceeds
true, // fallback_context_works
true, // async_layer_tree_frame_sink_creation
},
};
});
if (test_case_ >= std::size(kTests))
return false;

@ -11,6 +11,8 @@
#include <stddef.h>
#include <array>
#include "testing/gtest/include/gtest/gtest.h"
namespace cc {
@ -48,10 +50,12 @@ TEST(OcclusionTest, HasOcclusion) {
}
TEST(OcclusionTest, IsOccludedNoTransform) {
gfx::Rect rects[] = {gfx::Rect(10, 10),
gfx::Rect(10, 0, 10, 10),
gfx::Rect(0, 10, 10, 10),
gfx::Rect(10, 10, 10, 10)};
auto rects = std::to_array<gfx::Rect>({
gfx::Rect(10, 10),
gfx::Rect(10, 0, 10, 10),
gfx::Rect(0, 10, 10, 10),
gfx::Rect(10, 10, 10, 10),
});
Occlusion no_occlusion;
EXPECT_OCCLUSION(no_occlusion, rects, false, false, false, false);
@ -76,10 +80,12 @@ TEST(OcclusionTest, IsOccludedNoTransform) {
}
TEST(OcclusionTest, IsOccludedScaled) {
gfx::Rect rects[] = {gfx::Rect(10, 10),
gfx::Rect(10, 0, 10, 10),
gfx::Rect(0, 10, 10, 10),
gfx::Rect(10, 10, 10, 10)};
auto rects = std::to_array<gfx::Rect>({
gfx::Rect(10, 10),
gfx::Rect(10, 0, 10, 10),
gfx::Rect(0, 10, 10, 10),
gfx::Rect(10, 10, 10, 10),
});
gfx::Transform half_scale;
half_scale.Scale(0.5, 0.5);
@ -120,10 +126,12 @@ TEST(OcclusionTest, IsOccludedScaled) {
}
TEST(OcclusionTest, IsOccludedTranslated) {
gfx::Rect rects[] = {gfx::Rect(10, 10),
gfx::Rect(10, 0, 10, 10),
gfx::Rect(0, 10, 10, 10),
gfx::Rect(10, 10, 10, 10)};
auto rects = std::to_array<gfx::Rect>({
gfx::Rect(10, 10),
gfx::Rect(10, 0, 10, 10),
gfx::Rect(0, 10, 10, 10),
gfx::Rect(10, 10, 10, 10),
});
gfx::Transform move_left;
move_left.Translate(-100, 0);
@ -165,10 +173,12 @@ TEST(OcclusionTest, IsOccludedTranslated) {
}
TEST(OcclusionTest, IsOccludedScaledAfterConstruction) {
gfx::Rect rects[] = {gfx::Rect(10, 10),
gfx::Rect(10, 0, 10, 10),
gfx::Rect(0, 10, 10, 10),
gfx::Rect(10, 10, 10, 10)};
auto rects = std::to_array<gfx::Rect>({
gfx::Rect(10, 10),
gfx::Rect(10, 0, 10, 10),
gfx::Rect(0, 10, 10, 10),
gfx::Rect(10, 10, 10, 10),
});
gfx::Transform half_transform;
half_transform.Scale(0.5, 0.5);