Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
Skbug6653.cpp File Reference
#include "include/core/SkAlphaType.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorType.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GpuTypes.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrTypes.h"
#include "include/gpu/ganesh/SkSurfaceGanesh.h"
#include "include/private/base/SkDebug.h"
#include "tests/CtsEnforcement.h"
#include "tests/Test.h"
#include <cstdint>

Go to the source code of this file.

Functions

static SkBitmap read_pixels (sk_sp< SkSurface > surface, SkColor initColor)
 
static sk_sp< SkSurfacemake_surface (GrRecordingContext *rContext)
 
static void test_bug_6653 (GrDirectContext *dContext, skiatest::Reporter *reporter, const char *label)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (skbug6653, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 

Function Documentation

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS()

DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS ( skbug6653  ,
reporter  ,
ctxInfo  ,
CtsEnforcement::kApiLevel_T   
)

Definition at line 115 of file Skbug6653.cpp.

115 {
116 auto ctx = ctxInfo.directContext();
117 test_bug_6653(ctx, reporter, "Default");
118}
reporter
static void test_bug_6653(GrDirectContext *dContext, skiatest::Reporter *reporter, const char *label)
Definition Skbug6653.cpp:48

◆ make_surface()

static sk_sp< SkSurface > make_surface ( GrRecordingContext rContext)
static

Definition at line 42 of file Skbug6653.cpp.

42 {
46}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
@ 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
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)

◆ read_pixels()

static SkBitmap read_pixels ( sk_sp< SkSurface surface,
SkColor  initColor 
)
static

Definition at line 32 of file Skbug6653.cpp.

32 {
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}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition SkBitmap.cpp:232
void eraseColor(SkColor4f) const
Definition SkBitmap.cpp:442
VkSurfaceKHR surface
Definition main.cc:49

◆ test_bug_6653()

static void test_bug_6653 ( GrDirectContext dContext,
skiatest::Reporter reporter,
const char *  label 
)
static

Definition at line 48 of file Skbug6653.cpp.

50 {
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}
static bool match(const char *needle, const char *haystack)
Definition DM.cpp:1132
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
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
int height() const
Definition SkBitmap.h:158
uint32_t * getAddr32(int x, int y) const
Definition SkBitmap.h:1260
@ kStroke_Style
set to stroke geometry
Definition SkPaint.h:194
const Paint & paint
double y
double x
sk_sp< SkBlender > blender SkRect rect
Definition SkRecords.h:350
static constexpr SkRect MakeWH(float w, float h)
Definition SkRect.h:609