1 /* 2 * Copyright (c) 2016-2018, 2020, The Linux Foundation. All rights reserved. 3 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * * Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * * Redistributions in binary form must reproduce the above 10 * copyright notice, this list of conditions and the following 11 * disclaimer in the documentation and/or other materials provided 12 * with the distribution. 13 * * Neither the name of The Linux Foundation nor the names of its 14 * contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 #ifndef __GR_BUF_DESCRIPTOR_H__ 31 #define __GR_BUF_DESCRIPTOR_H__ 32 33 #include <atomic> 34 #include <string> 35 36 #include "gr_utils.h" 37 38 namespace gralloc { 39 using android::hardware::hidl_vec; 40 41 const uint32_t kBufferDescriptorSize = 7; 42 const uint32_t kBufferDescriptorSizeV4 = 42; 43 const uint32_t kMagicVersion = 0x76312E30; // v1.0 44 45 class BufferDescriptor { 46 public: BufferDescriptor()47 BufferDescriptor() {} BufferDescriptor(uint64_t id)48 explicit BufferDescriptor(uint64_t id) : id_(id) {} SetUsage(uint64_t usage)49 void SetUsage(uint64_t usage) { usage_ |= usage; } 50 SetDimensions(int w,int h)51 void SetDimensions(int w, int h) { 52 width_ = w; 53 height_ = h; 54 } 55 SetColorFormat(int format)56 void SetColorFormat(int format) { format_ = format; } 57 SetLayerCount(uint32_t layer_count)58 void SetLayerCount(uint32_t layer_count) { layer_count_ = layer_count; } 59 SetName(std::string name)60 void SetName(std::string name) { name_ = name; } 61 SetReservedSize(uint64_t reserved_size)62 void SetReservedSize(uint64_t reserved_size) { reserved_size_ = reserved_size; } 63 GetUsage()64 uint64_t GetUsage() const { return usage_; } 65 GetWidth()66 int GetWidth() const { return width_; } 67 GetHeight()68 int GetHeight() const { return height_; } 69 GetFormat()70 int GetFormat() const { return format_; } 71 GetLayerCount()72 uint32_t GetLayerCount() const { return layer_count_; } 73 GetId()74 uint64_t GetId() const { return id_; } 75 GetReservedSize()76 uint64_t GetReservedSize() const { return reserved_size_; } 77 GetName()78 std::string GetName() const { return name_; } 79 80 private: 81 std::string name_ = ""; 82 int width_ = -1; 83 int height_ = -1; 84 int format_ = -1; 85 uint32_t layer_count_ = 1; 86 uint64_t usage_ = 0; 87 const uint64_t id_ = 0; 88 uint64_t reserved_size_ = 0; 89 }; 90 }; // namespace gralloc 91 #endif // __GR_BUF_DESCRIPTOR_H__ 92