• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "window_adapter_impl.h"
17 
18 #include <cstdarg>
19 
20 #include "nweb_log.h"
21 #include "foundation/graphic/graphic_surface/interfaces/inner_api/surface/window.h"
22 #include "foundation/graphic/graphic_surface/surface/include/native_window.h"
23 
24 namespace OHOS::NWeb {
25 const int32_t WindowAdapter::SET_BUFFER_GEOMETRY = NativeWindowOperation::SET_BUFFER_GEOMETRY;
26 
GetInstance()27 WindowAdapterImpl& WindowAdapterImpl::GetInstance()
28 {
29     static WindowAdapterImpl instance;
30     return instance;
31 }
32 
CreateNativeWindowFromSurface(void * pSurface)33 NWebNativeWindow WindowAdapterImpl::CreateNativeWindowFromSurface(void* pSurface)
34 {
35     OHNativeWindow* window = ::CreateNativeWindowFromSurface(pSurface);
36     window->config.usage = BUFFER_USAGE_MEM_DMA;
37     return reinterpret_cast<NWebNativeWindow>(window);
38 }
39 
DestroyNativeWindow(NWebNativeWindow window)40 void WindowAdapterImpl::DestroyNativeWindow(NWebNativeWindow window)
41 {
42     ::DestoryNativeWindow(reinterpret_cast<OHNativeWindow*>(window));
43 }
44 
NativeWindowHandleOpt(NWebNativeWindow window,int code,...)45 int32_t WindowAdapterImpl::NativeWindowHandleOpt(NWebNativeWindow window, int code, ...)
46 {
47     va_list args;
48     va_start(args, code);
49     int32_t ret = -1;
50     switch (code) {
51         case SET_BUFFER_GEOMETRY: {
52             int32_t width = va_arg(args, int32_t);
53             int32_t height = va_arg(args, int32_t);
54             ret = ::NativeWindowHandleOpt(reinterpret_cast<OHNativeWindow*>(window), code, width, height);
55             break;
56         }
57         default:
58             WVLOG_E("Unsupport parameter format");
59             break;
60     }
61     va_end(args);
62     return ret;
63 }
64 } // namespace OHOS::NWeb
65