1818#include < android-base/unique_fd.h>
1919#include < binder/Parcel.h>
2020#include < binder/Parcelable.h>
21+ #include < cutils/ashmem.h>
22+ #include < sys/mman.h>
23+ #include < algorithm>
24+ #include < ostream>
2125#include < vector>
2226
2327namespace android ::gui {
@@ -62,4 +66,99 @@ struct DisplayLuts : public Parcelable {
6266 base::unique_fd fd;
6367}; // struct DisplayLuts
6468
69+ static inline void PrintTo (const std::vector<int32_t >& offsets, ::std::ostream* os) {
70+ *os << " \n .offsets = {" ;
71+ for (size_t i = 0 ; i < offsets.size (); i++) {
72+ *os << offsets[i];
73+ if (i != offsets.size () - 1 ) {
74+ *os << " , " ;
75+ }
76+ }
77+ *os << " }" ;
78+ }
79+
80+ static inline void PrintTo (const std::vector<DisplayLuts::Entry>& entries, ::std::ostream* os) {
81+ *os << " \n .lutProperties = {\n " ;
82+ for (auto & [dimension, size, samplingKey] : entries) {
83+ *os << " Entry{"
84+ << " dimension: " << dimension << " , size: " << size << " , samplingKey: " << samplingKey
85+ << " }\n " ;
86+ }
87+ *os << " }" ;
88+ }
89+
90+ static constexpr size_t kMaxPrintCount = 100 ;
91+
92+ static inline void PrintTo (const std::vector<float >& buffer, size_t offset, int32_t dimension,
93+ size_t size, ::std::ostream* os) {
94+ size_t range = std::min (size, kMaxPrintCount );
95+ *os << " {" ;
96+ if (dimension == 1 ) {
97+ for (size_t i = 0 ; i < range; i++) {
98+ *os << buffer[offset + i];
99+ if (i != range - 1 ) {
100+ *os << " , " ;
101+ }
102+ }
103+ } else {
104+ *os << " \n {R channel:" ;
105+ for (size_t i = 0 ; i < range; i++) {
106+ *os << buffer[offset + i];
107+ if (i != range - 1 ) {
108+ *os << " , " ;
109+ }
110+ }
111+ *os << " }\n {G channel:" ;
112+ for (size_t i = 0 ; i < range; i++) {
113+ *os << buffer[offset + size + i];
114+ if (i != range - 1 ) {
115+ *os << " , " ;
116+ }
117+ }
118+ *os << " }\n {B channel:" ;
119+ for (size_t i = 0 ; i < range; i++) {
120+ *os << buffer[offset + 2 * size + i];
121+ if (i != range - 1 ) {
122+ *os << " , " ;
123+ }
124+ }
125+ }
126+ *os << " }" ;
127+ }
128+
129+ static inline void PrintTo (const std::shared_ptr<DisplayLuts> luts, ::std::ostream* os) {
130+ *os << " gui::DisplayLuts {" ;
131+ auto & fd = luts->getLutFileDescriptor ();
132+ *os << " \n .pfd = " << fd.get ();
133+ if (fd.ok ()) {
134+ PrintTo (luts->offsets , os);
135+ PrintTo (luts->lutProperties , os);
136+ // decode luts
137+ int32_t fullLength = luts->offsets [luts->offsets .size () - 1 ];
138+ if (luts->lutProperties [luts->offsets .size () - 1 ].dimension == 1 ) {
139+ fullLength += luts->lutProperties [luts->offsets .size () - 1 ].size ;
140+ } else {
141+ fullLength += (luts->lutProperties [luts->offsets .size () - 1 ].size *
142+ luts->lutProperties [luts->offsets .size () - 1 ].size *
143+ luts->lutProperties [luts->offsets .size () - 1 ].size * 3 );
144+ }
145+ size_t bufferSize = static_cast <size_t >(fullLength) * sizeof (float );
146+ float * ptr = (float *)mmap (NULL , bufferSize, PROT_READ, MAP_SHARED, fd.get (), 0 );
147+ if (ptr == MAP_FAILED) {
148+ *os << " \n .bufferdata cannot mmap!" ;
149+ return ;
150+ }
151+ std::vector<float > buffers (ptr, ptr + fullLength);
152+ munmap (ptr, bufferSize);
153+
154+ *os << " \n .bufferdata = " ;
155+ for (size_t i = 0 ; i < luts->offsets .size (); i++) {
156+ PrintTo (buffers, static_cast <size_t >(luts->offsets [i]),
157+ luts->lutProperties [i].dimension ,
158+ static_cast <size_t >(luts->lutProperties [i].size ), os);
159+ }
160+ }
161+ *os << " \n }" ;
162+ }
163+
65164} // namespace android::gui
0 commit comments