Flutter Engine
 
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
11#include "flutter/third_party/skia/include/core/SkColorSpace.h"
12#include "flutter/third_party/skia/include/gpu/ganesh/GrBackendSurface.h"
13#include "flutter/third_party/skia/include/gpu/ganesh/GrDirectContext.h"
14#include "flutter/third_party/skia/include/gpu/ganesh/SkImageGanesh.h"
15#include "flutter/third_party/skia/include/gpu/ganesh/gl/GrGLBackendSurface.h"
16#include "flutter/third_party/skia/include/gpu/ganesh/gl/GrGLTypes.h"
17
18namespace flutter {
19
21 int64_t id,
22 const fml::jni::ScopedJavaGlobalRef<jobject>& surface_texture,
23 const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade)
24 : SurfaceTextureExternalTexture(id, surface_texture, jni_facade) {}
25
27 if (texture_name_ != 0) {
28 glDeleteTextures(1, &texture_name_);
29 }
30}
31
32void SurfaceTextureExternalTextureGLSkia::ProcessFrame(PaintContext& context,
33 const SkRect& bounds) {
35 // Generate the texture handle.
36 glGenTextures(1, &texture_name_);
37 Attach(texture_name_);
38 }
40
41 // Updates the texture contents and transformation matrix.
42 Update();
43
44 GrGLTextureInfo textureInfo = {GL_TEXTURE_EXTERNAL_OES, texture_name_,
45 GL_RGBA8_OES};
46 auto backendTexture =
47 GrBackendTextures::MakeGL(1, 1, skgpu::Mipmapped::kNo, textureInfo);
48 dl_image_ = DlImage::Make(SkImages::BorrowTextureFrom(
49 context.gr_context, backendTexture, kTopLeft_GrSurfaceOrigin,
50 kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr));
51}
52
53void SurfaceTextureExternalTextureGLSkia::Detach() {
55 // Detach will collect the texture handle.
56 // See also: https://github.com/flutter/flutter/issues/152459
57 texture_name_ = 0;
58}
59
60} // namespace flutter
static sk_sp< DlImage > Make(const SkImage *image)
Definition dl_image.cc:11
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