Flutter Engine
The Flutter Engine
Functions
ducky_yuv_blend.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkPaint.h"
#include "include/gpu/GrRecordingContext.h"
#include "src/core/SkCachedData.h"
#include "src/image/SkImage_Base.h"
#include "tools/DecodeUtils.h"
#include "tools/Resources.h"
#include "tools/ToolUtils.h"
#include "tools/gpu/YUVUtils.h"

Go to the source code of this file.

Functions

 DEF_SIMPLE_GM_CAN_FAIL (ducky_yuv_blend, canvas, errorMsg, 560, 1130)
 

Function Documentation

◆ DEF_SIMPLE_GM_CAN_FAIL()

DEF_SIMPLE_GM_CAN_FAIL ( ducky_yuv_blend  ,
canvas  ,
errorMsg  ,
560  ,
1130   
)

Definition at line 21 of file ducky_yuv_blend.cpp.

21 {
22 sk_sp<SkImage> duckyBG = ToolUtils::GetResourceAsImage("images/ducky.png");
23 sk_sp<SkImage> duckyFG[2] = {ToolUtils::GetResourceAsImage("images/ducky.jpg"), nullptr};
24 if (!duckyFG[0] || !duckyBG) {
25 *errorMsg = "Image(s) failed to load.";
27 }
28
29 // If we're on the GPU we do a second round of draws where the source image is YUV planes.
30 // Otherwise we just draw the original again,
31 if (auto* rContext = canvas->recordingContext(); rContext && !rContext->abandoned()) {
32 auto lazyYUV = sk_gpu_test::LazyYUVImage::Make(GetResourceAsData("images/ducky.jpg"),
34 if (lazyYUV) {
35 duckyFG[1] = lazyYUV->refImage(rContext, sk_gpu_test::LazyYUVImage::Type::kFromPixmaps);
36 }
37 if (!duckyFG[1]) {
39 }
40 } else {
41 duckyFG[1] = duckyFG[0];
42 }
43
44 static constexpr int kNumPerRow = 4;
45 static constexpr int kPad = 10;
46 static constexpr auto kDstRect = SkRect::MakeWH(130, 130);
47 int rowCnt = 0;
48 canvas->translate(kPad, kPad);
49 canvas->save();
50 auto newRow = [&] {
51 canvas->restore();
52 canvas->translate(0, kDstRect.height() + kPad);
53 canvas->save();
54 rowCnt = 0;
55 };
59 canvas, SK_ColorDKGRAY, SK_ColorLTGRAY, (kDstRect.height() + kPad)/5);
60 for (auto& fg : duckyFG) {
61 for (int bm = static_cast<int>(SkBlendMode::kLastCoeffMode) + 1;
62 bm < static_cast<int>(SkBlendMode::kLastMode);
63 ++bm) {
64 canvas->drawImageRect(duckyBG, kDstRect, sampling, nullptr);
66 paint.setBlendMode(static_cast<SkBlendMode>(bm));
67 canvas->drawImageRect(fg, kDstRect, sampling, &paint);
68 canvas->translate(kDstRect.width() + kPad, 0);
69 if (++rowCnt == kNumPerRow) {
70 newRow();
71 }
72 }
73 // Force a new row between the two foreground images
74 newRow();
75 }
76 canvas->restore();
78}
sk_sp< SkData > GetResourceAsData(const char *resource)
Definition: Resources.cpp:42
SkBlendMode
Definition: SkBlendMode.h:38
@ kLastCoeffMode
last porter duff blend mode
@ kLastMode
last valid value
constexpr SkColor SK_ColorLTGRAY
Definition: SkColor.h:118
constexpr SkColor SK_ColorDKGRAY
Definition: SkColor.h:108
constexpr int kPad
static std::unique_ptr< LazyYUVImage > Make(sk_sp< SkData > data, skgpu::Mipmapped=skgpu::Mipmapped::kNo, sk_sp< SkColorSpace >=nullptr)
Definition: YUVUtils.cpp:200
const Paint & paint
Definition: color_source.cc:38
SkSamplingOptions sampling
Definition: SkRecords.h:337
void draw_checkerboard(SkCanvas *canvas, SkColor c1, SkColor c2, int size)
Definition: ToolUtils.cpp:174
sk_sp< SkImage > GetResourceAsImage(const char *resource)
Definition: DecodeUtils.h:25
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609