Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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);
45
46 SkPath path;
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
@ 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 DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS(name, reporter, graphite_ctx, ctsEnforcement)
Definition Test.h:373
#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)
@ kStroke_Style
set to stroke geometry
Definition SkPaint.h:194
const Paint & paint
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)
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)