• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 // 2021.2.10 Increase the process used in native_view mode.
6 //           Copyright (c) 2021 Huawei Device Co., Ltd. All rights reserved.
7 
8 #ifndef FLUTTER_FLOW_OHOS_LAYERS_TEXTURE_REGISTER_H
9 #define FLUTTER_FLOW_OHOS_LAYERS_TEXTURE_REGISTER_H
10 
11 #include <unordered_map>
12 
13 #include "flutter/fml/macros.h"
14 #include "flutter/fml/platform/android/jni_util.h"
15 #include "flutter/fml/platform/android/jni_weak_ref.h"
16 
17 namespace flutter::OHOS {
18 
19 struct AceTextureLayer {
20     void setAlpha(int32_t alpha);
21     static bool Register(JNIEnv* env);
22 
23     int64_t id_ = -1;
24     long handle_ = 0;
25     fml::jni::JavaObjectWeakGlobalRef layerTexture_;
26     void* nativeWindow_ = nullptr;
27     int32_t alpha_ = 255;
28 };
29 
30 class TextureRegistry {
31 public:
32     TextureRegistry() = default;
33     ~TextureRegistry() = default;
34 
35     // Called from Platform thread.
36     void RegisterTexture(int64_t id, long textureHandle, const fml::jni::JavaObjectWeakGlobalRef& layerTexture);
37 
38     // Called from Platform thread.
39     void RegisterNativeWindow(int64_t id, const void* nativeWindow);
40 
41     // Called from Platform thread.
42     void UnregisterTexture(int64_t id);
43 
44     // Called from Platform thread.
45     const AceTextureLayer& GetTexture(int64_t id);
46 
47 private:
48     std::unordered_map<int64_t, AceTextureLayer> mapping_;
49 
50     FML_DISALLOW_COPY_AND_ASSIGN(TextureRegistry);
51 };
52 
53 }  // namespace flutter::OHOS
54 
55 #endif  // FLUTTER_FLOW_OHOS_LAYERS_TEXTURE_REGISTER_H
56