1 /*
2 * Copyright (C) 2024 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 "render_general_program.h"
17
18 namespace OHOS {
19 namespace Media {
20 namespace {
21 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_VIDEOEDITOR, "VideoEditorRender"};
22 }
RenderGeneralProgram(RenderContext * context,const std::string & vss,const std::string & fss)23 RenderGeneralProgram::RenderGeneralProgram(RenderContext* context, const std::string& vss, const std::string& fss)
24 : RenderProgram(context), vss_(vss), fss_(fss)
25 {
26 SetTag("RenderGeneralProgram");
27 }
28
Init()29 bool RenderGeneralProgram::Init()
30 {
31 MEDIA_LOGD("RenderGeneralProgram Init begin");
32 std::lock_guard<ffrt::mutex> lk(m_renderLock);
33 if (IsReady()) {
34 return true;
35 }
36 program_ = GLUtils::CreateProgram(vss_, fss_);
37 SetReady(program_ > 0);
38 MEDIA_LOGD("RenderGeneralProgram Init end");
39 return program_ > 0;
40 }
41
Release()42 bool RenderGeneralProgram::Release()
43 {
44 MEDIA_LOGD("RenderGeneralProgram Release begin");
45 if (!IsReady()) {
46 return false;
47 }
48 glDeleteProgram(program_);
49 GLUtils::CheckError(__FILE__, __LINE__);
50 program_ = 0;
51 SetReady(false);
52 MEDIA_LOGD("RenderGeneralProgram Release end");
53 return true;
54 }
55 }
56 }