Home | History | Annotate | Download | only in gui
      1 /*
      2  * Copyright 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 #include <gui/HdrMetadata.h>
     18 
     19 namespace android {
     20 
     21 size_t HdrMetadata::getFlattenedSize() const {
     22     size_t size = sizeof(validTypes);
     23     if (validTypes & SMPTE2086) {
     24         size += sizeof(smpte2086);
     25     }
     26     if (validTypes & CTA861_3) {
     27         size += sizeof(cta8613);
     28     }
     29     return size;
     30 }
     31 
     32 status_t HdrMetadata::flatten(void* buffer, size_t size) const {
     33     if (size < getFlattenedSize()) {
     34         return NO_MEMORY;
     35     }
     36 
     37     FlattenableUtils::write(buffer, size, validTypes);
     38     if (validTypes & SMPTE2086) {
     39         FlattenableUtils::write(buffer, size, smpte2086);
     40     }
     41     if (validTypes & CTA861_3) {
     42         FlattenableUtils::write(buffer, size, cta8613);
     43     }
     44 
     45     return NO_ERROR;
     46 }
     47 
     48 status_t HdrMetadata::unflatten(void const* buffer, size_t size) {
     49     if (size < sizeof(validTypes)) {
     50         return NO_MEMORY;
     51     }
     52     FlattenableUtils::read(buffer, size, validTypes);
     53     if (validTypes & SMPTE2086) {
     54         if (size < sizeof(smpte2086)) {
     55             return NO_MEMORY;
     56         }
     57         FlattenableUtils::read(buffer, size, smpte2086);
     58     }
     59     if (validTypes & CTA861_3) {
     60         if (size < sizeof(cta8613)) {
     61             return NO_MEMORY;
     62         }
     63         FlattenableUtils::read(buffer, size, cta8613);
     64     }
     65 
     66     return NO_ERROR;
     67 }
     68 
     69 bool HdrMetadata::operator==(const HdrMetadata& rhs) const {
     70     if (validTypes != rhs.validTypes) return false;
     71 
     72     if ((validTypes & SMPTE2086) == SMPTE2086) {
     73         if (smpte2086.displayPrimaryRed.x != rhs.smpte2086.displayPrimaryRed.x ||
     74             smpte2086.displayPrimaryRed.y != rhs.smpte2086.displayPrimaryRed.y ||
     75             smpte2086.displayPrimaryGreen.x != rhs.smpte2086.displayPrimaryGreen.x ||
     76             smpte2086.displayPrimaryGreen.y != rhs.smpte2086.displayPrimaryGreen.y ||
     77             smpte2086.displayPrimaryBlue.x != rhs.smpte2086.displayPrimaryBlue.x ||
     78             smpte2086.displayPrimaryBlue.y != rhs.smpte2086.displayPrimaryBlue.y ||
     79             smpte2086.whitePoint.x != rhs.smpte2086.whitePoint.x ||
     80             smpte2086.whitePoint.y != rhs.smpte2086.whitePoint.y ||
     81             smpte2086.maxLuminance != rhs.smpte2086.maxLuminance ||
     82             smpte2086.minLuminance != rhs.smpte2086.minLuminance) {
     83             return false;
     84         }
     85     }
     86 
     87     if ((validTypes & CTA861_3) == CTA861_3) {
     88         if (cta8613.maxFrameAverageLightLevel != rhs.cta8613.maxFrameAverageLightLevel ||
     89             cta8613.maxContentLightLevel != rhs.cta8613.maxContentLightLevel) {
     90             return false;
     91         }
     92     }
     93 
     94     return true;
     95 }
     96 
     97 } // namespace android
     98