1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "flutter/flow/layers/offscreen_surface.h"
6
7#include <memory>
8
9#include "gtest/gtest.h"
10#include "include/core/SkColor.h"
11#include "third_party/skia/include/core/SkCanvas.h"
12#include "third_party/skia/include/core/SkData.h"
13
14namespace flutter::testing {
15
16TEST(OffscreenSurfaceTest, EmptySurfaceIsInvalid) {
17 auto surface =
18 std::make_unique<OffscreenSurface>(args: nullptr, args: SkISize::MakeEmpty());
19 ASSERT_FALSE(surface->IsValid());
20}
21
22TEST(OffscreenSurfaceTest, OnexOneSurfaceIsValid) {
23 auto surface =
24 std::make_unique<OffscreenSurface>(args: nullptr, args: SkISize::Make(w: 1, h: 1));
25 ASSERT_TRUE(surface->IsValid());
26}
27
28TEST(OffscreenSurfaceTest, PaintSurfaceBlack) {
29 auto surface =
30 std::make_unique<OffscreenSurface>(args: nullptr, args: SkISize::Make(w: 1, h: 1));
31
32 DlCanvas* canvas = surface->GetCanvas();
33 canvas->Clear(color: DlColor::kBlack());
34 canvas->Flush();
35
36 auto raster_data = surface->GetRasterData(compressed: false);
37 const uint32_t* actual =
38 reinterpret_cast<const uint32_t*>(raster_data->data());
39
40 // picking black as the color since byte ordering seems to matter.
41 ASSERT_EQ(actual[0], 0xFF000000u);
42}
43
44} // namespace flutter::testing
45

source code of flutter_engine/flutter/flow/layers/offscreen_surface_unittests.cc