flutter中android的texture实现原理2

原理1
原理2
flutter端:texture将会设置texture id 找到渲染的texture

TextureBox
context.addLayer(TextureLayer(
      rect: Rect.fromLTWH(offset.dx, offset.dy, size.width, size.height),
      textureId: _textureId, 
    ));

Texture渲染放到了独立图层中,所以Texture可以不加RepaintBoundary

  TextureLayer
    builder.addTexture(
      textureId,
      offset: shiftedRect.topLeft,
      width: shiftedRect.width,
      height: shiftedRect.height,
      freeze: freeze,
    );
void SceneBuilder::addTexture(double dx,
                              double dy,
                              double width,
                              double height,
                              int64_t textureId,
                              bool freeze,
                              int filterQuality) {
  auto layer = std::make_unique(
      SkPoint::Make(dx, dy), SkSize::Make(width, height), textureId, freeze,
      static_cast(filterQuality));
  AddLayer(std::move(layer));
}

paint layer

void LayerTree::Paint(CompositorContext::ScopedFrame& frame,
                      bool ignore_raster_cache) const {
  ......
  if (root_layer_->needs_painting()) {
    root_layer_->Paint(context);
  }
}

TextureLayer Paint

texture_layer.cc
void TextureLayer::Paint(PaintContext& context) const {
  TRACE_EVENT0("flutter", "TextureLayer::Paint");

  std::shared_ptr texture =
      context.texture_registry.GetTexture(texture_id_);
  if (!texture) {
    TRACE_EVENT_INSTANT0("flutter", "null texture");
    return;
  }
  texture->Paint(*context.leaf_nodes_canvas, paint_bounds(), freeze_,
                 context.gr_context, filter_quality_);
}

参考:http://gityuan.com/2019/06/15/flutter_ui_draw/

你可能感兴趣的:(flutter中android的texture实现原理2)