Flutter Engine
The Flutter Engine
Skbug6653.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2017 Google Inc.
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
15#include "include/core/SkRect.h"
21#include "include/gpu/GrTypes.h"
25#include "tests/Test.h"
26
27#include <cstdint>
28
30struct GrContextOptions;
31
33 SkBitmap bmp;
34 bmp.allocN32Pixels(surface->width(), surface->height());
35 bmp.eraseColor(initColor);
36 if (!surface->readPixels(bmp, 0, 0)) {
37 SkDebugf("readPixels failed\n");
38 }
39 return bmp;
40}
41
46}
47
48static void test_bug_6653(GrDirectContext* dContext,
50 const char* label) {
51 SkRect rect = SkRect::MakeWH(50, 50);
52
54 paint.setColor(SK_ColorWHITE);
55 paint.setStrokeWidth(5);
57
58 // The one device that fails this test (Galaxy S6) does so in a flaky fashion. Trying many
59 // times makes it more likely to fail. Also, interacting with the phone (eg swiping between
60 // different home screens) while the test is running makes it fail close to 100%.
61 static const int kNumIterations = 50;
62
63 for (int i = 0; i < kNumIterations; ++i) {
64 auto s0 = make_surface(dContext);
65 if (!s0) {
66 // MSAA may not be supported
67 return;
68 }
69
70 auto s1 = make_surface(dContext);
71 s1->getCanvas()->clear(SK_ColorBLACK);
72 s1->getCanvas()->drawOval(rect, paint);
74 s1 = nullptr;
75
76 // The bug requires that all three of the following surfaces are cleared to the same color
77 auto s2 = make_surface(dContext);
78 s2->getCanvas()->clear(SK_ColorBLUE);
80 s2 = nullptr;
81
82 auto s3 = make_surface(dContext);
83 s3->getCanvas()->clear(SK_ColorBLUE);
84 s0->getCanvas()->drawImage(read_pixels(s3, SK_ColorBLACK).asImage(), 0, 0);
85 s3 = nullptr;
86
87 auto s4 = make_surface(dContext);
88 s4->getCanvas()->clear(SK_ColorBLUE);
89 s4->getCanvas()->drawOval(rect, paint);
90
91 // When this fails, b4 will "succeed", but return an empty bitmap (containing just the
92 // clear color). Regardless, b5 will contain the oval that was just drawn, so diffing the
93 // two bitmaps tests for the failure case. Initialize the bitmaps to different colors so
94 // that if the readPixels doesn't work, this test will always fail.
97
98 bool match = true;
99 for (int y = 0; y < b4.height() && match; ++y) {
100 for (int x = 0; x < b4.width() && match; ++x) {
101 uint32_t pixelA = *b4.getAddr32(x, y);
102 uint32_t pixelB = *b5.getAddr32(x, y);
103 if (pixelA != pixelB) {
104 match = false;
105 }
106 }
107 }
108
109 REPORTER_ASSERT(reporter, match, "%s", label);
110 }
111}
112
113// Tests that readPixels returns up-to-date results. This has failed on several GPUs,
114// from multiple vendors, in MSAA mode.
116 auto ctx = ctxInfo.directContext();
117 test_bug_6653(ctx, reporter, "Default");
118}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
reporter
Definition: FontMgrTest.cpp:39
@ kBottomLeft_GrSurfaceOrigin
Definition: GrTypes.h:149
@ 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
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(skbug6653, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
Definition: Skbug6653.cpp:115
static void test_bug_6653(GrDirectContext *dContext, skiatest::Reporter *reporter, const char *label)
Definition: Skbug6653.cpp:48
static SkBitmap read_pixels(sk_sp< SkSurface > surface, SkColor initColor)
Definition: Skbug6653.cpp:32
static sk_sp< SkSurface > make_surface(GrRecordingContext *rContext)
Definition: Skbug6653.cpp:42
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
int width() const
Definition: SkBitmap.h:149
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition: SkBitmap.cpp:232
int height() const
Definition: SkBitmap.h:158
uint32_t * getAddr32(int x, int y) const
Definition: SkBitmap.h:1260
void eraseColor(SkColor4f) const
Definition: SkBitmap.cpp:442
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
const Paint & paint
Definition: color_source.cc:38
VkSurfaceKHR surface
Definition: main.cc:49
double y
double x
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
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)
def match(bench, filt)
Definition: benchmark.py:23
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609