• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <surface.h>
17 
18 #include <hilog/log.h>
19 
20 #include "buffer_log.h"
21 #include "consumer_surface.h"
22 #include "producer_surface.h"
23 #include "egl_consumer_surface.h"
24 
25 namespace OHOS {
CreateSurfaceAsConsumer(std::string name,bool isShared)26 sptr<Surface> Surface::CreateSurfaceAsConsumer(std::string name, bool isShared)
27 {
28     sptr<ConsumerSurface> surf = new ConsumerSurface(name, isShared);
29     GSError ret = surf->Init();
30     if (ret != GSERROR_OK) {
31         BLOGE("Failure, Reason: consumer surf init failed");
32         return nullptr;
33     }
34     return surf;
35 }
36 
CreateSurfaceAsProducer(sptr<IBufferProducer> & producer)37 sptr<Surface> Surface::CreateSurfaceAsProducer(sptr<IBufferProducer>& producer)
38 {
39     if (producer == nullptr) {
40         BLOGE("Failure, Reason: producer is nullptr");
41         return nullptr;
42     }
43 
44     sptr<ProducerSurface> surf = new ProducerSurface(producer);
45     GSError ret = surf->Init();
46     if (ret != GSERROR_OK) {
47         BLOGE("Failure, Reason: producer surf init failed");
48         return nullptr;
49     }
50     return surf;
51 }
52 
CreateEglSurfaceAsConsumer(std::string name,bool isShared)53 sptr<Surface> Surface::CreateEglSurfaceAsConsumer(std::string name, bool isShared)
54 {
55     sptr<EglConsumerSurface> surf = new EglConsumerSurface(name, isShared);
56     GSError ret = surf->Init();
57     if (ret != GSERROR_OK) {
58         BLOGE("Failure, Reason: egl consumer surf init failed");
59         return nullptr;
60     }
61     return surf;
62 }
63 } // namespace OHOS
64