Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
embedder_external_texture_metal.mm
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
5#include "flutter/shell/platform/embedder/embedder_external_texture_metal.h"
6
7#include "flow/layers/layer.h"
8#include "flutter/fml/logging.h"
9#import "flutter/shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.h"
14
15namespace flutter {
16
17static bool ValidNumTextures(int expected, int actual) {
18 if (expected == actual) {
19 return true;
20 } else {
21 FML_LOG(ERROR) << "Invalid number of textures, expected: " << expected << ", got: " << actual;
22 return false;
23 }
24}
25
28 : Texture(texture_identifier), external_texture_callback_(callback) {
29 FML_DCHECK(external_texture_callback_);
30}
31
33
34// |flutter::Texture|
36 const SkRect& bounds,
37 bool freeze,
38 const DlImageSampling sampling) {
39 if (last_image_ == nullptr) {
40 last_image_ =
41 ResolveTexture(Id(), context.gr_context, SkISize::Make(bounds.width(), bounds.height()));
42 }
43
44 DlCanvas* canvas = context.canvas;
45 const DlPaint* paint = context.paint;
46
47 if (last_image_) {
48 SkRect image_bounds = SkRect::Make(last_image_->bounds());
49 if (bounds != image_bounds) {
50 canvas->DrawImageRect(last_image_, image_bounds, bounds, sampling, paint);
51 } else {
52 canvas->DrawImage(last_image_, {bounds.x(), bounds.y()}, sampling, paint);
53 }
54 }
55}
56
57sk_sp<DlImage> EmbedderExternalTextureMetal::ResolveTexture(int64_t texture_id,
58 GrDirectContext* context,
59 const SkISize& size) {
60 std::unique_ptr<FlutterMetalExternalTexture> texture =
61 external_texture_callback_(texture_id, size.width(), size.height());
62
63 if (!texture) {
64 return nullptr;
65 }
66
68
69 switch (texture->pixel_format) {
71 if (ValidNumTextures(1, texture->num_textures)) {
72 id<MTLTexture> rgbaTex = (__bridge id<MTLTexture>)texture->textures[0];
73 image = [FlutterDarwinExternalTextureSkImageWrapper wrapRGBATexture:rgbaTex
74 grContext:context
75 width:size.width()
76 height:size.height()];
77 }
78 break;
79 }
81 if (ValidNumTextures(2, texture->num_textures)) {
82 id<MTLTexture> yTex = (__bridge id<MTLTexture>)texture->textures[0];
83 id<MTLTexture> uvTex = (__bridge id<MTLTexture>)texture->textures[1];
84 SkYUVColorSpace colorSpace =
89 UVTex:uvTex
90 YUVColorSpace:colorSpace
91 grContext:context
92 width:size.width()
93 height:size.height()];
94 }
95 break;
96 }
97 }
98
99 if (!image) {
100 FML_LOG(ERROR) << "Could not create external texture: " << texture_id;
101 }
102
103 // This image should not escape local use by EmbedderExternalTextureMetal
104 return DlImage::Make(std::move(image));
105}
106
107// |flutter::Texture|
109
110// |flutter::Texture|
112
113// |flutter::Texture|
115 last_image_ = nullptr;
116}
117
118// |flutter::Texture|
120
121} // namespace flutter
SkYUVColorSpace
Definition SkImageInfo.h:68
@ kRec601_Limited_SkYUVColorSpace
describes SDTV range
Definition SkImageInfo.h:70
@ kJPEG_Full_SkYUVColorSpace
describes full range
Definition SkImageInfo.h:69
Developer-facing API for rendering anything within the engine.
Definition dl_canvas.h:37
virtual void DrawImageRect(const sk_sp< DlImage > &image, const SkRect &src, const SkRect &dst, DlImageSampling sampling, const DlPaint *paint=nullptr, SrcRectConstraint constraint=SrcRectConstraint::kFast)=0
virtual void DrawImage(const sk_sp< DlImage > &image, const SkPoint point, DlImageSampling sampling, const DlPaint *paint=nullptr)=0
static sk_sp< DlImage > Make(const SkImage *image)
Definition dl_image.cc:11
EmbedderExternalTextureMetal(int64_t texture_identifier, const ExternalTextureCallback &callback)
std::function< std::unique_ptr< FlutterMetalExternalTexture >(int64_t, size_t, size_t)> ExternalTextureCallback
void Paint(PaintContext &context, const SkRect &bounds, bool freeze, const DlImageSampling sampling) override
int64_t Id()
Definition texture.h:63
const Paint & paint
@ kBT601LimitedRange
Definition embedder.h:611
@ kRGBA
Definition embedder.h:605
@ kYUVA
Definition embedder.h:604
sk_sp< SkImage > image
Definition examples.cpp:29
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
#define FML_LOG(severity)
Definition logging.h:82
#define FML_DCHECK(condition)
Definition logging.h:103
FlTexture * texture
static bool ValidNumTextures(int expected, int actual)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition switches.h:259
YUVColorSpace
Definition color.h:55
int32_t height
int32_t width
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20
static SkRect Make(const SkISize &size)
Definition SkRect.h:669
GrDirectContext * gr_context
Definition texture.h:43
int64_t texture_id
#define ERROR(message)