Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrOpListFlushTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2018 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
16#include "include/core/SkRect.h"
27#include "tests/Test.h"
28
29#include <cstdint>
30
31struct GrContextOptions;
32
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}
45
48 ctxInfo,
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
80 sk_sp<SkImage> image = surface1->makeImageSnapshot();
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}
reporter
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
constexpr SkColor SK_ColorGREEN
Definition SkColor.h:131
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
#define ERRORF(r,...)
Definition Test.h:293
#define DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(name, reporter, context_info, ctsEnforcement)
Definition Test.h:434
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)
@ 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)
T * get() const
Definition SkRefCnt.h:303
const Paint & paint
sk_sp< SkImage > image
Definition examples.cpp:29
GAsyncResult * result
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)
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