1 /*
2  * Copyright (c) 2022 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 "image_chain.h"
17 
18 namespace OHOS {
19 namespace Rosen {
ImageChain(std::vector<std::shared_ptr<Input>> inputs)20 ImageChain::ImageChain(std::vector<std::shared_ptr<Input>> inputs) : inputs_(inputs)
21 {
22     CreatTexture(srcTextureID_);
23     CreatTexture(dstTextureID_);
24 
25     glGenFramebuffers(1, &frameBufferID_);
26     if (inputs_.size() == 1) {
27         flagSeries_ = true;
28     }
29 }
30 
Render()31 bool ImageChain::Render()
32 {
33     ProcessData data {srcTextureID_, dstTextureID_, frameBufferID_, 0, 0};
34     if (flagSeries_) {
35         return SeriesRendering(data);
36     }
37 
38     if (inputs_.size() == 0) {
39         return false;
40     }
41     return ParallelRendering();
42 }
43 
SeriesRendering(ProcessData & data)44 bool ImageChain::SeriesRendering(ProcessData& data)
45 {
46     return inputs_.at(0)->Process(data);
47 }
48 
ParallelRendering()49 bool ImageChain::ParallelRendering()
50 {
51     return false;
52 }
53 
CreatTexture(unsigned int & textureID)54 void ImageChain::CreatTexture(unsigned int& textureID)
55 {
56     glGenTextures(1, &textureID);
57     glBindTexture(GL_TEXTURE_2D, textureID);
58     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
59     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
60     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
61     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
62     glBindTexture(GL_TEXTURE_2D, 0);
63 }
64 } // namespcae Rosen
65 } // namespace OHOS