Home | History | Annotate | Download | only in include
      1 /*
      2  * Copyright 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 #ifndef CODEC2_VNDK_TYPES_H
     18 #define CODEC2_VNDK_TYPES_H
     19 
     20 #include <android/hardware/graphics/bufferqueue/2.0/types.h>
     21 #include <android/hardware/graphics/common/1.2/types.h>
     22 #include <hidl/HidlSupport.h>
     23 #include <ui/Fence.h>
     24 #include <ui/GraphicBuffer.h>
     25 #include <ui/Region.h>
     26 
     27 namespace android {
     28 namespace hardware {
     29 namespace graphics {
     30 namespace bufferqueue {
     31 namespace V2_0 {
     32 namespace utils {
     33 
     34 // Status
     35 // ======
     36 
     37 using HStatus = ::android::hardware::graphics::bufferqueue::V2_0::
     38         Status;
     39 
     40 // A status_t value may have flags encoded. These flags are decoded into boolean
     41 // values if their corresponding output pointers are not null.
     42 bool b2h(status_t from, HStatus* to,
     43          bool* bufferNeedsReallocation = nullptr,
     44          bool* releaseAllBuffers = nullptr);
     45 // Simple 1-to-1 mapping. If BUFFER_NEEDS_REALLOCATION or RELEASE_ALL_BUFFERS
     46 // needs to be added, it must be done manually afterwards.
     47 bool h2b(HStatus from, status_t* to);
     48 
     49 // Fence
     50 // =====
     51 
     52 using BFence = ::android::Fence;
     53 // This class manages the lifetime of a copied handle. Its destructor calls
     54 // native_handle_delete() but not native_handle_close().
     55 struct HFenceWrapper {
     56     HFenceWrapper() = default;
     57     // Sets mHandle to a new value.
     58     HFenceWrapper(native_handle_t* h);
     59     // Deletes mHandle without closing.
     60     ~HFenceWrapper();
     61     // Deletes mHandle without closing, then sets mHandle to a new value.
     62     HFenceWrapper& set(native_handle_t* h);
     63     HFenceWrapper& operator=(native_handle_t* h);
     64     // Returns a non-owning hidl_handle pointing to mHandle.
     65     hidl_handle getHandle() const;
     66     operator hidl_handle() const;
     67 protected:
     68     native_handle_t* mHandle{nullptr};
     69 };
     70 
     71 // Does not clone the fd---only copy the fd. The returned HFenceWrapper should
     72 // not outlive the input Fence object.
     73 bool b2h(sp<BFence> const& from, HFenceWrapper* to);
     74 // Clones the fd and puts it in a new Fence object.
     75 bool h2b(native_handle_t const* from, sp<BFence>* to);
     76 
     77 // ConnectionType
     78 // ==============
     79 
     80 using HConnectionType = ::android::hardware::graphics::bufferqueue::V2_0::
     81         ConnectionType;
     82 
     83 bool b2h(int from, HConnectionType* to);
     84 bool h2b(HConnectionType from, int* to);
     85 
     86 // Rect
     87 // ====
     88 
     89 using BRect = ::android::Rect;
     90 using HRect = ::android::hardware::graphics::common::V1_2::Rect;
     91 
     92 bool b2h(BRect const& from, HRect* to);
     93 bool h2b(HRect const& from, BRect* to);
     94 
     95 // Region
     96 // ======
     97 
     98 using BRegion = ::android::Region;
     99 using HRegion = ::android::hardware::hidl_vec<HRect>;
    100 
    101 bool b2h(BRegion const& from, HRegion* to);
    102 bool h2b(HRegion const& from, BRegion* to);
    103 
    104 // GraphicBuffer
    105 // =============
    106 
    107 using HardwareBuffer = ::android::hardware::graphics::common::V1_2::
    108         HardwareBuffer;
    109 using HardwareBufferDescription = ::android::hardware::graphics::common::V1_2::
    110         HardwareBufferDescription;
    111 
    112 // Does not clone the handle. The returned HardwareBuffer should not outlive the
    113 // input GraphicBuffer. Note that HardwareBuffer does not carry the generation
    114 // number, so this function needs another output argument.
    115 bool b2h(sp<GraphicBuffer> const& from, HardwareBuffer* to,
    116          uint32_t* toGenerationNumber = nullptr);
    117 // Clones the handle and creates a new GraphicBuffer from the cloned handle.
    118 // Note that the generation number of the GraphicBuffer has to be set manually
    119 // afterwards because HardwareBuffer does not have such information.
    120 bool h2b(HardwareBuffer const& from, sp<GraphicBuffer>* to);
    121 
    122 }  // namespace utils
    123 }  // namespace V2_0
    124 }  // namespace bufferqueue
    125 }  // namespace graphics
    126 }  // namespace hardware
    127 }  // namespace android
    128 
    129 #endif  // CODEC2_VNDK_TYPES_H
    130 
    131