1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "recovery_ui/vr_ui.h"
18 
19 #include <android-base/properties.h>
20 
21 #include "minui/minui.h"
22 
23 constexpr int kDefaultStereoOffset = 0;
24 
VrRecoveryUI()25 VrRecoveryUI::VrRecoveryUI()
26     : stereo_offset_(
27           android::base::GetIntProperty("ro.recovery.ui.stereo_offset", kDefaultStereoOffset)) {}
28 
ScreenWidth() const29 int VrRecoveryUI::ScreenWidth() const {
30   return gr_fb_width() / 2;
31 }
32 
ScreenHeight() const33 int VrRecoveryUI::ScreenHeight() const {
34   return gr_fb_height();
35 }
36 
DrawSurface(const GRSurface * surface,int sx,int sy,int w,int h,int dx,int dy) const37 void VrRecoveryUI::DrawSurface(const GRSurface* surface, int sx, int sy, int w, int h, int dx,
38                                int dy) const {
39   gr_blit(surface, sx, sy, w, h, dx + stereo_offset_, dy);
40   gr_blit(surface, sx, sy, w, h, dx - stereo_offset_ + ScreenWidth(), dy);
41 }
42 
DrawTextIcon(int x,int y,const GRSurface * surface) const43 void VrRecoveryUI::DrawTextIcon(int x, int y, const GRSurface* surface) const {
44   gr_texticon(x + stereo_offset_, y, surface);
45   gr_texticon(x - stereo_offset_ + ScreenWidth(), y, surface);
46 }
47 
DrawTextLine(int x,int y,const std::string & line,bool bold) const48 int VrRecoveryUI::DrawTextLine(int x, int y, const std::string& line, bool bold) const {
49   gr_text(gr_sys_font(), x + stereo_offset_, y, line.c_str(), bold);
50   gr_text(gr_sys_font(), x - stereo_offset_ + ScreenWidth(), y, line.c_str(), bold);
51   return char_height_ + 4;
52 }
53 
DrawHorizontalRule(int y) const54 int VrRecoveryUI::DrawHorizontalRule(int y) const {
55   y += 4;
56   gr_fill(margin_width_ + stereo_offset_, y, ScreenWidth() - margin_width_ + stereo_offset_, y + 2);
57   gr_fill(ScreenWidth() + margin_width_ - stereo_offset_, y,
58           gr_fb_width() - margin_width_ - stereo_offset_, y + 2);
59   return y + 4;
60 }
61 
DrawHighlightBar(int,int y,int,int height) const62 void VrRecoveryUI::DrawHighlightBar(int /* x */, int y, int /* width */, int height) const {
63   gr_fill(margin_width_ + stereo_offset_, y, ScreenWidth() - margin_width_ + stereo_offset_,
64           y + height);
65   gr_fill(ScreenWidth() + margin_width_ - stereo_offset_, y,
66           gr_fb_width() - margin_width_ - stereo_offset_, y + height);
67 }
68 
DrawFill(int x,int y,int w,int h) const69 void VrRecoveryUI::DrawFill(int x, int y, int w, int h) const {
70   gr_fill(x + stereo_offset_, y, w, h);
71   gr_fill(x - stereo_offset_ + ScreenWidth(), y, w, h);
72 }
73