1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <stdint.h>
20 #include <sys/time.h>
21 
22 namespace cuttlefish {
23 
24 struct CompositionStats {
25   uint32_t num_prepare_calls;
26   uint16_t num_layers;
27   uint16_t num_hwcomposited_layers;
28   timespec last_vsync;
29   timespec prepare_start;
30   timespec prepare_end;
31   timespec set_start;
32   timespec set_end;
33 };
34 
35 class ScreenView {
36  public:
37   ScreenView() = default;
38   ScreenView(const ScreenView&) = delete;
39   virtual ~ScreenView() = default;
40 
41   ScreenView& operator=(const ScreenView&) = delete;
42 
43   virtual void Broadcast(int buffer_id,
44                          const CompositionStats* stats = nullptr) = 0;
45   virtual int NextBuffer();
46   virtual void* GetBuffer(int buffer_id) = 0;
47 
48   virtual int32_t x_res() const = 0;
49   virtual int32_t y_res() const = 0;
50   virtual int32_t dpi() const = 0;
51   virtual int32_t refresh_rate() const = 0;
52 
53   size_t buffer_size() const;
54   size_t line_length() const;
55   int bytes_per_pixel() const;
56 
57   virtual int num_buffers() const = 0;
58 
59  private:
60   int last_buffer_ = 0;
61 };
62 }  // namespace cuttlefish