• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 #ifndef HISTOGRAM_HISTOGRAM_COLLECTOR_H_
18 #define HISTOGRAM_HISTOGRAM_COLLECTOR_H_
19 #include <string>
20 #include <thread>
21 #define HWC2_INCLUDE_STRINGIFICATION
22 #define HWC2_USE_CPP11
23 #include <hardware/hwcomposer2.h>
24 #undef HWC2_INCLUDE_STRINGIFICATION
25 #undef HWC2_USE_CPP11
26 
27 //number of enums in hwc2_format_color_component_t;
28 #define NUM_HISTOGRAM_COLOR_COMPONENTS 4
29 
30 namespace histogram {
31 
32 class Ringbuffer;
33 class HistogramCollector
34 {
35 public:
36     HistogramCollector();
37     ~HistogramCollector();
38 
39     void start();
40     void start(uint64_t max_frames);
41     void stop();
42 
43     std::string Dump() const;
44 
45     HWC2::Error collect(uint64_t max_frames,
46                         uint64_t timestamp,
47                         int32_t samples_size[NUM_HISTOGRAM_COLOR_COMPONENTS],
48                         uint64_t* samples[NUM_HISTOGRAM_COLOR_COMPONENTS],
49                         uint64_t* numFrames) const;
50     HWC2::Error getAttributes(int32_t* format,
51                               int32_t* dataspace,
52                               uint8_t* supported_components) const;
53 
54 private:
55     HistogramCollector(HistogramCollector const&) = delete;
56     HistogramCollector& operator=(HistogramCollector const&) = delete;
57     void collecting_thread(int pipe);
58 
59     std::mutex thread_control;
60     bool started = false;
61     std::thread monitoring_thread;
62     int selfpipe[2];
63 
64     std::unique_ptr<histogram::Ringbuffer> histogram;
65 
66 };
67 
68 }  // namespace histogram
69 
70 #endif  // HISTOGRAM_HISTOGRAM_COLLECTOR_H_
71