Flutter Engine
ios_external_texture_gl.h
Go to the documentation of this file.
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_IOS_EXTERNAL_TEXTURE_GL_H_
6 #define FLUTTER_SHELL_PLATFORM_IOS_EXTERNAL_TEXTURE_GL_H_
7 
8 #include "flutter/flow/texture.h"
9 #include "flutter/fml/platform/darwin/cf_utils.h"
10 #include "flutter/fml/platform/darwin/scoped_nsobject.h"
11 #import "flutter/shell/platform/darwin/common/framework/Headers/FlutterTexture.h"
12 
13 namespace flutter {
14 
15 class IOSExternalTextureGL final : public Texture {
16  public:
17  IOSExternalTextureGL(int64_t textureId, NSObject<FlutterTexture>* externalTexture);
18 
19  // |Texture|
20  ~IOSExternalTextureGL() override;
21 
22  private:
23  bool new_frame_ready_ = false;
27  fml::CFRef<CVPixelBufferRef> buffer_ref_;
28  OSType pixel_format_ = 0;
29  fml::CFRef<CVOpenGLESTextureRef> y_texture_ref_;
30  fml::CFRef<CVOpenGLESTextureRef> uv_texture_ref_;
31 
32  // |Texture|
33  void Paint(SkCanvas& canvas,
34  const SkRect& bounds,
35  bool freeze,
36  GrDirectContext* context,
37  SkFilterQuality filter_quality) override;
38 
39  // |Texture|
40  void OnGrContextCreated() override;
41 
42  // |Texture|
43  void OnGrContextDestroyed() override;
44 
45  // |Texture|
46  void MarkNewFrameAvailable() override;
47 
48  // |Texture|
49  void OnTextureUnregistered() override;
50 
51  void CreateTextureFromPixelBuffer();
52 
53  void EnsureTextureCacheExists();
54 
55  bool NeedUpdateTexture(bool freeze);
56 
57  bool IsTexturesAvailable() const;
58 
59  void CreateYUVTexturesFromPixelBuffer();
60 
61  void CreateRGBATextureFromPixelBuffer();
62 
63  sk_sp<SkImage> CreateImageFromYUVTextures(GrDirectContext* context, const SkRect& bounds);
64 
65  sk_sp<SkImage> CreateImageFromRGBATexture(GrDirectContext* context, const SkRect& bounds);
66 
67  FML_DISALLOW_COPY_AND_ASSIGN(IOSExternalTextureGL);
68 };
69 
70 } // namespace flutter
71 
72 #endif // FLUTTER_SHELL_PLATFORM_IOS_EXTERNAL_TEXTURE_GL_H_
IOSExternalTextureGL(int64_t textureId, NSObject< FlutterTexture > *externalTexture)