Flutter Engine
The Flutter Engine
Functions
GrOpListFlushTest.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/SkImage.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkSamplingOptions.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GpuTypes.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/ganesh/SkSurfaceGanesh.h"
#include "src/gpu/ganesh/GrDirectContextPriv.h"
#include "src/gpu/ganesh/GrGpu.h"
#include "tests/CtsEnforcement.h"
#include "tests/Test.h"
#include <cstdint>

Go to the source code of this file.

Functions

static bool check_read (skiatest::Reporter *reporter, const SkBitmap &bitmap)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (OpsTaskFlushCount, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 

Function Documentation

◆ check_read()

static bool check_read ( skiatest::Reporter reporter,
const SkBitmap bitmap 
)
static

Definition at line 33 of file GrOpListFlushTest.cpp.

33 {
34 bool result = true;
35 for (int x = 0; x < 1000 && result; ++x) {
36 const uint32_t srcPixel = *bitmap.getAddr32(x, 0);
37 if (srcPixel != SK_ColorGREEN) {
38 ERRORF(reporter, "Expected color of Green, but got 0x%08x, at pixel (%d, 0).",
39 srcPixel, x);
40 result = false;
41 }
42 }
43 return result;
44}
reporter
Definition: FontMgrTest.cpp:39
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
#define ERRORF(r,...)
Definition: Test.h:293
GAsyncResult * result
double x
Definition: bitmap.py:1

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS()

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

Definition at line 46 of file GrOpListFlushTest.cpp.

49 {
50 auto context = ctxInfo.directContext();
51 GrGpu* gpu = context->priv().getGpu();
52
54
56 if (!surface1) {
57 return;
58 }
60 if (!surface2) {
61 return;
62 }
63
64 SkCanvas* canvas1 = surface1->getCanvas();
65 SkCanvas* canvas2 = surface2->getCanvas();
66
67 canvas1->clear(SK_ColorRED);
68 canvas2->clear(SK_ColorRED);
69
70 SkRect srcRect = SkRect::MakeWH(1, 1);
71 SkRect dstRect = SkRect::MakeWH(1, 1);
73 paint.setColor(SK_ColorGREEN);
74 canvas1->drawRect(dstRect, paint);
75
76 for (int i = 0; i < 1000; ++i) {
77 srcRect.fLeft = i;
78 srcRect.fRight = srcRect.fLeft + 1;
79
81 canvas2->drawImageRect(image.get(), srcRect, dstRect, SkSamplingOptions(), nullptr,
83 if (i != 999) {
84 dstRect.fLeft = i+1;
85 dstRect.fRight = dstRect.fLeft + 1;
86 image = surface2->makeImageSnapshot();
87 canvas1->drawImageRect(image.get(), srcRect, dstRect, SkSamplingOptions(), nullptr,
89 }
90 }
91 context->flushAndSubmit();
92
93 // In total we make 2000 oplists. Our current limit on max oplists between flushes is 100, so we
94 // should do 20 flushes while executing oplists. Additionaly we always do 1 flush at the end of
95 // executing all oplists. So in total we should see 21 flushes here.
96 REPORTER_ASSERT(reporter, gpu->stats()->numSubmitToGpus() == 21);
97
98 SkBitmap readbackBitmap;
99 readbackBitmap.allocN32Pixels(1000, 1);
100 REPORTER_ASSERT(reporter, surface1->readPixels(readbackBitmap, 0, 0));
101 REPORTER_ASSERT(reporter, check_read(reporter, readbackBitmap));
102
103 REPORTER_ASSERT(reporter, surface2->readPixels(readbackBitmap, 0, 0));
104 REPORTER_ASSERT(reporter, check_read(reporter, readbackBitmap));
105}
static bool check_read(skiatest::Reporter *reporter, const SkBitmap &bitmap)
@ 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_ColorRED
Definition: SkColor.h:126
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
Definition: GrGpu.h:62
Stats * stats()
Definition: GrGpu.h:551
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition: SkBitmap.cpp:232
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
@ kStrict_SrcRectConstraint
sample only inside bounds; slower
Definition: SkCanvas.h:1542
void clear(SkColor color)
Definition: SkCanvas.h:1199
void drawImageRect(const SkImage *, const SkRect &src, const SkRect &dst, const SkSamplingOptions &, const SkPaint *, SrcRectConstraint)
Definition: SkCanvas.cpp:2333
SkCanvas * getCanvas()
Definition: SkSurface.cpp:82
sk_sp< SkImage > makeImageSnapshot()
Definition: SkSurface.cpp:90
bool readPixels(const SkPixmap &dst, int srcX, int srcY)
Definition: SkSurface.cpp:125
T * get() const
Definition: SkRefCnt.h:303
const Paint & paint
Definition: color_source.cc:38
sk_sp< const SkImage > image
Definition: SkRecords.h:269
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)
SkScalar fLeft
smaller x-axis bounds
Definition: extension.cpp:14
SkScalar fRight
larger x-axis bounds
Definition: extension.cpp:16
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609