blob: 0953c4e832c77ae566e713a3d4470a2cbced112f [file] [log] [blame]
Jorge E. Moreiraccd57452017-09-29 15:19:07 -07001#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 */
Jorge E. Moreira24307012017-09-22 14:35:21 -070018
Jorge E. Moreira24307012017-09-22 14:35:21 -070019#include <array>
Jorge E. Moreira24307012017-09-22 14:35:21 -070020#include <cstdint>
Greg Hartman70753782017-09-28 16:12:43 -070021#include <utility>
22#include <vector>
Jorge E. Moreira24307012017-09-22 14:35:21 -070023
Jorge E. Moreirac87c2c72019-03-06 16:12:23 -080024#include "common/libs/utils/size_utils.h"
Ryan Haining5dc3ab22018-01-25 13:03:06 -080025#include "common/libs/tcp_socket/tcp_socket.h"
Cody Schuffelen134ff032019-11-22 00:25:32 -080026#include "common/vsoc/lib/screen_region_view.h"
Jorge E. Moreira08ea9e42018-05-24 14:17:51 -070027#include "host/libs/config/cuttlefish_config.h"
Jorge E. Moreira24307012017-09-22 14:35:21 -070028
Greg Hartman153b1062017-11-11 12:09:21 -080029namespace cvd {
Jorge E. Moreira24307012017-09-22 14:35:21 -070030namespace 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;
35class StripeSeqNumber {
36 public:
37 StripeSeqNumber() = default;
38 explicit StripeSeqNumber(std::uint64_t t) : t_{t} {}
Greg Hartman70753782017-09-28 16:12:43 -070039 bool operator<(const StripeSeqNumber& other) const { return t_ < other.t_; }
Jorge E. Moreira24307012017-09-22 14:35:21 -070040
Greg Hartman70753782017-09-28 16:12:43 -070041 bool operator<=(const StripeSeqNumber& other) const { return t_ <= other.t_; }
Jorge E. Moreira24307012017-09-22 14:35:21 -070042
43 private:
44 std::uint64_t t_{};
45};
46
Jorge E. Moreira24307012017-09-22 14:35:21 -070047constexpr int32_t kJpegMaxQualityEncoding = -23;
48constexpr int32_t kJpegMinQualityEncoding = -32;
49
50enum class ScreenOrientation { Portrait, Landscape };
51constexpr int kNumOrientations = 2;
52
53struct 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{};
Jorge E. Moreiraf1630092019-04-05 16:14:03 -070059 std::uint16_t stride{};
Jorge E. Moreira24307012017-09-22 14:35:21 -070060 std::uint16_t height{};
61 Message raw_data{};
62 Message jpeg_data{};
63 StripeSeqNumber seq_number{};
64 ScreenOrientation orientation{};
65};
66
Jorge E. Moreira02ccbd52018-01-25 16:57:48 -080067inline constexpr int BytesPerPixel() {
Cody Schuffelen134ff032019-11-22 00:25:32 -080068 return sizeof(vsoc::screen::ScreenRegionView::Pixel);
Greg Hartmanca7fb192017-09-28 16:14:12 -070069}
Jorge E. Moreira24307012017-09-22 14:35:21 -070070
71// The width of the screen regardless of orientation. Does not change.
Greg Hartmanca7fb192017-09-28 16:14:12 -070072inline int ActualScreenWidth() {
Jorge E. Moreiraf1630092019-04-05 16:14:03 -070073 return vsoc::CuttlefishConfig::Get()->x_res();
74}
75
76// The length of the screen stride regardless of orientation. Does not change.
77inline int ActualScreenStride() {
78 return AlignToPowerOf2(ActualScreenWidth() * BytesPerPixel(), 4);
Greg Hartmanca7fb192017-09-28 16:14:12 -070079}
Jorge E. Moreira24307012017-09-22 14:35:21 -070080
81// The height of the screen regardless of orientation. Does not change.
82inline int ActualScreenHeight() {
Jorge E. Moreirac87c2c72019-03-06 16:12:23 -080083 return vsoc::CuttlefishConfig::Get()->y_res();
Jorge E. Moreira24307012017-09-22 14:35:21 -070084}
85
86inline int ScreenSizeInBytes() {
87 return ActualScreenWidth() * ActualScreenHeight() * BytesPerPixel();
88}
89
90} // namespace vnc
Greg Hartman153b1062017-11-11 12:09:21 -080091} // namespace cvd