1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, Hardware
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <csignal>
17 #include <iostream>
18
19 #include "dm/display_manager.h"
20 #include "pipeline/rs_render_thread.h"
21 #include "ui/rs_surface_extractor.h"
22
23 using namespace OHOS;
24 using namespace OHOS::Rosen;
25 using namespace std;
26
27 constexpr float X_RATIO = 0.5;
28 constexpr float Y_RATIO = 0.68;
29 constexpr float RADIUS = 200;
30 constexpr float MAX_ZORDER = 100000.0f;
31 constexpr int SLEEP_TIME = 5;
32 static volatile sig_atomic_t g_flag = 0;
33
Handler(int sig)34 static void Handler(int sig)
35 {
36 g_flag = 1;
37 }
38
main()39 int main()
40 {
41 signal(SIGINT, Handler);
42
43 RSSurfaceNodeConfig config = {
44 .SurfaceNodeName = "FingerprintSurfaceNodeTest"
45 };
46
47 auto renderContext = std::make_shared<RenderContext>();
48 renderContext->InitializeEglContext();
49
50 auto surfaceNode = RSSurfaceNode::Create(config, RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE);
51 auto defaultDisplay = DisplayManager::GetInstance().GetDefaultDisplay();
52 surfaceNode->SetBounds(0, 0, defaultDisplay->GetWidth(), defaultDisplay->GetHeight());
53
54 std::shared_ptr<RSSurface> rsSurface = RSSurfaceExtractor::ExtractRSSurface(surfaceNode);
55 rsSurface->SetRenderContext(renderContext.get());
56
57 auto surfaceFrame = rsSurface->RequestFrame(defaultDisplay->GetWidth(), defaultDisplay->GetHeight());
58 auto skSurface = surfaceFrame->GetSurface();
59 auto canvas = std::make_shared<RSPaintFilterCanvas>(skSurface.get());
60
61 SkPaint paint;
62 paint.setStyle(SkPaint::kFill_Style);
63 paint.setAntiAlias(true);
64 paint.setColor(SK_ColorWHITE);
65 canvas->drawCircle(SkPoint::Make(defaultDisplay->GetWidth() * X_RATIO,
66 defaultDisplay->GetHeight() * Y_RATIO), RADIUS, paint);
67
68 rsSurface->FlushFrame(surfaceFrame);
69 surfaceNode->SetFingerprint(true);
70
71 DisplayId id = DisplayManager::GetInstance().GetDefaultDisplayId();
72 surfaceNode->SetPositionZ(MAX_ZORDER);
73 surfaceNode->AttachToDisplay(id);
74
75 auto transactionProxy = RSTransactionProxy::GetInstance();
76 transactionProxy->FlushImplicitTransaction();
77
78 while (1) {
79 if (g_flag) {
80 cout << "Terminated by Ctrl+C." << endl;
81 break;
82 }
83 }
84
85 surfaceNode->DetachToDisplay(id);
86 transactionProxy->FlushImplicitTransaction();
87 sleep(SLEEP_TIME);
88 return 0;
89 }
90