• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #pragma once
2 
3 /*
4  * Copyright (C) 2017 The Android Open Source Project
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #include <array>
20 #include <cstdint>
21 #include <utility>
22 #include <vector>
23 
24 #include "common/libs/utils/size_utils.h"
25 #include "common/libs/tcp_socket/tcp_socket.h"
26 #include "common/vsoc/lib/screen_region_view.h"
27 #include "host/libs/config/cuttlefish_config.h"
28 
29 namespace cvd {
30 namespace vnc {
31 
32 // TODO(haining) when the hwcomposer gives a sequence number type, use that
33 // instead. It might just work to replace this class with a type alias
34 // using StripeSeqNumber = whatever_the_hwcomposer_uses;
35 class StripeSeqNumber {
36  public:
37   StripeSeqNumber() = default;
StripeSeqNumber(std::uint64_t t)38   explicit StripeSeqNumber(std::uint64_t t) : t_{t} {}
39   bool operator<(const StripeSeqNumber& other) const { return t_ < other.t_; }
40 
41   bool operator<=(const StripeSeqNumber& other) const { return t_ <= other.t_; }
42 
43  private:
44   std::uint64_t t_{};
45 };
46 
47 constexpr int32_t kJpegMaxQualityEncoding = -23;
48 constexpr int32_t kJpegMinQualityEncoding = -32;
49 
50 enum class ScreenOrientation { Portrait, Landscape };
51 constexpr int kNumOrientations = 2;
52 
53 struct Stripe {
54   int index = -1;
55   std::uint64_t frame_id{};
56   std::uint16_t x{};
57   std::uint16_t y{};
58   std::uint16_t width{};
59   std::uint16_t stride{};
60   std::uint16_t height{};
61   Message raw_data{};
62   Message jpeg_data{};
63   StripeSeqNumber seq_number{};
64   ScreenOrientation orientation{};
65 };
66 
BytesPerPixel()67 inline constexpr int BytesPerPixel() {
68   return sizeof(vsoc::screen::ScreenRegionView::Pixel);
69 }
70 
71 // The width of the screen regardless of orientation. Does not change.
ActualScreenWidth()72 inline int ActualScreenWidth() {
73   return vsoc::CuttlefishConfig::Get()->x_res();
74 }
75 
76 // The length of the screen stride regardless of orientation. Does not change.
ActualScreenStride()77 inline int ActualScreenStride() {
78   return AlignToPowerOf2(ActualScreenWidth() * BytesPerPixel(), 4);
79 }
80 
81 // The height of the screen regardless of orientation. Does not change.
ActualScreenHeight()82 inline int ActualScreenHeight() {
83   return vsoc::CuttlefishConfig::Get()->y_res();
84 }
85 
ScreenSizeInBytes()86 inline int ScreenSizeInBytes() {
87   return ActualScreenWidth() * ActualScreenHeight() * BytesPerPixel();
88 }
89 
90 }  // namespace vnc
91 }  // namespace cvd
92