Flutter Engine
The Flutter Engine
Functions
LazyStencilAttachmentTest.cpp File Reference
#include "include/core/SkAlphaType.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/SkPath.h"
#include "include/core/SkPathTypes.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 "src/core/SkAutoPixmapStorage.h"
#include "tests/CtsEnforcement.h"
#include "tests/Test.h"
#include <initializer_list>

Go to the source code of this file.

Functions

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

Function Documentation

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS()

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

Definition at line 33 of file LazyStencilAttachmentTest.cpp.

36 {
37 GrDirectContext* dc = context_info.directContext();
38
39 // Make sure we don't get recycled render targets that already have stencil attachments.
40 dc->freeGpuResources();
41
42 SkImageInfo ii = SkImageInfo::Make({100, 100},
45 nullptr);
48
49 // Make sure the surfaces' proxies are instantiated without stencil. Creating textures lazily
50 // can invalidate the current tracked FBO since FBO state must be modified to during
51 // GrGLRenderTarget creation.
52 for (int i = 0; i < 2; ++i) {
53 surfs[i]->getCanvas()->clear(SK_ColorWHITE);
54 dc->flushAndSubmit(surfs[i].get(), GrSyncCpu::kNo);
55 }
56
57 auto drawWithStencilClip = [&](SkSurface& surf, SkColor color) {
59 clip.addCircle(50, 50, 50);
62 paint.setColor(color);
63 surf.getCanvas()->clipPath(clip, false);
64 surf.getCanvas()->drawRect(SkRect::MakeLTRB(0,0, 100, 100), paint);
65 };
66
67 // Use surfs[0] create to create a cached stencil buffer that is also sized for surfs[1].
68 drawWithStencilClip(*surfs[0], SK_ColorRED);
69 dc->flushAndSubmit(surfs[0].get(), GrSyncCpu::kNo);
70
71 // Make sure surf[1]'s FBO is bound but without using draws that would attach stencil.
72 surfs[1]->getCanvas()->clear(SK_ColorGREEN);
73 dc->flushAndSubmit(surfs[1].get(), GrSyncCpu::kNo);
74
75 // Now use stencil for clipping. We should now have the following properties:
76 // 1) surf[1]'s FBO is already bound
77 // 2) surf[1] doesn't have a stencil buffer
78 // 3) There is an appropriately sized stencil buffer in the cache (used with surf[0]). This is
79 // important because creating a new stencil buffer will invalidate the bound FBO tracking.
80 // The bug was that because the correct FBO was already bound we would not rebind and would
81 // skip the lazy stencil attachment in GrGLRenderTarget. This would cause the clip to fail.
82 drawWithStencilClip(*surfs[1], SK_ColorBLUE);
83
84 // Check that four pixels that should have been clipped out of the blue draw are green.
86 rb.alloc(surfs[1]->imageInfo().makeWH(1, 1));
87 for (int x : {5, 95}) {
88 for (int y : {5, 95}) {
89 if (!surfs[1]->readPixels(rb, x, y)) {
90 ERRORF(reporter, "readback failed");
91 return;
92 }
93 if (*rb.addr32() != SK_ColorGREEN) {
95 "Expected green at (%d, %d), instead got 0x%08x.",
96 x,
97 y,
98 *rb.addr32());
99 return;
100 }
101 }
102 }
103}
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
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_ColorGREEN
Definition: SkColor.h:131
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition: SkPath.cpp:3892
#define ERRORF(r,...)
Definition: Test.h:293
void flushAndSubmit(GrSyncCpu sync=GrSyncCpu::kNo)
void alloc(const SkImageInfo &)
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void clear(SkColor color)
Definition: SkCanvas.h:1199
void clipPath(const SkPath &path, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1456
Definition: SkPath.h:59
SkPath & addCircle(SkScalar x, SkScalar y, SkScalar radius, SkPathDirection dir=SkPathDirection::kCW)
Definition: SkPath.cpp:1213
const uint32_t * addr32() const
Definition: SkPixmap.h:352
SkCanvas * getCanvas()
Definition: SkSurface.cpp:82
const Paint & paint
Definition: color_source.cc:38
DlColor color
double y
double x
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)
const myers::Point & get(const myers::Segment &)
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646