Jorge E. Moreira | ccd5745 | 2017-09-29 15:19:07 -0700 | [diff] [blame] | 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 | */ |
Jorge E. Moreira | 2430701 | 2017-09-22 14:35:21 -0700 | [diff] [blame] | 18 | |
Jorge E. Moreira | 2430701 | 2017-09-22 14:35:21 -0700 | [diff] [blame] | 19 | #include <array> |
Jorge E. Moreira | 2430701 | 2017-09-22 14:35:21 -0700 | [diff] [blame] | 20 | #include <cstdint> |
Greg Hartman | 7075378 | 2017-09-28 16:12:43 -0700 | [diff] [blame] | 21 | #include <utility> |
| 22 | #include <vector> |
Jorge E. Moreira | 2430701 | 2017-09-22 14:35:21 -0700 | [diff] [blame] | 23 | |
Jorge E. Moreira | c87c2c7 | 2019-03-06 16:12:23 -0800 | [diff] [blame] | 24 | #include "common/libs/utils/size_utils.h" |
Ryan Haining | 5dc3ab2 | 2018-01-25 13:03:06 -0800 | [diff] [blame] | 25 | #include "common/libs/tcp_socket/tcp_socket.h" |
Jorge E. Moreira | a581090 | 2018-02-13 11:50:34 -0800 | [diff] [blame] | 26 | #include "common/vsoc/lib/screen_region_view.h" |
Jorge E. Moreira | 08ea9e4 | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 27 | #include "host/libs/config/cuttlefish_config.h" |
Jorge E. Moreira | 2430701 | 2017-09-22 14:35:21 -0700 | [diff] [blame] | 28 | |
Greg Hartman | 153b106 | 2017-11-11 12:09:21 -0800 | [diff] [blame] | 29 | namespace cvd { |
Jorge E. Moreira | 2430701 | 2017-09-22 14:35:21 -0700 | [diff] [blame] | 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; |
| 38 | explicit StripeSeqNumber(std::uint64_t t) : t_{t} {} |
Greg Hartman | 7075378 | 2017-09-28 16:12:43 -0700 | [diff] [blame] | 39 | bool operator<(const StripeSeqNumber& other) const { return t_ < other.t_; } |
Jorge E. Moreira | 2430701 | 2017-09-22 14:35:21 -0700 | [diff] [blame] | 40 | |
Greg Hartman | 7075378 | 2017-09-28 16:12:43 -0700 | [diff] [blame] | 41 | bool operator<=(const StripeSeqNumber& other) const { return t_ <= other.t_; } |
Jorge E. Moreira | 2430701 | 2017-09-22 14:35:21 -0700 | [diff] [blame] | 42 | |
| 43 | private: |
| 44 | std::uint64_t t_{}; |
| 45 | }; |
| 46 | |
Jorge E. Moreira | 2430701 | 2017-09-22 14:35:21 -0700 | [diff] [blame] | 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{}; |
Jorge E. Moreira | 91ce18a | 2019-04-05 16:14:03 -0700 | [diff] [blame] | 59 | std::uint16_t stride{}; |
Jorge E. Moreira | 2430701 | 2017-09-22 14:35:21 -0700 | [diff] [blame] | 60 | std::uint16_t height{}; |
| 61 | Message raw_data{}; |
| 62 | Message jpeg_data{}; |
| 63 | StripeSeqNumber seq_number{}; |
| 64 | ScreenOrientation orientation{}; |
| 65 | }; |
| 66 | |
Jorge E. Moreira | 02ccbd5 | 2018-01-25 16:57:48 -0800 | [diff] [blame] | 67 | inline constexpr int BytesPerPixel() { |
Jorge E. Moreira | a581090 | 2018-02-13 11:50:34 -0800 | [diff] [blame] | 68 | return sizeof(vsoc::screen::ScreenRegionView::Pixel); |
Greg Hartman | ca7fb19 | 2017-09-28 16:14:12 -0700 | [diff] [blame] | 69 | } |
Jorge E. Moreira | 2430701 | 2017-09-22 14:35:21 -0700 | [diff] [blame] | 70 | |
| 71 | // The width of the screen regardless of orientation. Does not change. |
Greg Hartman | ca7fb19 | 2017-09-28 16:14:12 -0700 | [diff] [blame] | 72 | inline int ActualScreenWidth() { |
Jorge E. Moreira | 91ce18a | 2019-04-05 16:14:03 -0700 | [diff] [blame] | 73 | return vsoc::CuttlefishConfig::Get()->x_res(); |
| 74 | } |
| 75 | |
| 76 | // The length of the screen stride regardless of orientation. Does not change. |
| 77 | inline int ActualScreenStride() { |
| 78 | return AlignToPowerOf2(ActualScreenWidth() * BytesPerPixel(), 4); |
Greg Hartman | ca7fb19 | 2017-09-28 16:14:12 -0700 | [diff] [blame] | 79 | } |
Jorge E. Moreira | 2430701 | 2017-09-22 14:35:21 -0700 | [diff] [blame] | 80 | |
| 81 | // The height of the screen regardless of orientation. Does not change. |
| 82 | inline int ActualScreenHeight() { |
Jorge E. Moreira | c87c2c7 | 2019-03-06 16:12:23 -0800 | [diff] [blame] | 83 | return vsoc::CuttlefishConfig::Get()->y_res(); |
Jorge E. Moreira | 2430701 | 2017-09-22 14:35:21 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | inline int ScreenSizeInBytes() { |
| 87 | return ActualScreenWidth() * ActualScreenHeight() * BytesPerPixel(); |
| 88 | } |
| 89 | |
| 90 | } // namespace vnc |
Greg Hartman | 153b106 | 2017-11-11 12:09:21 -0800 | [diff] [blame] | 91 | } // namespace cvd |