2020-06-11 16:34:03 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2020 Google LLC
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gm/gm.h"
|
|
|
|
|
|
|
|
// This test only works with the Vulkan backend.
|
|
|
|
#ifdef SK_VULKAN
|
|
|
|
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkImage.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
2020-07-01 18:45:24 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2020-06-11 16:34:03 +00:00
|
|
|
#include "tools/gpu/vk/VkYcbcrSamplerHelper.h"
|
|
|
|
|
2020-06-15 18:26:58 +00:00
|
|
|
static void release_ycbcrhelper(void* releaseContext) {
|
|
|
|
VkYcbcrSamplerHelper* ycbcrHelper = reinterpret_cast<VkYcbcrSamplerHelper*>(releaseContext);
|
|
|
|
delete ycbcrHelper;
|
|
|
|
}
|
2020-06-11 16:34:03 +00:00
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
// This GM exercises the native YCbCr image format on Vulkan
|
|
|
|
class YCbCrImageGM : public GpuGM {
|
|
|
|
public:
|
|
|
|
YCbCrImageGM() {
|
|
|
|
this->setBGColor(0xFFCCCCCC);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
SkString onShortName() override {
|
|
|
|
return SkString("ycbcrimage");
|
|
|
|
}
|
|
|
|
|
|
|
|
SkISize onISize() override {
|
|
|
|
return SkISize::Make(2*kPad+kImageSize, 2*kPad+kImageSize);
|
|
|
|
}
|
|
|
|
|
2020-07-17 15:59:01 +00:00
|
|
|
DrawResult createYCbCrImage(GrDirectContext* dContext, SkString* errorMsg) {
|
|
|
|
std::unique_ptr<VkYcbcrSamplerHelper> ycbcrHelper(new VkYcbcrSamplerHelper(dContext));
|
2020-06-15 18:26:58 +00:00
|
|
|
|
|
|
|
if (!ycbcrHelper->isYCbCrSupported()) {
|
|
|
|
*errorMsg = "YCbCr sampling not supported.";
|
|
|
|
return skiagm::DrawResult::kSkip;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ycbcrHelper->createBackendTexture(kImageSize, kImageSize)) {
|
|
|
|
*errorMsg = "Failed to create I420 backend texture.";
|
|
|
|
return skiagm::DrawResult::kFail;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkASSERT(!fYCbCrImage);
|
2020-07-17 15:59:01 +00:00
|
|
|
fYCbCrImage = SkImage::MakeFromTexture(dContext, ycbcrHelper->backendTexture(),
|
2020-06-15 18:26:58 +00:00
|
|
|
kTopLeft_GrSurfaceOrigin, kRGB_888x_SkColorType,
|
|
|
|
kPremul_SkAlphaType, nullptr,
|
|
|
|
release_ycbcrhelper, ycbcrHelper.get());
|
|
|
|
if (!fYCbCrImage) {
|
|
|
|
*errorMsg = "Failed to create I420 image.";
|
|
|
|
return DrawResult::kFail;
|
|
|
|
}
|
|
|
|
|
|
|
|
ycbcrHelper.release();
|
|
|
|
return DrawResult::kOk;
|
|
|
|
}
|
|
|
|
|
2020-07-01 18:45:24 +00:00
|
|
|
DrawResult onGpuSetup(GrDirectContext* context, SkString* errorMsg) override {
|
2020-06-19 13:50:33 +00:00
|
|
|
if (!context || context->abandoned()) {
|
2020-06-16 15:11:33 +00:00
|
|
|
return DrawResult::kSkip;
|
|
|
|
}
|
|
|
|
|
2020-06-11 16:34:03 +00:00
|
|
|
if (context->backend() != GrBackendApi::kVulkan) {
|
|
|
|
*errorMsg = "This GM requires a Vulkan context.";
|
|
|
|
return DrawResult::kSkip;
|
|
|
|
}
|
|
|
|
|
2020-06-15 18:26:58 +00:00
|
|
|
DrawResult result = this->createYCbCrImage(context, errorMsg);
|
|
|
|
if (result != DrawResult::kOk) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DrawResult::kOk;
|
|
|
|
}
|
|
|
|
|
2020-06-25 16:38:53 +00:00
|
|
|
void onGpuTeardown() override {
|
|
|
|
fYCbCrImage = nullptr;
|
|
|
|
}
|
|
|
|
|
2020-12-09 21:37:04 +00:00
|
|
|
DrawResult onDraw(GrRecordingContext*, GrSurfaceDrawContext*,
|
2020-06-29 19:36:12 +00:00
|
|
|
SkCanvas* canvas, SkString*) override {
|
2020-06-15 18:26:58 +00:00
|
|
|
SkASSERT(fYCbCrImage);
|
|
|
|
|
2020-06-11 16:34:03 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setFilterQuality(kLow_SkFilterQuality);
|
|
|
|
|
2020-06-15 18:26:58 +00:00
|
|
|
canvas->drawImage(fYCbCrImage, kPad, kPad, &paint);
|
2020-06-11 16:34:03 +00:00
|
|
|
return DrawResult::kOk;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static const int kImageSize = 112;
|
|
|
|
static const int kPad = 8;
|
|
|
|
|
2020-06-15 18:26:58 +00:00
|
|
|
sk_sp<SkImage> fYCbCrImage;
|
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = GpuGM;
|
2020-06-11 16:34:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
DEF_GM(return new YCbCrImageGM;)
|
|
|
|
|
2020-08-06 18:11:56 +00:00
|
|
|
} // namespace skiagm
|
2020-06-11 16:34:03 +00:00
|
|
|
|
|
|
|
#endif // SK_VULKAN
|