1 /*
2 * Copyright (c) 2021 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 "egl_consumer_surface.h"
17
18 #include "buffer_log.h"
19
20 #include "buffer_queue_producer.h"
21 namespace OHOS {
EglConsumerSurface(const std::string & name,bool isShared)22 EglConsumerSurface::EglConsumerSurface(const std::string &name, bool isShared)
23 : ConsumerSurface(name, isShared)
24 {
25 BLOGD("ctor");
26 }
27
~EglConsumerSurface()28 EglConsumerSurface::~EglConsumerSurface()
29 {
30 BLOGD("dtor");
31 }
32
Init()33 GSError EglConsumerSurface::Init()
34 {
35 auto ret = ConsumerSurface::Init();
36 if (ret) {
37 BLOGE("ConsumerSurface::Init failed with %{public}d", ret);
38 return ret;
39 }
40
41 return GSERROR_OK;
42 }
43
AcquireBuffer(sptr<SurfaceBuffer> & buffer,int32_t & fence,int64_t & timestamp,Rect & damage)44 GSError EglConsumerSurface::AcquireBuffer(sptr<SurfaceBuffer>& buffer, int32_t &fence,
45 int64_t ×tamp, Rect &damage)
46 {
47 auto ret = ConsumerSurface::AcquireBuffer(buffer, fence, timestamp, damage);
48 if (ret) {
49 return ret;
50 }
51
52 auto eglData = buffer->GetEglData();
53 if (eglData == nullptr) {
54 auto eglDataImpl = new EglDataImpl();
55 auto res = eglDataImpl->CreateEglData(buffer);
56 if (res) {
57 BLOGE("EglDataImpl::CreateEglData failed with %{public}d", res);
58 return GSERROR_INTERNAL;
59 } else {
60 eglData = eglDataImpl;
61 buffer->SetEglData(eglData);
62 }
63 }
64 EglManager::GetInstance()->EglMakeCurrent();
65 return GSERROR_OK;
66 }
67 } // namespace OHOS
68