Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions | Variables
yuv420_odd_dim.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkImage.h"
#include "include/core/SkPixmap.h"
#include "include/core/SkShader.h"
#include "include/core/SkStream.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTileMode.h"
#include "include/encode/SkJpegEncoder.h"
#include "include/gpu/GrRecordingContext.h"
#include "include/gpu/ganesh/SkImageGanesh.h"
#include "src/base/SkRandom.h"
#include "src/core/SkCachedData.h"
#include "src/image/SkImage_Base.h"
#include "tools/DecodeUtils.h"
#include "tools/Resources.h"
#include "tools/gpu/YUVUtils.h"

Go to the source code of this file.

Functions

static sk_sp< SkImagemake_image (GrRecordingContext *rContext, skgpu::graphite::Recorder *recorder)
 
 DEF_SIMPLE_GM_CAN_FAIL (yuv420_odd_dim, canvas, errMsg, kScale *kImageDim.width(), kScale *kImageDim.height())
 
 DEF_SIMPLE_GM_CAN_FAIL (yuv420_odd_dim_repeat, canvas, errMsg, 1000, 500)
 

Variables

static constexpr int kScale = 10
 
static constexpr SkISize kImageDim = {5, 5}
 

Function Documentation

◆ DEF_SIMPLE_GM_CAN_FAIL() [1/2]

DEF_SIMPLE_GM_CAN_FAIL ( yuv420_odd_dim  ,
canvas  ,
errMsg  ,
kScale *kImageDim.  width(),
kScale *kImageDim.  height() 
)

Definition at line 68 of file yuv420_odd_dim.cpp.

69 {
70 auto rContext = canvas->recordingContext();
71 skgpu::graphite::Recorder* recorder = nullptr;
72#if defined(SK_GRAPHITE)
73 recorder = canvas->recorder();
74#endif
75 if (!rContext && !recorder) {
76 // This GM exists to exercise GPU planar images.
78 }
79 auto image = make_image(rContext, recorder);
80 if (!image) {
81 if (rContext) {
82 return rContext->abandoned() ? skiagm::DrawResult::kOk : skiagm::DrawResult::kFail;
83 } else {
85 }
86 }
87 // We draw the image offscreen and then blow it up using nearest filtering by kScale.
88 // This avoids skbug.com/9693
90 if (auto origSurface = canvas->getSurface()) {
91 surface = origSurface->makeSurface(image->width(), image->height());
92 } else {
93 auto ct = canvas->imageInfo().colorType();
94 if (ct == kUnknown_SkColorType) {
95 ct = image->colorType();
96 }
97 auto info = canvas->imageInfo().makeColorType(ct);
98 info = info.makeAlphaType(kPremul_SkAlphaType);
100 }
101 surface->getCanvas()->drawImage(image, 0, 0);
102 canvas->scale(kScale, kScale);
103 canvas->drawImage(surface->makeImageSnapshot(), 0, 0);
105}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
@ kUnknown_SkColorType
uninitialized
Definition SkColorType.h:20
int width() const
Definition SkImage.h:285
SkColorType colorType() const
Definition SkImage.cpp:152
int height() const
Definition SkImage.h:291
VkSurfaceKHR surface
Definition main.cc:49
sk_sp< SkImage > image
Definition examples.cpp:29
static sk_sp< SkImage > make_image()
Definition mipmap.cpp:21
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
static constexpr int kScale

◆ DEF_SIMPLE_GM_CAN_FAIL() [2/2]

DEF_SIMPLE_GM_CAN_FAIL ( yuv420_odd_dim_repeat  ,
canvas  ,
errMsg  ,
1000  ,
500   
)

Definition at line 108 of file yuv420_odd_dim.cpp.

110 {
111 auto rContext = canvas->recordingContext();
112 skgpu::graphite::Recorder* recorder = nullptr;
113#if defined(SK_GRAPHITE)
114 recorder = canvas->recorder();
115#endif
116 if (!rContext && !recorder) {
117 // This GM exists to exercise GPU planar images.
119 }
120 auto image = ToolUtils::GetResourceAsImage("images/mandrill_256.png");
121 if (!image) {
122 if (rContext) {
123 return rContext->abandoned() ? skiagm::DrawResult::kOk : skiagm::DrawResult::kFail;
124 } else {
126 }
127 }
128 // Make sure the image is odd dimensioned.
129 int w = image->width() & 0b1 ? image->width() : image->width() - 1;
130 int h = image->height() & 0b1 ? image->height() : image->height() - 1;
131 image = image->makeSubset(nullptr, SkIRect::MakeWH(w, h));
132
133 auto [planes, yuvaInfo] = sk_gpu_test::MakeYUVAPlanesAsA8(image.get(),
136 nullptr);
137 SkPixmap pixmaps[4];
138 for (int i = 0; i < yuvaInfo.numPlanes(); ++i) {
139 planes[i]->peekPixels(&pixmaps[i]);
140 }
141 auto yuvaPixmaps = SkYUVAPixmaps::FromExternalPixmaps(yuvaInfo, pixmaps);
142 auto lazyYUV = sk_gpu_test::LazyYUVImage::Make(yuvaPixmaps, skgpu::Mipmapped::kYes);
143
144#if defined(SK_GRAPHITE)
145 if (recorder) {
146 image = lazyYUV->refImage(recorder, sk_gpu_test::LazyYUVImage::Type::kFromPixmaps);
147 } else
148#endif
149 {
150 image = lazyYUV->refImage(rContext, sk_gpu_test::LazyYUVImage::Type::kFromPixmaps);
151 }
152 if (!image) {
153 *errMsg = "Could not make YUVA image";
154 if (rContext) {
155 return rContext->abandoned() ? skiagm::DrawResult::kOk : skiagm::DrawResult::kFail;
156 } else {
158 }
159 }
160 int i = 0;
162 int j = 0;
164 canvas->save();
165 canvas->clipRect(SkRect::MakeXYWH(500.f*j, 250.f*i, 500.f, 250.f));
166 canvas->rotate(30.f);
167 canvas->scale(0.4f, 0.4f); // so mipmaps sampling doesn't just use base level.
168 // Large translation so that if U/V planes aren't repeated correctly WRT to Y plane we
169 // accumulate a lot of error.
170 canvas->translate(-240000.f, -240000.f);
171 auto shader = image->makeShader(SkTileMode::kRepeat,
173 SkSamplingOptions(filter, mm));
175 paint.setShader(std::move(shader));
176 canvas->drawPaint(paint);
177 canvas->restore();
178 ++j;
179 }
180 ++i;
181 }
183}
@ kJPEG_SkYUVColorSpace
Definition SkImageInfo.h:98
SkFilterMode
SkMipmapMode
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition SkImage.cpp:179
virtual sk_sp< SkImage > makeSubset(GrDirectContext *direct, const SkIRect &subset) const =0
@ k420
1 set of UV values for each 2x2 block of Y values.
static SkYUVAPixmaps FromExternalPixmaps(const SkYUVAInfo &, const SkPixmap[kMaxPlanes])
static std::unique_ptr< LazyYUVImage > Make(sk_sp< SkData > data, skgpu::Mipmapped=skgpu::Mipmapped::kNo, sk_sp< SkColorSpace >=nullptr)
Definition YUVUtils.cpp:200
T * get() const
Definition SkRefCnt.h:303
const Paint & paint
sk_sp< SkImage > GetResourceAsImage(const char *resource)
Definition DecodeUtils.h:25
SkScalar w
SkScalar h
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition SkRect.h:56
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659

◆ make_image()

static sk_sp< SkImage > make_image ( GrRecordingContext rContext,
skgpu::graphite::Recorder recorder 
)
static

Definition at line 31 of file yuv420_odd_dim.cpp.

32 {
33 // Generate a small jpeg with odd dimensions.
34 SkBitmap bmp;
36 SkRandom random;
37 // These random values won't compress well, but it doesn't matter. This test exists to
38 // compare the GPU YUV code path to the SW.
39 for (int y = 0; y < bmp.height(); ++y) {
40 for (int x = 0; x < bmp.width(); ++x) {
41 *bmp.getAddr32(x, y) = random.nextU() | 0xFF000000;
42 }
43 }
48 options.fQuality = 100;
49 if (!SkJpegEncoder::Encode(&stream, bmp.pixmap(), options)) {
50 return nullptr;
51 }
52 auto imageHelper = sk_gpu_test::LazyYUVImage::Make(stream.detachAsData());
53 if (!imageHelper) {
54 return nullptr;
55 }
56#if defined(SK_GRAPHITE)
57 if (recorder) {
58 return imageHelper->refImage(recorder, sk_gpu_test::LazyYUVImage::Type::kFromPixmaps);
59 } else
60#endif
61 {
62 return imageHelper->refImage(rContext, sk_gpu_test::LazyYUVImage::Type::kFromPixmaps);
63 }
64}
const char * options
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition SkColorType.h:24
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition SkBitmap.cpp:258
void notifyPixelsChanged() const
Definition SkBitmap.cpp:365
int width() const
Definition SkBitmap.h:149
const SkPixmap & pixmap() const
Definition SkBitmap.h:133
int height() const
Definition SkBitmap.h:158
uint32_t * getAddr32(int x, int y) const
Definition SkBitmap.h:1260
uint32_t nextU()
Definition SkRandom.h:42
double y
double x
SK_API bool Encode(SkWStream *dst, const SkPixmap &src, const Options &options)
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
static constexpr SkISize kImageDim

Variable Documentation

◆ kImageDim

constexpr SkISize kImageDim = {5, 5}
staticconstexpr

Definition at line 29 of file yuv420_odd_dim.cpp.

29{5, 5};

◆ kScale

constexpr int kScale = 10
staticconstexpr

Definition at line 28 of file yuv420_odd_dim.cpp.