Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QtTextureView.java
Go to the documentation of this file.
1// Copyright (C) 2014 BogDan Vatra <bogdan@kde.org>
2// Copyright (C) 2016 The Qt Company Ltd.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5package org.qtproject.qt.android;
6
7import android.annotation.SuppressLint;
8import android.content.Context;
9import android.graphics.SurfaceTexture;
10import android.view.Surface;
11import android.view.TextureView;
12
13@SuppressLint("ViewConstructor")
14class QtTextureView extends TextureView implements TextureView.SurfaceTextureListener
15{
16 private final QtSurfaceInterface m_surfaceCallback;
17 private boolean m_staysOnTop;
18 private Surface m_surface;
19
20 QtTextureView(Context context, QtSurfaceInterface surfaceCallback, boolean isOpaque)
21 {
22 super(context);
23 setFocusable(false);
24 setFocusableInTouchMode(false);
25 m_surfaceCallback = surfaceCallback;
26 setSurfaceTextureListener(this);
27 setOpaque(isOpaque);
28 setSurfaceTexture(new SurfaceTexture(false));
29 }
30
32 public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width, int height) {
33 if (m_surface == null) {
34 m_surface = new Surface(surfaceTexture);
35 m_surfaceCallback.onSurfaceCreated(m_surface);
36 }
37 }
38
40 public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int width, int height) {
41 // A SurfaceTexture set in the constructor never gets onSurfaceTextureAvailable,
42 // so the first resize delivers the Surface.
43 if (m_surface == null) {
44 m_surface = new Surface(surfaceTexture);
45 m_surfaceCallback.onSurfaceCreated(m_surface);
46 return;
47 }
48 // HWUI shows the old buffer at the new size until Qt draws, and offers
49 // nothing to wait on, so ask for a frame right away.
50 m_surfaceCallback.onSurfaceRedrawNeeded(() -> {});
51 }
52
54 public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
55 final Surface surface = m_surface;
56 m_surface = null;
57 m_surfaceCallback.onSurfaceDestroyed(() -> {
58 if (surface != null)
59 surface.release();
60 surfaceTexture.release();
61 });
62 return false;
63 }
64
66 public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
67 }
68}
QPainter Context
GLint GLsizei width