Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
DeviceTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2022 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
8#include "tests/Test.h"
9
17
18namespace skgpu::graphite {
19
20// Tests that vertex transparency will affect draw order.
21DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS(DeviceTestVertexTransparency, reporter, context,
23 // Set up transparent vertices, in a 5px wide by 10px tall rectangle.
24 static constexpr int kVertexCount = 5;
25 SkPoint positions[kVertexCount];
26 positions[0].set(2.5, 5);
27 positions[1].set(0, 0);
28 positions[2].set(5, 0);
29 positions[3].set(5, 10);
30 positions[4].set(0, 10);
31
32 static constexpr int kIndexCount = 6;
33 static constexpr uint16_t kIndices[kIndexCount] = {0, 1, 2, 3, 4, 1};
34
35 SkColor colors[kVertexCount];
36 for (size_t i = 0; i < kVertexCount; ++i) {
37 colors[i] = 0x7F00FF00;
38 }
39
42 positions,
43 nullptr,
44 colors,
46 kIndices);
47
48 // Draw vertices at x = 0.
49 std::unique_ptr<Recorder> recorder = context->makeRecorder();
54 SkCanvas* canvas = surface->getCanvas();
56
57 // Draw a square that will overlap both vertex draws.
58 SkPaint redPaint;
59 redPaint.setColor(SK_ColorRED);
60 canvas->drawRect(SkRect::MakeXYWH(0, 0, 10, 10), redPaint);
61
62 // Draw vertices at x = 5.
63 canvas->translate(5, 0);
65
66 // Read pixels.
68 SkPixmap pixmap;
69 bitmap.allocPixels(ii);
70 SkAssertResult(bitmap.peekPixels(&pixmap));
71 if (!surface->readPixels(pixmap, 0, 0)) {
72 ERRORF(reporter, "readPixels failed");
73 return;
74 }
75
76 // Check that draws weren't reordered to put vertex draws together.
77 // The second vertex draw should have been 50% green on top of red.
78 SkColor color = pixmap.getColor(9, 5);
79 SkColor expected = 0xFF807F00;
81 reporter, color == expected, "Wrong color, expected %08x, found %08x", expected, color);
82}
83
84} // namespace skgpu::graphite
reporter
static const uint16_t kIndices[]
SkColor4f color
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
#define SkAssertResult(cond)
Definition SkAssert.h:123
@ 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_ColorRED
Definition SkColor.h:126
#define DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS(name, reporter, graphite_ctx, ctsEnforcement)
Definition Test.h:373
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
#define ERRORF(r,...)
Definition Test.h:293
void drawRect(const SkRect &rect, const SkPaint &paint)
void translate(SkScalar dx, SkScalar dy)
void drawVertices(const SkVertices *vertices, SkBlendMode mode, const SkPaint &paint)
void setColor(SkColor color)
Definition SkPaint.cpp:119
SkColor getColor(int x, int y) const
Definition SkPixmap.cpp:187
static sk_sp< SkVertices > MakeCopy(VertexMode mode, int vertexCount, const SkPoint positions[], const SkPoint texs[], const SkColor colors[], int indexCount, const uint16_t indices[])
@ kTriangleFan_VertexMode
Definition SkVertices.h:33
VkSurfaceKHR surface
Definition main.cc:49
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 constexpr int kIndexCount
static constexpr int kVertexCount
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
void set(float x, float y)
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659