Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
FloatingPointTextureTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2014 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/*
9 * This is a straightforward test of floating point textures, which are
10 * supported on some platforms. As of right now, this test only supports
11 * 32 bit floating point textures, and indeed floating point test values
12 * have been selected to require 32 bits of precision and full IEEE conformance
13 */
14
21#include "include/gpu/GrTypes.h"
24#include "src/base/SkHalf.h"
31#include "tests/Test.h"
33
34#include <cstring>
35#include <initializer_list>
36#include <memory>
37#include <utility>
38
39struct GrContextOptions;
40
41static const int DEV_W = 100, DEV_H = 100;
42
43template <typename T>
45 T min, T max, T epsilon, T maxInt,
46 int arraySize, GrColorType colorType) {
47 if (0 != arraySize % 4) {
48 REPORT_FAILURE(reporter, "(0 != arraySize % 4)",
49 SkString("arraySize must be divisible by 4."));
50 return;
51 }
52
53 SkTDArray<T> controlPixelData, readBuffer;
54 controlPixelData.resize(arraySize);
55 readBuffer.resize(arraySize);
56
57 for (int i = 0; i < arraySize; i += 4) {
58 controlPixelData[i + 0] = min;
59 controlPixelData[i + 1] = max;
60 controlPixelData[i + 2] = epsilon;
61 controlPixelData[i + 3] = maxInt;
62 }
63
66 GrCPixmap controlPixmap(info, controlPixelData.begin(), info.minRowBytes());
67 auto fpView = sk_gpu_test::MakeTextureProxyViewFromData(dContext,
68 GrRenderable::kYes,
69 origin,
70 controlPixmap);
71 // Floating point textures are NOT supported everywhere
72 if (!fpView) {
73 continue;
74 }
75
76 auto sc = dContext->priv().makeSC(std::move(fpView), info.colorInfo());
78
79 GrPixmap readPixmap(info, readBuffer.begin(), info.minRowBytes());
80 bool result = sc->readPixels(dContext, readPixmap, {0, 0});
83 !memcmp(readBuffer.begin(), controlPixelData.begin(), readBuffer.size_bytes()));
84 }
85}
86
87static const int HALF_ALPHA_CONTROL_ARRAY_SIZE = DEV_W * DEV_H * 1 /*alpha-only*/;
89
92 ctxInfo,
94 auto direct = ctxInfo.directContext();
95
96 runFPTest<SkHalf>(reporter, direct, SK_HalfMin, SK_HalfMax, SK_HalfEpsilon,
99}
100
101static const int HALF_RGBA_CONTROL_ARRAY_SIZE = DEV_W * DEV_H * 4 /*RGBA*/;
102
104 reporter,
105 ctxInfo,
107 auto direct = ctxInfo.directContext();
108
109 runFPTest<SkHalf>(reporter, direct, SK_HalfMin, SK_HalfMax, SK_HalfEpsilon,
112}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
static const SkHalf kMaxIntegerRepresentableInHalfFloatingPoint
static const int DEV_H
static const int HALF_ALPHA_CONTROL_ARRAY_SIZE
static const int HALF_RGBA_CONTROL_ARRAY_SIZE
void runFPTest(skiatest::Reporter *reporter, GrDirectContext *dContext, T min, T max, T epsilon, T maxInt, int arraySize, GrColorType colorType)
static const int DEV_W
reporter
GrColorType
@ kBottomLeft_GrSurfaceOrigin
Definition GrTypes.h:149
@ kTopLeft_GrSurfaceOrigin
Definition GrTypes.h:148
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
static constexpr uint16_t SK_HalfMax
Definition SkHalf.h:21
static constexpr uint16_t SK_HalfMin
Definition SkHalf.h:20
uint16_t SkHalf
Definition SkHalf.h:16
static constexpr uint16_t SK_HalfEpsilon
Definition SkHalf.h:22
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
#define DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(name, reporter, context_info, ctsEnforcement)
Definition Test.h:434
#define REPORT_FAILURE(reporter, cond, message)
Definition Test.h:90
GrDirectContextPriv priv()
std::unique_ptr< skgpu::ganesh::SurfaceContext > makeSC(GrSurfaceProxyView readView, const GrColorInfo &)
T * begin()
Definition SkTDArray.h:150
void resize(int count)
Definition SkTDArray.h:183
size_t size_bytes() const
Definition SkTDArray.h:146
GAsyncResult * result
static float max(float r, float g, float b)
Definition hsl.cpp:49
static float min(float r, float g, float b)
Definition hsl.cpp:48
GrSurfaceProxyView MakeTextureProxyViewFromData(GrDirectContext *dContext, GrRenderable renderable, GrSurfaceOrigin origin, GrCPixmap pixmap)
#define T