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 | |
Greg Hartman | 86b114a | 2017-11-03 21:04:14 -0700 | [diff] [blame] | 24 | #include "common/vsoc/framebuffer/fb_bcast_region_view.h" |
Jorge E. Moreira | 2430701 | 2017-09-22 14:35:21 -0700 | [diff] [blame] | 25 | |
Greg Hartman | 153b106 | 2017-11-11 12:09:21 -0800 | [diff] [blame^] | 26 | namespace cvd { |
Jorge E. Moreira | 2430701 | 2017-09-22 14:35:21 -0700 | [diff] [blame] | 27 | namespace 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; |
| 32 | class StripeSeqNumber { |
| 33 | public: |
| 34 | StripeSeqNumber() = default; |
| 35 | explicit StripeSeqNumber(std::uint64_t t) : t_{t} {} |
Greg Hartman | 7075378 | 2017-09-28 16:12:43 -0700 | [diff] [blame] | 36 | bool operator<(const StripeSeqNumber& other) const { return t_ < other.t_; } |
Jorge E. Moreira | 2430701 | 2017-09-22 14:35:21 -0700 | [diff] [blame] | 37 | |
Greg Hartman | 7075378 | 2017-09-28 16:12:43 -0700 | [diff] [blame] | 38 | bool operator<=(const StripeSeqNumber& other) const { return t_ <= other.t_; } |
Jorge E. Moreira | 2430701 | 2017-09-22 14:35:21 -0700 | [diff] [blame] | 39 | |
| 40 | private: |
| 41 | std::uint64_t t_{}; |
| 42 | }; |
| 43 | |
| 44 | using Message = std::vector<std::uint8_t>; |
| 45 | |
| 46 | constexpr int32_t kJpegMaxQualityEncoding = -23; |
| 47 | constexpr int32_t kJpegMinQualityEncoding = -32; |
| 48 | |
| 49 | enum class ScreenOrientation { Portrait, Landscape }; |
| 50 | constexpr int kNumOrientations = 2; |
| 51 | |
| 52 | struct 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 Hartman | 86b114a | 2017-11-03 21:04:14 -0700 | [diff] [blame] | 65 | vsoc::framebuffer::FBBroadcastRegionView* GetFBBroadcastRegionView(); |
| 66 | |
Greg Hartman | ca7fb19 | 2017-09-28 16:14:12 -0700 | [diff] [blame] | 67 | inline int BytesPerPixel() { |
Greg Hartman | 86b114a | 2017-11-03 21:04:14 -0700 | [diff] [blame] | 68 | return GetFBBroadcastRegionView()->bytes_per_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() { |
Greg Hartman | 86b114a | 2017-11-03 21:04:14 -0700 | [diff] [blame] | 73 | return GetFBBroadcastRegionView()->x_res(); |
Greg Hartman | ca7fb19 | 2017-09-28 16:14:12 -0700 | [diff] [blame] | 74 | } |
Jorge E. Moreira | 2430701 | 2017-09-22 14:35:21 -0700 | [diff] [blame] | 75 | |
| 76 | // The height of the screen regardless of orientation. Does not change. |
| 77 | inline int ActualScreenHeight() { |
Greg Hartman | 86b114a | 2017-11-03 21:04:14 -0700 | [diff] [blame] | 78 | return GetFBBroadcastRegionView()->y_res(); |
Jorge E. Moreira | 2430701 | 2017-09-22 14:35:21 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | inline int ScreenSizeInBytes() { |
| 82 | return ActualScreenWidth() * ActualScreenHeight() * BytesPerPixel(); |
| 83 | } |
| 84 | |
| 85 | } // namespace vnc |
Greg Hartman | 153b106 | 2017-11-11 12:09:21 -0800 | [diff] [blame^] | 86 | } // namespace cvd |