blob: 0485ab12abe95672a26d248a144a170c04a50e6d [file] [log] [blame]
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'box.dart';
import 'layer.dart';
import 'object.dart';
/// A rectangle upon which a backend texture is mapped.
/// Backend textures are images that can be applied (mapped) to an area of the
/// Flutter view. They are created, managed, and updated using a
/// platform-specific texture registry. This is typically done by a plugin
/// that integrates with host platform video player, camera, or OpenGL APIs,
/// or similar image sources.
/// A texture box refers to its backend texture using an integer ID. Texture
/// IDs are obtained from the texture registry and are scoped to the Flutter
/// view. Texture IDs may be reused after deregistration, at the discretion
/// of the registry. The use of texture IDs currently unknown to the registry
/// will silently result in a blank rectangle.
/// Texture boxes are repainted autonomously as dictated by the backend (e.g. on
/// arrival of a video frame). Such repainting generally does not involve
/// executing Dart code.
/// The size of the rectangle is determined by the parent, and the texture is
/// automatically scaled to fit.
/// See also:
/// * <>
/// for how to create and manage backend textures on Android.
/// * <>
/// for how to create and manage backend textures on iOS.
class TextureBox extends RenderBox {
/// Creates a box backed by the texture identified by [textureId], and use
/// [filterQuality] to set texture's [FilterQuality].
required int textureId,
bool freeze = false,
FilterQuality filterQuality = FilterQuality.low,
}) : _textureId = textureId,
_freeze = freeze,
_filterQuality = filterQuality;
/// The identity of the backend texture.
int get textureId => _textureId;
int _textureId;
set textureId(int value) {
if (value != _textureId) {
_textureId = value;
/// When true the texture will not be updated with new frames.
bool get freeze => _freeze;
bool _freeze;
set freeze(bool value) {
if (value != _freeze) {
_freeze = value;
/// {@macro flutter.widgets.Texture.filterQuality}
FilterQuality get filterQuality => _filterQuality;
FilterQuality _filterQuality;
set filterQuality(FilterQuality value) {
if (value != _filterQuality) {
_filterQuality = value;
bool get sizedByParent => true;
bool get alwaysNeedsCompositing => true;
bool get isRepaintBoundary => true;
Size computeDryLayout(BoxConstraints constraints) {
return constraints.biggest;
bool hitTestSelf(Offset position) => true;
void paint(PaintingContext context, Offset offset) {
rect: Rect.fromLTWH(offset.dx, offset.dy, size.width, size.height),
textureId: _textureId,
freeze: freeze,
filterQuality: _filterQuality,