Flutter Engine
The Flutter Engine
Functions
SaveLayerOriginTest.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/SkColorSpace.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/gpu/GpuTypes.h"
#include "include/gpu/GrBackendSurface.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrTypes.h"
#include "include/gpu/ganesh/SkSurfaceGanesh.h"
#include "include/private/gpu/ganesh/GrTypesPriv.h"
#include "src/gpu/ganesh/GrDirectContextPriv.h"
#include "tests/CtsEnforcement.h"
#include "tests/Test.h"
#include <cstdint>

Go to the source code of this file.

Functions

static void check_pixels (skiatest::Reporter *reporter, const SkBitmap &bitmap, GrSurfaceOrigin origin)
 
static void run_test (skiatest::Reporter *reporter, GrDirectContext *context, GrSurfaceOrigin origin)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (SaveLayerOrigin, reporter, context_info, CtsEnforcement::kApiLevel_T)
 

Function Documentation

◆ check_pixels()

static void check_pixels ( skiatest::Reporter reporter,
const SkBitmap bitmap,
GrSurfaceOrigin  origin 
)
static

Definition at line 33 of file SaveLayerOriginTest.cpp.

34 {
35 const uint32_t* canvasPixels = static_cast<const uint32_t*>(bitmap.getPixels());
36
37 bool failureFound = false;
38 bool foundNonBlue = false;
39
40 for (int cy = 0; cy < 8 && !failureFound; ++cy) {
41 int cx = 4; // Just need to check one column;
42 SkPMColor canvasPixel = canvasPixels[cy * 8 + cx];
43 // We don't know which way the GPU will snap so the non-blue line could either be at row
44 // 3 or 4 since we drew the line at a y value of 4. We check that one of those two values
45 // is green and all the rest are blue. The key thing is that we should not get any red
46 // values since the green line in the saveLayer should snap the same way and overwrite the
47 // red line.
48 if (cy == 3) {
49 if (canvasPixel != 0xFFFF0000 && canvasPixel != 0xFF00FF00) {
50 failureFound = true;
51 ERRORF(reporter, "Wrong color at %d, %d. Got 0x%08x when we expected Blue or Green."
52 " Origin is: %s",
53 cx, cy, canvasPixel, GrSurfaceOriginToStr(origin));
54 }
55 if (canvasPixel != 0XFFFF0000) {
56 foundNonBlue = true;
57 }
58 } else {
59 SkPMColor expectedPixel;
60 if (cy == 4 && !foundNonBlue) {
61 expectedPixel = 0xFF00FF00; // Green
62 } else {
63 expectedPixel = 0xFFFF0000; // Blue
64 }
65 if (canvasPixel != expectedPixel) {
66 failureFound = true;
68 "Wrong color at %d, %d. Got 0x%08x when we expected 0x%08x. Origin is: %s",
69 cx, cy, canvasPixel, expectedPixel, GrSurfaceOriginToStr(origin));
70 }
71 }
72 }
73}
reporter
Definition: FontMgrTest.cpp:39
uint32_t SkPMColor
Definition: SkColor.h:205
#define ERRORF(r,...)
Definition: Test.h:293
Definition: bitmap.py:1

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS()

DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS ( SaveLayerOrigin  ,
reporter  ,
context_info  ,
CtsEnforcement::kApiLevel_T   
)

Definition at line 124 of file SaveLayerOriginTest.cpp.

127 {
128 GrDirectContext* context = context_info.directContext();
131}
@ kBottomLeft_GrSurfaceOrigin
Definition: GrTypes.h:149
@ kTopLeft_GrSurfaceOrigin
Definition: GrTypes.h:148
static void run_test(skiatest::Reporter *reporter, GrDirectContext *context, GrSurfaceOrigin origin)

◆ run_test()

static void run_test ( skiatest::Reporter reporter,
GrDirectContext context,
GrSurfaceOrigin  origin 
)
static

Definition at line 75 of file SaveLayerOriginTest.cpp.

77 {
78 using namespace skgpu;
79
80 Protected isProtected = Protected(context->priv().caps()->supportsProtectedContent());
81
82 auto beTexture = context->createBackendTexture(8,
83 8,
87 isProtected);
88 REPORTER_ASSERT(reporter, beTexture.isValid());
89 if (!beTexture.isValid()) {
90 return;
91 }
92
94 context, beTexture, origin, 0, kRGBA_8888_SkColorType, nullptr, nullptr);
96 if (!surface) {
97 return;
98 }
99
100 SkCanvas* canvas = surface->getCanvas();
101
102 canvas->clear(SK_ColorBLUE);
103
105 paint.setColor(SK_ColorRED);
106 canvas->drawLine({ 0,4 }, { 8,4 }, paint);
107
109 SkPaint layerPaint;
110 canvas->saveLayer(bounds, &paint);
111 paint.setColor(SK_ColorGREEN);
112 canvas->drawLine({ 0,4 }, { 8,4 }, paint);
113 canvas->restore();
114
117 surface->readPixels(bitmap, 0, 0);
118
119 check_pixels(reporter, bitmap, origin);
120
121 context->deleteBackendTexture(beTexture);
122}
skgpu::Protected Protected
static void check_pixels(skiatest::Reporter *reporter, const SkBitmap &bitmap, GrSurfaceOrigin origin)
@ 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
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
const GrCaps * caps() const
bool supportsProtectedContent() const
Definition: GrCaps.h:422
void deleteBackendTexture(const GrBackendTexture &)
GrBackendTexture createBackendTexture(int width, int height, const GrBackendFormat &, skgpu::Mipmapped, GrRenderable, GrProtected=GrProtected::kNo, std::string_view label={})
GrDirectContextPriv priv()
int saveLayer(const SkRect *bounds, const SkPaint *paint)
Definition: SkCanvas.cpp:496
void restore()
Definition: SkCanvas.cpp:461
void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint &paint)
Definition: SkCanvas.cpp:2700
void clear(SkColor color)
Definition: SkCanvas.h:1199
const Paint & paint
Definition: color_source.cc:38
VkSurfaceKHR surface
Definition: main.cc:49
Optional< SkRect > bounds
Definition: SkRecords.h:189
SK_API sk_sp< SkSurface > WrapBackendTexture(GrRecordingContext *context, const GrBackendTexture &backendTexture, GrSurfaceOrigin origin, int sampleCnt, SkColorType colorType, sk_sp< SkColorSpace > colorSpace, const SkSurfaceProps *surfaceProps, TextureReleaseProc textureReleaseProc=nullptr, ReleaseContext releaseContext=nullptr)
Definition: GpuTools.h:21
Protected
Definition: GpuTypes.h:61
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609