Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / skia / gm / clear_swizzle.cpp
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 #include "include/core/SkColorSpace.h"
11 #include "include/core/SkPoint.h"
12 #include "include/core/SkRect.h"
13 #include "include/private/SkColorData.h"
14 #include "src/core/SkCanvasPriv.h"
15 #include "src/gpu/Swizzle.h"
16 #include "src/gpu/ganesh/GrRecordingContextPriv.h"
17 #include "src/gpu/ganesh/SurfaceFillContext.h"
18
19 namespace skiagm {
20
21 // Size of each clear
22 static constexpr int kSize = 64;
23
24 DEF_SIMPLE_GPU_GM_CAN_FAIL(clear_swizzle, rContext, canvas, errorMsg, 6*kSize, 2*kSize) {
25     if (rContext->abandoned()) {
26         *errorMsg = GM::kErrorMsg_DrawSkippedGpuOnly;
27         return DrawResult::kSkip;
28     }
29
30     auto sfc = SkCanvasPriv::TopDeviceSurfaceFillContext(canvas);
31     if (!sfc) {
32         *errorMsg = GM::kErrorMsg_DrawSkippedGpuOnly;
33         return DrawResult::kSkip;
34     }
35
36     auto make_offscreen = [&](const SkISize dimensions) {
37         skgpu::Swizzle readSwizzle  = skgpu::Swizzle::Concat(sfc->readSwizzle(),
38                                                              skgpu::Swizzle{"bgra"});
39         skgpu::Swizzle writeSwizzle = skgpu::Swizzle::Concat(sfc->readSwizzle(),
40                                                              skgpu::Swizzle{"bgra"});
41         return rContext->priv().makeSFC(kPremul_SkAlphaType,
42                                         sfc->colorInfo().refColorSpace(),
43                                         dimensions,
44                                         SkBackingFit::kExact,
45                                         sfc->asSurfaceProxy()->backendFormat(),
46                                         /* sample count*/ 1,
47                                         GrMipmapped::kNo,
48                                         sfc->asSurfaceProxy()->isProtected(),
49                                         readSwizzle,
50                                         writeSwizzle,
51                                         kTopLeft_GrSurfaceOrigin,
52                                         SkBudgeted::kYes);
53     };
54
55     struct {
56         SkIRect rect;
57         SkPMColor4f color;
58     } clears[] {
59             {{    0,     0,   kSize,   kSize}, {1, 0, 0, 1}},
60             {{kSize,     0, 2*kSize,   kSize}, {0, 1, 0, 1}},
61             {{    0, kSize,   kSize, 2*kSize}, {0, 0, 1, 1}},
62             {{kSize, kSize, 2*kSize, 2*kSize}, {1, 0, 1, 1}},
63     };
64
65     // onscreen for reference
66     for (const auto& c : clears) {
67         sfc->clear(c.rect, c.color);
68     }
69
70     // partial clear offscreen
71     auto offscreen = make_offscreen({2*kSize, 2*kSize});
72     for (const auto& c : clears) {
73         offscreen->clear(c.rect, c.color);
74     }
75     sfc->blitTexture(offscreen->readSurfaceView(),
76                      SkIRect::MakeSize({2*kSize, 2*kSize}),
77                      SkIPoint{2*kSize, 0});
78
79     // full offscreen clears
80     for (const auto& c : clears) {
81         offscreen = make_offscreen(c.rect.size());
82         offscreen->clear(SkIRect::MakeSize(c.rect.size()), c.color);
83         sfc->blitTexture(offscreen->readSurfaceView(),
84                          SkIRect::MakeSize(offscreen->dimensions()),
85                          c.rect.topLeft() + SkIPoint{4*kSize, 0});
86     }
87
88     return DrawResult::kOk;
89 }
90
91 } // namespace skiagm