1 /*
2  * Copyright 2023 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_HWC_ALTERNATINGIMAGESTORAGE_H
18 #define ANDROID_HWC_ALTERNATINGIMAGESTORAGE_H
19 
20 #include <stdint.h>
21 
22 #include <vector>
23 
24 #include "Common.h"
25 
26 namespace aidl::android::hardware::graphics::composer3::impl {
27 
28 // Provides storage for images when transforming images with the expectation
29 // that image N will no longer be used after producing image N + 1. With this,
30 // the storage just needs to be 2x the needed image size and the returned buffers
31 // can alternate back and forth.
32 class AlternatingImageStorage {
33    public:
34     AlternatingImageStorage() = default;
35 
36     uint8_t* getRotatingScratchBuffer(std::size_t neededSize, std::uint32_t imageIndex);
37 
38     uint8_t* getSpecialScratchBuffer(std::size_t neededSize);
39 
40    private:
41     static constexpr const int kNumScratchBufferPieces = 2;
42 
43     // The main alternating storage.
44     std::vector<uint8_t> mScratchBuffer;
45 
46     // Extra additional storage for one-off operations (scaling).
47     std::vector<uint8_t> mSpecialScratchBuffer;
48 };
49 
50 }  // namespace aidl::android::hardware::graphics::composer3::impl
51 
52 #endif
53