• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "buffer/avbuffer_common.h"
17 #include "surface_type.h" // foundation/graphic/graphic_2d/interfaces/surface/surface_type.h
18 
19 namespace OHOS {
20 namespace Media {
AVBufferConfig()21 AVBufferConfig::AVBufferConfig()
22 {
23     this->surfaceBufferConfig = std::make_unique<BufferRequestConfig>();
24 }
25 
AVBufferConfig(const AVBufferConfig & rhs)26 AVBufferConfig::AVBufferConfig(const AVBufferConfig &rhs)
27 {
28     if (&rhs == this) {
29         return;
30     }
31     this->surfaceBufferConfig = std::make_unique<BufferRequestConfig>();
32     *(this->surfaceBufferConfig) = *(rhs.surfaceBufferConfig);
33     this->size = rhs.size;
34     this->align = rhs.align;
35     this->dmaFd = rhs.dmaFd;
36     this->capacity = rhs.capacity;
37     this->memoryFlag = rhs.memoryFlag;
38     this->memoryType = rhs.memoryType;
39 }
40 
AVBufferConfig(AVBufferConfig && rhs)41 AVBufferConfig::AVBufferConfig(AVBufferConfig &&rhs) noexcept
42 {
43     this->surfaceBufferConfig = std::move(rhs.surfaceBufferConfig);
44     this->size = rhs.size;
45     this->align = rhs.align;
46     this->dmaFd = rhs.dmaFd;
47     this->capacity = rhs.capacity;
48     this->memoryFlag = rhs.memoryFlag;
49     this->memoryType = rhs.memoryType;
50 }
51 
operator =(const AVBufferConfig & rhs)52 AVBufferConfig &AVBufferConfig::operator=(const AVBufferConfig &rhs)
53 {
54     if (&rhs == this) {
55         return *this;
56     }
57     *(this->surfaceBufferConfig) = *(rhs.surfaceBufferConfig);
58     this->size = rhs.size;
59     this->align = rhs.align;
60     this->dmaFd = rhs.dmaFd;
61     this->capacity = rhs.capacity;
62     this->memoryFlag = rhs.memoryFlag;
63     this->memoryType = rhs.memoryType;
64     return *this;
65 }
66 
operator =(AVBufferConfig && rhs)67 AVBufferConfig &AVBufferConfig::operator=(AVBufferConfig &&rhs) noexcept
68 {
69     if (&rhs == this) {
70         return *this;
71     }
72     this->surfaceBufferConfig = std::move(rhs.surfaceBufferConfig);
73     this->size = rhs.size;
74     this->align = rhs.align;
75     this->dmaFd = rhs.dmaFd;
76     this->capacity = rhs.capacity;
77     this->memoryFlag = rhs.memoryFlag;
78     this->memoryType = rhs.memoryType;
79     return *this;
80 }
81 
operator <=(const struct AVBufferConfig & rhs) const82 bool AVBufferConfig::operator<=(const struct AVBufferConfig &rhs) const
83 {
84     if (memoryType != rhs.memoryType) {
85         return false;
86     }
87     int32_t configAllocSize = rhs.align ? (rhs.capacity + rhs.align - 1) : rhs.capacity;
88     switch (memoryType) {
89         case MemoryType::VIRTUAL_MEMORY:
90             return size <= configAllocSize;
91         case MemoryType::SHARED_MEMORY:
92             return size <= configAllocSize &&
93                    (memoryFlag == rhs.memoryFlag || rhs.memoryFlag == MemoryFlag::MEMORY_READ_WRITE);
94         case MemoryType::HARDWARE_MEMORY:
95             return size <= configAllocSize &&
96                    (memoryFlag == rhs.memoryFlag || rhs.memoryFlag == MemoryFlag::MEMORY_READ_WRITE);
97         case MemoryType::SURFACE_MEMORY:
98             return (surfaceBufferConfig->width == rhs.surfaceBufferConfig->width) &&
99                    (surfaceBufferConfig->height == rhs.surfaceBufferConfig->height) &&
100                    (surfaceBufferConfig->strideAlignment == rhs.surfaceBufferConfig->strideAlignment) &&
101                    (surfaceBufferConfig->format == rhs.surfaceBufferConfig->format) &&
102                    (surfaceBufferConfig->usage == rhs.surfaceBufferConfig->usage) &&
103                    (surfaceBufferConfig->transform == rhs.surfaceBufferConfig->transform) &&
104                    (surfaceBufferConfig->colorGamut == rhs.surfaceBufferConfig->colorGamut); // ignore timeout
105         default:
106             return false;
107     }
108 }
109 
110 } // namespace Media
111 } // namespace OHOS