Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
ycbcrimage.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2020 Google LLC
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#include "gm/gm.h"
9
10// This test only works with the Vulkan backend.
11#ifdef SK_VULKAN
12
17#include "include/core/SkSize.h"
22
23static void release_ycbcrhelper(void* releaseContext) {
24 VkYcbcrSamplerHelper* ycbcrHelper = reinterpret_cast<VkYcbcrSamplerHelper*>(releaseContext);
25 delete ycbcrHelper;
26}
27
28namespace skiagm {
29
30// This GM exercises the native YCbCr image format on Vulkan
31class YCbCrImageGM : public GM {
32public:
33 YCbCrImageGM() {
34 this->setBGColor(0xFFCCCCCC);
35 }
36
37protected:
38 SkString getName() const override { return SkString("ycbcrimage"); }
39
40 SkISize getISize() override {
42 }
43
44 DrawResult createYCbCrImage(GrDirectContext* dContext, SkString* errorMsg) {
45 std::unique_ptr<VkYcbcrSamplerHelper> ycbcrHelper(new VkYcbcrSamplerHelper(dContext));
46
47 if (!ycbcrHelper->isYCbCrSupported()) {
48 *errorMsg = "YCbCr sampling not supported.";
50 }
51
52 if (!ycbcrHelper->createBackendTexture(kImageSize, kImageSize)) {
53 *errorMsg = "Failed to create I420 backend texture.";
55 }
56
57 SkASSERT(!fYCbCrImage);
58 fYCbCrImage = SkImages::BorrowTextureFrom(dContext,
59 ycbcrHelper->backendTexture(),
63 nullptr,
64 release_ycbcrhelper,
65 ycbcrHelper.get());
66 ycbcrHelper.release();
67 if (!fYCbCrImage) {
68 *errorMsg = "Failed to create I420 image.";
69 return DrawResult::kFail;
70 }
71
72 return DrawResult::kOk;
73 }
74
75 DrawResult onGpuSetup(SkCanvas* canvas, SkString* errorMsg, GraphiteTestContext*) override {
77 if (!dContext || dContext->abandoned()) {
78 return DrawResult::kSkip;
79 }
80
81 if (dContext->backend() != GrBackendApi::kVulkan) {
82 *errorMsg = "This GM requires a Vulkan context.";
83 return DrawResult::kSkip;
84 }
85
86 DrawResult result = this->createYCbCrImage(dContext, errorMsg);
87 if (result != DrawResult::kOk) {
88 return result;
89 }
90
91 return DrawResult::kOk;
92 }
93
94 void onGpuTeardown() override {
95 fYCbCrImage = nullptr;
96 }
97
98 DrawResult onDraw(SkCanvas* canvas, SkString*) override {
99 SkASSERT(fYCbCrImage);
100
102 return DrawResult::kOk;
103 }
104
105private:
106 static const int kImageSize = 112;
107 static const int kPad = 8;
108
109 sk_sp<SkImage> fYCbCrImage;
110
111 using INHERITED = GpuGM;
112};
113
114//////////////////////////////////////////////////////////////////////////////
115
116DEF_GM(return new YCbCrImageGM;)
117
118} // namespace skiagm
119
120#endif // SK_VULKAN
static GrDirectContext * GrAsDirectContext(GrContext_Base *base)
@ kTopLeft_GrSurfaceOrigin
Definition GrTypes.h:148
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
#define SkASSERT(cond)
Definition SkAssert.h:116
@ kRGB_888x_SkColorType
pixel with 8 bits each for red, green, blue; in 32-bit word
Definition SkColorType.h:25
#define INHERITED(method,...)
constexpr int kPad
SK_API GrBackendApi backend() const
bool abandoned() override
virtual GrRecordingContext * recordingContext() const
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition SkCanvas.h:1528
GAsyncResult * result
static const int kImageSize
Definition flippity.cpp:44
#define DEF_GM(CODE)
Definition gm.h:40
SK_API sk_sp< SkImage > BorrowTextureFrom(GrRecordingContext *context, const GrBackendTexture &backendTexture, GrSurfaceOrigin origin, SkColorType colorType, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace, TextureReleaseProc textureReleaseProc=nullptr, ReleaseContext releaseContext=nullptr)
DrawResult
Definition gm.h:104
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20