+++ /dev/null
-/*
- * Copyright 2016 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "Benchmark.h"
-#include "SkOpts.h"
-#include "SkRandom.h"
-
-struct FloatToHalfBench : public Benchmark {
- const char* onGetName() override { return "float_to_half"; }
- bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }
-
- void onDraw(int loops, SkCanvas* canvas) override {
- SkRandom rand;
- float fs[1023];
- for (float& f : fs) {
- f = rand.nextF();
- }
-
- uint16_t hs[1023];
- while (loops --> 0) {
- SkOpts::float_to_half(hs, fs, 1023);
- }
- }
-};
-DEF_BENCH(return new FloatToHalfBench;)
-
-struct HalfToFloatBench : public Benchmark {
- const char* onGetName() override { return "half_to_float"; }
- bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }
-
- void onDraw(int loops, SkCanvas* canvas) override {
- SkRandom rand;
- uint16_t hs[1023];
- for (uint16_t& h : hs) {
- h = rand.nextU16();
- }
-
- float fs[1023];
- while (loops --> 0) {
- SkOpts::half_to_float(fs, hs, 1023);
- }
- }
-};
-DEF_BENCH(return new HalfToFloatBench;)
#include "SkTextureCompressor_opts.h"
#include "SkXfermode_opts.h"
-namespace SK_OPTS_NS {
- static void float_to_half(uint16_t dst[], const float src[], int n) {
- while (n-->0) {
- *dst++ = SkFloatToHalf(*src++);
- }
- }
- static void half_to_float(float dst[], const uint16_t src[], int n) {
- while (n-->0) {
- *dst++ = SkHalfToFloat(*src++);
- }
- }
-}
-
namespace SkOpts {
// Define default function pointer values here...
// If our global compile options are set high enough, these defaults might even be
DEFINE_DEFAULT(inverted_CMYK_to_RGB1);
DEFINE_DEFAULT(inverted_CMYK_to_BGR1);
- DEFINE_DEFAULT(half_to_float);
- DEFINE_DEFAULT(float_to_half);
-
DEFINE_DEFAULT(srcover_srgb_srgb);
DEFINE_DEFAULT(color_xform_RGB1_to_2dot2);
inverted_CMYK_to_RGB1, // i.e. convert color space
inverted_CMYK_to_BGR1; // i.e. convert color space
- extern void (*half_to_float)(float[], const uint16_t[], int);
- extern void (*float_to_half)(uint16_t[], const float[], int);
-
// Blend ndst src pixels over dst, where both src and dst point to sRGB pixels (RGBA or BGRA).
// If nsrc < ndst, we loop over src to create a pattern.
extern void (*srcover_srgb_srgb)(uint32_t* dst, const uint32_t* src, int ndst, int nsrc);
}
}
-DEF_TEST(float_to_half, reporter) {
- const float fs[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 };
- const uint16_t hs[] = { 0x3c00, 0x4000, 0x4200, 0x4400, 0x4500, 0x4600, 0x4700 };
-
- uint16_t hscratch[7];
- SkOpts::float_to_half(hscratch, fs, 7);
- REPORTER_ASSERT(reporter, 0 == memcmp(hscratch, hs, sizeof(hs)));
-
- float fscratch[7];
- SkOpts::half_to_float(fscratch, hs, 7);
- REPORTER_ASSERT(reporter, 0 == memcmp(fscratch, fs, sizeof(fs)));
-}
-
static uint32_t u(float f) {
uint32_t x;
memcpy(&x, &f, 4);