• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "surface_ohos_gl.h"
17 
18 #include <hilog/log.h>
19 #include "window.h"
20 
21 namespace OHOS {
22 namespace Rosen {
SurfaceOhosGl(const sptr<Surface> & producer)23 SurfaceOhosGl::SurfaceOhosGl(const sptr<Surface>& producer)
24     : SurfaceOhos(producer), frame_(nullptr)
25 {
26 }
27 
~SurfaceOhosGl()28 SurfaceOhosGl::~SurfaceOhosGl()
29 {
30     frame_ = nullptr;
31 }
32 
RequestFrame(int32_t width,int32_t height)33 std::unique_ptr<SurfaceFrame> SurfaceOhosGl::RequestFrame(int32_t width, int32_t height)
34 {
35     struct NativeWindow* nativeWindow = CreateNativeWindowFromSurface(&producer_);
36     if (nativeWindow == nullptr) {
37         return nullptr;
38     }
39 
40     frame_ = std::make_unique<SurfaceFrameOhosGl>(width, height);
41     frame_->SetColorSpace(ColorGamut::COLOR_GAMUT_SRGB);
42     frame_->SetSurface(static_cast<EGLSurface>(drawingProxy_->CreateSurface((EGLNativeWindowType)nativeWindow)));
43     NativeWindowHandleOpt(nativeWindow, SET_BUFFER_GEOMETRY, frame_->GetWidth(), frame_->GetHeight());
44     NativeWindowHandleOpt(nativeWindow, SET_COLOR_GAMUT, frame_->GetColorSpace());
45     drawingProxy_->MakeCurrent();
46 
47     std::unique_ptr<SurfaceFrame> ret(std::move(frame_));
48     DestoryNativeWindow(nativeWindow);
49     return ret;
50 }
51 
FlushFrame(std::unique_ptr<SurfaceFrame> & frame)52 bool SurfaceOhosGl::FlushFrame(std::unique_ptr<SurfaceFrame>& frame)
53 {
54     // gpu render flush
55     drawingProxy_->RenderFrame();
56     drawingProxy_->SwapBuffers();
57     return true;
58 }
59 
GetCanvas(std::unique_ptr<SurfaceFrame> & frame)60 SkCanvas* SurfaceOhosGl::GetCanvas(std::unique_ptr<SurfaceFrame>& frame)
61 {
62     return drawingProxy_->AcquireCanvas(frame);
63 }
64 } // namespace Rosen
65 } // namespace OHOS
66