Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
surface_texture_external_texture_gl_skia.cc
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
6
7#include <GLES2/gl2.h>
8#define GL_GLEXT_PROTOTYPES
9#include <GLES2/gl2ext.h>
10
12#include "flutter/third_party/skia/include/core/SkColorSpace.h"
13#include "flutter/third_party/skia/include/gpu/ganesh/GrBackendSurface.h"
14#include "flutter/third_party/skia/include/gpu/ganesh/GrDirectContext.h"
15#include "flutter/third_party/skia/include/gpu/ganesh/SkImageGanesh.h"
16#include "flutter/third_party/skia/include/gpu/ganesh/gl/GrGLBackendSurface.h"
17#include "flutter/third_party/skia/include/gpu/ganesh/gl/GrGLTypes.h"
18
19namespace flutter {
20
22 int64_t id,
23 const fml::jni::ScopedJavaGlobalRef<jobject>& surface_texture,
24 const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade)
25 : SurfaceTextureExternalTexture(id, surface_texture, jni_facade) {}
26
28 if (texture_name_ != 0) {
29 glDeleteTextures(1, &texture_name_);
30 }
31}
32
33void SurfaceTextureExternalTextureGLSkia::ProcessFrame(PaintContext& context,
34 const SkRect& bounds) {
36 // Generate the texture handle.
37 glGenTextures(1, &texture_name_);
38 Attach(texture_name_);
39 }
41
42 // Updates the texture contents and transformation matrix.
43 Update();
44
45 GrGLTextureInfo textureInfo = {GL_TEXTURE_EXTERNAL_OES, texture_name_,
46 GL_RGBA8_OES};
47 auto backendTexture =
48 GrBackendTextures::MakeGL(1, 1, skgpu::Mipmapped::kNo, textureInfo);
49 dl_image_ = DlImageSkia::Make(SkImages::BorrowTextureFrom(
50 context.gr_context, backendTexture, kTopLeft_GrSurfaceOrigin,
51 kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr));
52}
53
54void SurfaceTextureExternalTextureGLSkia::Detach() {
56 // Detach will collect the texture handle.
57 // See also: https://github.com/flutter/flutter/issues/152459
58 texture_name_ = 0;
59}
60
61} // namespace flutter
static sk_sp< DlImage > Make(const SkImage *image)
SurfaceTextureExternalTextureGLSkia(int64_t id, const fml::jni::ScopedJavaGlobalRef< jobject > &surface_texture, const std::shared_ptr< PlatformViewAndroidJNI > &jni_facade)
Instances of external textures peered to android.graphics.SurfaceTexture.
void Attach(int gl_tex_id)
Attaches the given OpenGL texture handle to the surface texture via a bind operation.
virtual void Detach()
Provides an opportunity for the subclasses to sever the connection between the OpenGL texture resourc...
void Update()
Update the surface texture contents and transformation matrix.
#define FML_CHECK(condition)
Definition logging.h:104
GrDirectContext * gr_context
Definition layer.h:99
const uintptr_t id