• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 #ifndef RENDER_SERVICE_BASE_CORE_COMMON_RS_SHARED_CONTEXT_H
17 #define RENDER_SERVICE_BASE_CORE_COMMON_RS_SHARED_CONTEXT_H
18 
19 #include <memory>
20 #include <thread>
21 
22 #include "common/rs_macros.h"
23 #ifndef USE_ROSEN_DRAWING
24 #include "include/core/SkRefCnt.h"
25 #ifdef NEW_SKIA
26 #include "include/gpu/GrDirectContext.h"
27 #else
28 #include "include/gpu/GrContext.h"
29 #endif
30 #else // USE_ROSEN_DRAWING
31 #include "image/gpu_context.h"
32 #endif // USE_ROSEN_DRAWING
33 
34 typedef void* EGLSurface;
35 typedef void* EGLContext;
36 typedef void* EGLDisplay;
37 
38 namespace OHOS::Rosen {
39 
40 class RSB_EXPORT RSSharedContext final : public std::enable_shared_from_this<RSSharedContext> {
41 public:
42     static std::shared_ptr<RSSharedContext> MakeSharedGLContext(EGLContext context);
43 
44     ~RSSharedContext();
45     void MakeCurrent();
46 #ifndef USE_ROSEN_DRAWING
47 #ifdef NEW_SKIA
48     sk_sp<GrDirectContext> MakeGrContext();
49 #else
50     sk_sp<GrContext> MakeGrContext();
51 #endif
52 #else // USE_ROSEN_DRAWING
53     std::shared_ptr<Drawing::GPUContext> MakeDrContext();
54 #endif
55 
56 private:
RSSharedContext(EGLDisplay display,EGLContext context,EGLSurface surface)57     RSSharedContext(EGLDisplay display, EGLContext context, EGLSurface surface)
58         : display_(display), context_(context), surface_(surface) {}
59 
60     EGLDisplay display_ = nullptr;
61     EGLContext context_ = nullptr;
62     EGLSurface surface_ = nullptr;
63 };
64 } // namespace OHOS::Rosen
65 #endif // RENDER_SERVICE_BASE_CORE_COMMON_RS_SHARED_CONTEXT_H
66