blob: 5c88754294b729b79b99051ba0742dad60576fb5 [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
Greg Hartman86b114a2017-11-03 21:04:14 -070024#include "common/vsoc/framebuffer/fb_bcast_region_view.h"
Jorge E. Moreira24307012017-09-22 14:35:21 -070025
Greg Hartman153b1062017-11-11 12:09:21 -080026namespace cvd {
Jorge E. Moreira24307012017-09-22 14:35:21 -070027namespace vnc {
28
29// TODO(haining) when the hwcomposer gives a sequence number type, use that
30// instead. It might just work to replace this class with a type alias
31// using StripeSeqNumber = whatever_the_hwcomposer_uses;
32class StripeSeqNumber {
33 public:
34 StripeSeqNumber() = default;
35 explicit StripeSeqNumber(std::uint64_t t) : t_{t} {}
Greg Hartman70753782017-09-28 16:12:43 -070036 bool operator<(const StripeSeqNumber& other) const { return t_ < other.t_; }
Jorge E. Moreira24307012017-09-22 14:35:21 -070037
Greg Hartman70753782017-09-28 16:12:43 -070038 bool operator<=(const StripeSeqNumber& other) const { return t_ <= other.t_; }
Jorge E. Moreira24307012017-09-22 14:35:21 -070039
40 private:
41 std::uint64_t t_{};
42};
43
44using Message = std::vector<std::uint8_t>;
45
46constexpr int32_t kJpegMaxQualityEncoding = -23;
47constexpr int32_t kJpegMinQualityEncoding = -32;
48
49enum class ScreenOrientation { Portrait, Landscape };
50constexpr int kNumOrientations = 2;
51
52struct Stripe {
53 int index = -1;
54 std::uint64_t frame_id{};
55 std::uint16_t x{};
56 std::uint16_t y{};
57 std::uint16_t width{};
58 std::uint16_t height{};
59 Message raw_data{};
60 Message jpeg_data{};
61 StripeSeqNumber seq_number{};
62 ScreenOrientation orientation{};
63};
64
Greg Hartman86b114a2017-11-03 21:04:14 -070065vsoc::framebuffer::FBBroadcastRegionView* GetFBBroadcastRegionView();
66
Greg Hartmanca7fb192017-09-28 16:14:12 -070067inline int BytesPerPixel() {
Greg Hartman86b114a2017-11-03 21:04:14 -070068 return GetFBBroadcastRegionView()->bytes_per_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() {
Greg Hartman86b114a2017-11-03 21:04:14 -070073 return GetFBBroadcastRegionView()->x_res();
Greg Hartmanca7fb192017-09-28 16:14:12 -070074}
Jorge E. Moreira24307012017-09-22 14:35:21 -070075
76// The height of the screen regardless of orientation. Does not change.
77inline int ActualScreenHeight() {
Greg Hartman86b114a2017-11-03 21:04:14 -070078 return GetFBBroadcastRegionView()->y_res();
Jorge E. Moreira24307012017-09-22 14:35:21 -070079}
80
81inline int ScreenSizeInBytes() {
82 return ActualScreenWidth() * ActualScreenHeight() * BytesPerPixel();
83}
84
85} // namespace vnc
Greg Hartman153b1062017-11-11 12:09:21 -080086} // namespace cvd