Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
CachedDecodingPixelRefTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2013 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
19#include "src/core/SkMemset.h"
20#include "tests/Test.h"
21#include "tools/ToolUtils.h"
22
23#include <array>
24#include <cstddef>
25#include <cstdint>
26#include <memory>
27#include <utility>
28
30public:
36 static int Width() { return 10; }
37 static int Height() { return 10; }
38 // value choosen so that there is no loss when converting to to RGB565 and back
39 static SkColor Color() { return ToolUtils::color_to_565(0xffaabbcc); }
40 static SkPMColor PMColor() { return SkPreMultiplyColor(Color()); }
41
43 SkColorType colorType = kN32_SkColorType)
44 : SkImageGenerator(GetMyInfo(colorType)), fType(type), fReporter(reporter) {
45 SkASSERT((fType <= kLast_TestType) && (fType >= 0));
46 }
47 ~TestImageGenerator() override {}
48
49protected:
54
55 bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
56 const Options& options) override {
57 REPORTER_ASSERT(fReporter, pixels != nullptr);
58 REPORTER_ASSERT(fReporter, rowBytes >= info.minRowBytes());
59 if (fType != kSucceedGetPixels_TestType) {
60 return false;
61 }
62 if (info.colorType() != kN32_SkColorType && info.colorType() != getInfo().colorType()) {
63 return false;
64 }
65 char* bytePtr = static_cast<char*>(pixels);
66 switch (info.colorType()) {
67 case kN32_SkColorType:
68 for (int y = 0; y < info.height(); ++y) {
69 SkOpts::memset32((uint32_t*)bytePtr,
71 bytePtr += rowBytes;
72 }
73 break;
75 for (int y = 0; y < info.height(); ++y) {
76 SkOpts::memset16((uint16_t*)bytePtr,
78 bytePtr += rowBytes;
79 }
80 break;
81 default:
82 return false;
83 }
84 return true;
85 }
86
87private:
88 const TestType fType;
89 skiatest::Reporter* const fReporter;
90};
91
92////////////////////////////////////////////////////////////////////////////////
93
94DEF_TEST(Image_NewFromGenerator, r) {
95 const TestImageGenerator::TestType testTypes[] = {
98 };
99 const SkColorType testColorTypes[] = {
100 kN32_SkColorType,
102 };
103 for (size_t i = 0; i < std::size(testTypes); ++i) {
104 TestImageGenerator::TestType test = testTypes[i];
105 for (const SkColorType testColorType : testColorTypes) {
106 auto gen = std::make_unique<TestImageGenerator>(test, r, testColorType);
108 if (nullptr == image) {
109 ERRORF(r, "SkImage::NewFromGenerator unexpecedly failed [%zu]", i);
110 continue;
111 }
115
118 SkCanvas canvas(bitmap);
119 const SkColor kDefaultColor = 0xffabcdef;
120 canvas.clear(kDefaultColor);
121 canvas.drawImage(image, 0, 0);
124 r, TestImageGenerator::Color() == bitmap.getColor(0, 0));
125 }
126 else {
127 REPORTER_ASSERT(r, kDefaultColor == bitmap.getColor(0, 0));
128 }
129 }
130 }
131}
const char * options
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
reporter
@ kOpaque_SkAlphaType
pixel is opaque
Definition SkAlphaType.h:28
#define SkASSERT(cond)
Definition SkAssert.h:116
static U16CPU SkPixel32ToPixel16(SkPMColor c)
SkColorType
Definition SkColorType.h:19
@ kRGB_565_SkColorType
pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word
Definition SkColorType.h:22
SK_API SkPMColor SkPreMultiplyColor(SkColor c)
Definition SkColor.cpp:21
uint32_t SkColor
Definition SkColor.h:37
uint32_t SkPMColor
Definition SkColor.h:205
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
#define DEF_TEST(name, reporter)
Definition Test.h:312
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
#define ERRORF(r,...)
Definition Test.h:293
void clear(SkColor color)
Definition SkCanvas.h:1199
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition SkCanvas.h:1528
const SkImageInfo & getInfo() const
virtual bool isLazyGenerated() const =0
int width() const
Definition SkImage.h:285
int height() const
Definition SkImage.h:291
static SkImageInfo GetMyInfo(SkColorType colorType)
TestImageGenerator(TestType type, skiatest::Reporter *reporter, SkColorType colorType=kN32_SkColorType)
bool onGetPixels(const SkImageInfo &info, void *pixels, size_t rowBytes, const Options &options) override
sk_sp< SkImage > image
Definition examples.cpp:29
double y
SK_API sk_sp< SkImage > DeferredFromGenerator(std::unique_ptr< SkImageGenerator > imageGenerator)
void(* memset16)(uint16_t[], uint16_t, int)
void(* memset32)(uint32_t[], uint32_t, int)
SkColor color_to_565(SkColor color)
Definition gen.py:1
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)