Flutter Engine
The Flutter Engine
MultisampleTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2022 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "tests/Test.h"
9
12#include "include/core/SkPath.h"
19
20namespace skgpu::graphite {
21
22// Tests that a drawing with MSAA will have contents retained between recordings.
23// This is for testing MSAA load from resolve feature.
24// TODO(b/296420752): enable in CTS after adding VK support for loading MSAA from Resolve
25DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS(MultisampleRetainTest, reporter, context,
27 const SkImageInfo surfaceImageInfo = SkImageInfo::Make(
29
30 std::unique_ptr<Recorder> surfaceRecorder = context->makeRecorder();
31 sk_sp<SkSurface> surface = SkSurfaces::RenderTarget(surfaceRecorder.get(), surfaceImageInfo);
32
33 // Clear entire surface to red
34 SkCanvas* surfaceCanvas = surface->getCanvas();
35 surfaceCanvas->clear(SkColors::kRed);
36 std::unique_ptr<Recording> surfaceRecording = surfaceRecorder->snap();
37 // Flush the clearing
38 context->insertRecording({surfaceRecording.get()});
39
40 // Draw a blue path. The old red background should be retained between recordings.
42 paint.setStrokeWidth(3);
43 paint.setColor(SkColors::kBlue);
44 paint.setStyle(SkPaint::Style::kStroke_Style);
45
47 constexpr int kPathPoints[][2] = {
48 {3, 2},
49 {3, 4},
50 {6, 8},
51 {3, 15},
52 };
53
54 for (size_t i = 0; i < std::size(kPathPoints); ++i) {
55 path.lineTo(kPathPoints[i][0], kPathPoints[i][1]);
56 }
57
58 surfaceCanvas->drawPath(path, paint);
59
60 std::unique_ptr<Recording> surfaceRecording2 = surfaceRecorder->snap();
61 // Play back recording.
62 context->insertRecording({surfaceRecording2.get()});
63
64 // Read pixels.
66 bitmap.allocPixels(surfaceImageInfo);
67 if (!surface->readPixels(bitmap, 0, 0)) {
68 ERRORF(reporter, "readPixels failed");
69 return;
70 }
71
72 // Verify recording was replayed.
73 REPORTER_ASSERT(reporter, bitmap.getColor4f(8, 0) == SkColors::kRed);
74 REPORTER_ASSERT(reporter, bitmap.getColor4f(0, 8) == SkColors::kRed);
75 REPORTER_ASSERT(reporter, bitmap.getColor4f(15, 14) == SkColors::kRed);
76
77 // Verify points on the path have blue color. We don't verify last point because it is on the
78 // edge of the path thus might have blurry color.
79 for (size_t i = 0; i < std::size(kPathPoints) - 1; ++i) {
81 bitmap.getColor4f(kPathPoints[i][0], kPathPoints[i][1]) == SkColors::kBlue);
82 }
83}
84
85} // namespace skgpu::graphite
reporter
Definition: FontMgrTest.cpp:39
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition: SkColorType.h:24
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
#define ERRORF(r,...)
Definition: Test.h:293
void clear(SkColor color)
Definition: SkCanvas.h:1199
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
Definition: SkPath.h:59
const Paint & paint
Definition: color_source.cc:38
VkSurfaceKHR surface
Definition: main.cc:49
constexpr SkColor4f kRed
Definition: SkColor.h:440
constexpr SkColor4f kBlue
Definition: SkColor.h:442
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)
Definition: bitmap.py:1
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS(DeviceTestVertexTransparency, reporter, context, CtsEnforcement::kNextRelease)
Definition: DeviceTest.cpp:21
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)