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 const uint32_t kBufferDescriptorSize = 7;
41 const uint32_t kBufferDescriptorSizeV4 = 42;
42 const uint32_t kMagicVersion = 0x76312E30;  // v1.0
43 
44 class BufferDescriptor {
45  public:
BufferDescriptor()46   BufferDescriptor() {}
BufferDescriptor(uint64_t id)47   explicit BufferDescriptor(uint64_t id) : id_(id) {}
SetUsage(uint64_t usage)48   void SetUsage(uint64_t usage) { usage_ |= usage; }
49 
SetDimensions(int w,int h)50   void SetDimensions(int w, int h) {
51     width_ = w;
52     height_ = h;
53   }
54 
SetColorFormat(int format)55   void SetColorFormat(int format) { format_ = format; }
56 
SetLayerCount(uint32_t layer_count)57   void SetLayerCount(uint32_t layer_count) { layer_count_ = layer_count; }
58 
SetName(std::string name)59   void SetName(std::string name) { name_ = name; }
60 
SetReservedSize(uint64_t reserved_size)61   void SetReservedSize(uint64_t reserved_size) { reserved_size_ = reserved_size; }
62 
GetUsage()63   uint64_t GetUsage() const { return usage_; }
64 
GetWidth()65   int GetWidth() const { return width_; }
66 
GetHeight()67   int GetHeight() const { return height_; }
68 
GetFormat()69   int GetFormat() const { return format_; }
70 
GetLayerCount()71   uint32_t GetLayerCount() const { return layer_count_; }
72 
GetId()73   uint64_t GetId() const { return id_; }
74 
GetReservedSize()75   uint64_t GetReservedSize() const { return reserved_size_; }
76 
GetName()77   std::string GetName() const { return name_; }
78 
79  private:
80   std::string name_ = "";
81   int width_ = -1;
82   int height_ = -1;
83   int format_ = -1;
84   uint32_t layer_count_ = 1;
85   uint64_t usage_ = 0;
86   const uint64_t id_ = 0;
87   uint64_t reserved_size_ = 0;
88 };
89 };      // namespace gralloc
90 #endif  // __GR_BUF_DESCRIPTOR_H__
91