39#if defined(SK_GRAPHITE)
86 unsigned char* yuvPixels[] = {
87 static_cast<unsigned char*
>(pixmaps.planes()[0].writable_addr()),
88 static_cast<unsigned char*
>(pixmaps.planes()[1].writable_addr()),
89 static_cast<unsigned char*
>(pixmaps.planes()[2].writable_addr()),
90 static_cast<unsigned char*
>(pixmaps.planes()[3].writable_addr()),
97 for (
int j = 0; j < pixmaps.planes()[0].
height(); ++j) {
98 for (
int i = 0;
i < pixmaps.planes()[0].
width(); ++
i) {
100 auto r = (
rgba & 0x000000ff) >> 0;
101 auto g = (
rgba & 0x0000ff00) >> 8;
102 auto b = (
rgba & 0x00ff0000) >> 16;
103 auto a = (
rgba & 0xff000000) >> 24;
104 yuvPixels[0][j*pixmaps.planes()[0].width() +
i] =
SkToU8(
107 m[15]*r +
m[16]*g +
m[17]*
b +
m[18]*
a + 255*
m[19]));
110 for (
int j = 0; j < pixmaps.planes()[1].
height(); ++j) {
111 for (
int i = 0;
i < pixmaps.planes()[1].
width(); ++
i) {
113 int rgba[] = {0, 0, 0, 0};
115 int ylimit =
std::min(2*j + 2, pixmaps.planes()[0].height());
116 int xlimit =
std::min(2*
i + 2, pixmaps.planes()[0].width());
117 for (
int y = 2*j;
y < ylimit; ++
y) {
118 for (
int x = 2*
i;
x < xlimit; ++
x) {
120 rgba[0] += (
src & 0x000000ff) >> 0;
121 rgba[1] += (
src & 0x0000ff00) >> 8;
122 rgba[2] += (
src & 0x00ff0000) >> 16;
123 rgba[3] += (
src & 0xff000000) >> 24;
127 for (
int c = 0; c < 4; ++c) {
130 int uvIndex = j*pixmaps.planes()[1].width() +
i;
148 return fLazyYUVImage->refImage(context,
type);
150#if defined(SK_GRAPHITE)
151 return fLazyYUVImage->refImage(recorder,
type);
176#if defined(SK_GRAPHITE)
181 if (!resultSurface) {
191 auto* recorder = canvas->
recorder();
193 if (!recorder && (!dContext || dContext->abandoned())) {
194 *errorMsg =
"DirectContext or graphite::Recorder required to create YUV images";
198 if (dContext && !dContext->priv().caps()->mipmapSupport()) {
203 *errorMsg =
"YUV Image from SkImage planes not supported with Ganesh.";
207 if (!fLazyYUVImage) {
208 fLazyYUVImage =
CreatePlanes(
"images/mandrill_128.png");
213 for (
int i = 0;
i < kNumImages; ++
i) {
215 if (!fYUVAImages[
i]) {
216 *errorMsg =
"Couldn't create src YUVA image.";
222 if (!fReferenceImage) {
223 *errorMsg =
"Couldn't create reference YUVA image.";
239 fLazyYUVImage.reset();
243 fReferenceImage.
reset();
247 SkASSERT(index >= 0 && index < kNumImages);
248 return fYUVAImages[index].
get();
266 subset.inset(subset.width() * .05f, subset.height() * .1f);
270 return {
dst.width(),
dst.height()};
285 return {
rect.width(),
rect.height()};
291 using DF = std::function<DrawSig>;
292 for (
const auto&
draw : {DF(
draw_image), DF(draw_image_rect), DF(draw_image_shader)}) {
293 float wForDrawFunc = 0;
295 for (
auto scale : {1.f, 1.5f, 0.3f}) {
307 for (
const auto&
sampling : samplings) {
335 hForScale =
std::max(hForScale, yuvAndRefH);
339 wForDrawFunc =
std::max(wForScale, wForDrawFunc);
349 std::unique_ptr<sk_gpu_test::LazyYUVImage> fLazyYUVImage;
352 inline static constexpr int kNumImages = 3 * 3 * 4;
356 inline static constexpr SkScalar kPad = 10.0f;
358 using INHERITED =
GM;
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
static GrDirectContext * GrAsDirectContext(GrContext_Base *base)
@ kTopLeft_GrSurfaceOrigin
static void draw_image(SkCanvas *canvas, SkImage *img)
static const uint32_t rgba[kNumPixels]
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
constexpr SkColor SK_ColorBLACK
#define sk_float_round2int(x)
@ kJPEG_Full_SkYUVColorSpace
describes full range
static void copy(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static constexpr bool SkToBool(const T &x)
constexpr uint8_t SkToU8(S x)
void SkColorMatrix_RGB2YUV(SkYUVColorSpace cs, float m[20])
SkISize dimensions() const
SkColorType colorType() const
const SkImageInfo & info() const
bool readPixels(const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY) const
uint32_t * getAddr32(int x, int y) const
void drawRect(const SkRect &rect, const SkPaint &paint)
void translate(SkScalar dx, SkScalar dy)
virtual GrRecordingContext * recordingContext() const
virtual skgpu::graphite::Recorder * recorder() const
@ kStrict_SrcRectConstraint
sample only inside bounds; slower
void drawImageRect(const SkImage *, const SkRect &src, const SkRect &dst, const SkSamplingOptions &, const SkPaint *, SrcRectConstraint)
void scale(SkScalar sx, SkScalar sy)
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
SkISize dimensions() const
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
void setColor(SkColor color)
void setAntiAlias(bool aa)
sk_sp< SkImage > makeImageSnapshot()
@ kY_U_V_A
Plane 0: Y, Plane 1: U, Plane 2: V, Plane 3: A.
@ k420
1 set of UV values for each 2x2 block of Y values.
@ kUnorm8
8 bit unsigned normalized
static SkYUVAPixmaps Allocate(const SkYUVAPixmapInfo &yuvaPixmapInfo)
static std::unique_ptr< LazyYUVImage > Make(sk_sp< SkData > data, skgpu::Mipmapped=skgpu::Mipmapped::kNo, sk_sp< SkColorSpace >=nullptr)
void reset(T *ptr=nullptr)
GM(SkColor backgroundColor=SK_ColorWHITE)
DrawResult draw(SkCanvas *canvas)
ImageFromYUV(Source source)
static std::unique_ptr< sk_gpu_test::LazyYUVImage > CreatePlanes(const char *name)
void onGpuTeardown() override
DrawResult onGpuSetup(SkCanvas *canvas, SkString *errorMsg, GraphiteTestContext *) override
SkString getName() const override
SkISize getISize() override
sk_sp< SkImage > makeYUVAImage(GrDirectContext *context, skgpu::graphite::Recorder *recorder)
sk_sp< SkImage > createReferenceImage(GrDirectContext *dContext, skgpu::graphite::Recorder *recorder)
void onDraw(SkCanvas *canvas) override
SkImage * getYUVAImage(int index)
static float max(float r, float g, float b)
static float min(float r, float g, float b)
sk_sp< const SkImage > image
sk_sp< SkBlender > blender SkRect rect
SkSamplingOptions sampling
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)
DEF_SWITCHES_START aot vmservice shared library name
DEF_GM(return F(C(clipbox), 0.0f, 0.0f, {})) DEF_GM(return F(C(clipbox)
static SkPath scale(const SkPath &path, SkScalar scale)
SIN Vec< N, float > ceil(const Vec< N, float > &x)
static constexpr SkCubicResampler CatmullRom()
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
SkImageInfo makeColorType(SkColorType newColorType) const
static SkRect Make(const SkISize &size)
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
static constexpr SkRect MakeWH(float w, float h)