• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FLUTTER_SHELL_PLATFORM_ANDROID_EXTERNAL_TEXTURE_GL_H_
6 #define FLUTTER_SHELL_PLATFORM_ANDROID_EXTERNAL_TEXTURE_GL_H_
7 
8 #include <GLES/gl.h>
9 #include "flutter/flow/texture.h"
10 #include "flutter/fml/platform/android/jni_weak_ref.h"
11 
12 namespace flutter {
13 
14 class AndroidExternalTextureGL : public flutter::Texture {
15  public:
16   AndroidExternalTextureGL(
17       int64_t id,
18       const fml::jni::JavaObjectWeakGlobalRef& surfaceTexture);
19 
20   ~AndroidExternalTextureGL() override;
21 
22   void Paint(SkCanvas& canvas,
23              const SkRect& bounds,
24              bool freeze,
25              GrContext* context) override;
26 
27   void OnGrContextCreated() override;
28 
29   void OnGrContextDestroyed() override;
30 
31   void MarkNewFrameAvailable() override;
32 
33  private:
34   void Attach(jint textureName);
35 
36   void Update();
37 
38   void Detach();
39 
40   void UpdateTransform();
41 
42   enum class AttachmentState { uninitialized, attached, detached };
43 
44   fml::jni::JavaObjectWeakGlobalRef surface_texture_;
45 
46   AttachmentState state_ = AttachmentState::uninitialized;
47 
48   bool new_frame_ready_ = false;
49 
50   GLuint texture_name_ = 0;
51 
52   SkMatrix transform;
53 
54   FML_DISALLOW_COPY_AND_ASSIGN(AndroidExternalTextureGL);
55 };
56 
57 }  // namespace flutter
58 
59 #endif  // FLUTTER_SHELL_PLATFORM_ANDROID_EXTERNAL_TEXTURE_GL_H_
60