Home | History | Annotate | Download | only in ui
      1 /*
      2  * Copyright 2016 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 ANDROID_UI_GRALLOC3_H
     18 #define ANDROID_UI_GRALLOC3_H
     19 
     20 #include <string>
     21 
     22 #include <android/hardware/graphics/allocator/3.0/IAllocator.h>
     23 #include <android/hardware/graphics/common/1.1/types.h>
     24 #include <android/hardware/graphics/mapper/3.0/IMapper.h>
     25 #include <ui/Gralloc.h>
     26 #include <ui/PixelFormat.h>
     27 #include <ui/Rect.h>
     28 #include <utils/StrongPointer.h>
     29 
     30 namespace android {
     31 
     32 class Gralloc3Mapper : public GrallocMapper {
     33 public:
     34     static void preload();
     35 
     36     Gralloc3Mapper();
     37 
     38     bool isLoaded() const override;
     39 
     40     status_t createDescriptor(void* bufferDescriptorInfo, void* outBufferDescriptor) const override;
     41 
     42     status_t importBuffer(const hardware::hidl_handle& rawHandle,
     43                           buffer_handle_t* outBufferHandle) const override;
     44 
     45     void freeBuffer(buffer_handle_t bufferHandle) const override;
     46 
     47     status_t validateBufferSize(buffer_handle_t bufferHandle, uint32_t width, uint32_t height,
     48                                 android::PixelFormat format, uint32_t layerCount, uint64_t usage,
     49                                 uint32_t stride) const override;
     50 
     51     void getTransportSize(buffer_handle_t bufferHandle, uint32_t* outNumFds,
     52                           uint32_t* outNumInts) const override;
     53 
     54     status_t lock(buffer_handle_t bufferHandle, uint64_t usage, const Rect& bounds,
     55                   int acquireFence, void** outData, int32_t* outBytesPerPixel,
     56                   int32_t* outBytesPerStride) const override;
     57 
     58     status_t lock(buffer_handle_t bufferHandle, uint64_t usage, const Rect& bounds,
     59                   int acquireFence, android_ycbcr* ycbcr) const override;
     60 
     61     int unlock(buffer_handle_t bufferHandle) const override;
     62 
     63     status_t isSupported(uint32_t width, uint32_t height, android::PixelFormat format,
     64                          uint32_t layerCount, uint64_t usage, bool* outSupported) const override;
     65 
     66 private:
     67     // Determines whether the passed info is compatible with the mapper.
     68     status_t validateBufferDescriptorInfo(
     69             hardware::graphics::mapper::V3_0::IMapper::BufferDescriptorInfo* descriptorInfo) const;
     70 
     71     sp<hardware::graphics::mapper::V3_0::IMapper> mMapper;
     72 };
     73 
     74 class Gralloc3Allocator : public GrallocAllocator {
     75 public:
     76     // An allocator relies on a mapper, and that mapper must be alive at all
     77     // time.
     78     Gralloc3Allocator(const Gralloc3Mapper& mapper);
     79 
     80     bool isLoaded() const override;
     81 
     82     std::string dumpDebugInfo() const override;
     83 
     84     status_t allocate(uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount,
     85                       uint64_t usage, uint32_t bufferCount, uint32_t* outStride,
     86                       buffer_handle_t* outBufferHandles) const override;
     87 
     88 private:
     89     const Gralloc3Mapper& mMapper;
     90     sp<hardware::graphics::allocator::V3_0::IAllocator> mAllocator;
     91 };
     92 
     93 } // namespace android
     94 
     95 #endif // ANDROID_UI_GRALLOC3_H
     96