Flutter Engine
 
Loading...
Searching...
No Matches
flutter::testing::MockTexture Class Reference

#include <mock_texture.h>

Inheritance diagram for flutter::testing::MockTexture:
flutter::Texture flutter::Texture flutter::ContextListener flutter::ContextListener

Public Member Functions

 MockTexture (int64_t textureId, const sk_sp< DlImage > &texture=nullptr)
 
void Paint (PaintContext &context, const DlRect &bounds, bool freeze, const DlImageSampling sampling) override
 
void OnGrContextCreated () override
 
void OnGrContextDestroyed () override
 
void MarkNewFrameAvailable () override
 
void OnTextureUnregistered () override
 
bool gr_context_created ()
 
bool gr_context_destroyed ()
 
bool unregistered ()
 
 MockTexture (int64_t textureId, std::shared_ptr< fml::AutoResetWaitableEvent > latch)
 
 ~MockTexture () override=default
 
void Paint (PaintContext &context, const DlRect &bounds, bool freeze, const DlImageSampling) override
 
void OnGrContextCreated () override
 
void OnGrContextDestroyed () override
 
void MarkNewFrameAvailable () override
 
void OnTextureUnregistered () override
 
bool unregistered ()
 
int frames_available ()
 
- Public Member Functions inherited from flutter::Texture
 Texture (int64_t id)
 
virtual ~Texture ()
 
int64_t Id ()
 
- Public Member Functions inherited from flutter::ContextListener
 ContextListener ()
 
 ~ContextListener ()
 

Static Public Member Functions

static sk_sp< DlImageMakeTestTexture (int w, int h, int checker_size)
 

Detailed Description

Definition at line 20 of file mock_texture.h.

Constructor & Destructor Documentation

◆ MockTexture() [1/2]

flutter::testing::MockTexture::MockTexture ( int64_t  textureId,
const sk_sp< DlImage > &  texture = nullptr 
)
explicit

Definition at line 32 of file mock_texture.cc.

33 : Texture(textureId), texture_(texture) {}
Texture(int64_t id)
Definition texture.cc:13
FlTexture * texture

◆ MockTexture() [2/2]

flutter::testing::MockTexture::MockTexture ( int64_t  textureId,
std::shared_ptr< fml::AutoResetWaitableEvent latch 
)
inline

Definition at line 2003 of file shell_unittests.cc.

2005 : Texture(textureId), latch_(std::move(latch)) {}

◆ ~MockTexture()

flutter::testing::MockTexture::~MockTexture ( )
overridedefault

Member Function Documentation

◆ frames_available()

int flutter::testing::MockTexture::frames_available ( )
inline

Definition at line 2030 of file shell_unittests.cc.

2030{ return frames_available_; }

◆ gr_context_created()

bool flutter::testing::MockTexture::gr_context_created ( )
inline

Definition at line 38 of file mock_texture.h.

38{ return gr_context_created_; }

◆ gr_context_destroyed()

bool flutter::testing::MockTexture::gr_context_destroyed ( )
inline

Definition at line 39 of file mock_texture.h.

39{ return gr_context_destroyed_; }

◆ MakeTestTexture()

sk_sp< DlImage > flutter::testing::MockTexture::MakeTestTexture ( int  w,
int  h,
int  checker_size 
)
static

Definition at line 12 of file mock_texture.cc.

12 {
13 sk_sp<SkSurface> surface =
14 SkSurfaces::Raster(SkImageInfo::MakeN32Premul(w, h));
15 SkCanvas* canvas = surface->getCanvas();
16 SkPaint p0, p1;
17 p0.setStyle(SkPaint::kFill_Style);
18 p0.setColor(SK_ColorGREEN);
19 p1.setStyle(SkPaint::kFill_Style);
20 p1.setColor(SK_ColorBLUE);
21 p1.setAlpha(128);
22 for (int y = 0; y < w; y += checker_size) {
23 for (int x = 0; x < h; x += checker_size) {
24 SkPaint& cellp = ((x + y) & 1) == 0 ? p0 : p1;
25 canvas->drawRect(SkRect::MakeXYWH(x, y, checker_size, checker_size),
26 cellp);
27 }
28 }
29 return DlImage::Make(surface->makeImageSnapshot());
30}
static sk_sp< DlImage > Make(const SkImage *image)
Definition dl_image.cc:11
int32_t x
VkSurfaceKHR surface
Definition main.cc:65
double y
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder h
Definition switch_defs.h:54

References flutter::h, flutter::DlImage::Make(), surface, x, and y.

Referenced by flutter::testing::TEST(), flutter::testing::TEST(), and flutter::testing::TEST_F().

◆ MarkNewFrameAvailable() [1/2]

void flutter::testing::MockTexture::MarkNewFrameAvailable ( )
inlineoverridevirtual

Implements flutter::Texture.

Definition at line 35 of file mock_texture.h.

35{}

◆ MarkNewFrameAvailable() [2/2]

void flutter::testing::MockTexture::MarkNewFrameAvailable ( )
inlineoverridevirtual

Implements flutter::Texture.

Definition at line 2019 of file shell_unittests.cc.

2019 {
2020 frames_available_++;
2021 latch_->Signal();
2022 }

◆ OnGrContextCreated() [1/2]

void flutter::testing::MockTexture::OnGrContextCreated ( )
inlineoverridevirtual

Implements flutter::ContextListener.

Definition at line 33 of file mock_texture.h.

33{ gr_context_created_ = true; }

◆ OnGrContextCreated() [2/2]

void flutter::testing::MockTexture::OnGrContextCreated ( )
inlineoverridevirtual

Implements flutter::ContextListener.

Definition at line 2015 of file shell_unittests.cc.

2015{}

◆ OnGrContextDestroyed() [1/2]

void flutter::testing::MockTexture::OnGrContextDestroyed ( )
inlineoverridevirtual

Implements flutter::ContextListener.

Definition at line 34 of file mock_texture.h.

34{ gr_context_destroyed_ = true; }

◆ OnGrContextDestroyed() [2/2]

void flutter::testing::MockTexture::OnGrContextDestroyed ( )
inlineoverridevirtual

Implements flutter::ContextListener.

Definition at line 2017 of file shell_unittests.cc.

2017{}

◆ OnTextureUnregistered() [1/2]

void flutter::testing::MockTexture::OnTextureUnregistered ( )
inlineoverridevirtual

Implements flutter::Texture.

Definition at line 36 of file mock_texture.h.

36{ unregistered_ = true; }

◆ OnTextureUnregistered() [2/2]

void flutter::testing::MockTexture::OnTextureUnregistered ( )
inlineoverridevirtual

Implements flutter::Texture.

Definition at line 2024 of file shell_unittests.cc.

2024 {
2025 unregistered_ = true;
2026 latch_->Signal();
2027 }

◆ Paint() [1/2]

void flutter::testing::MockTexture::Paint ( PaintContext context,
const DlRect bounds,
bool  freeze,
const DlImageSampling  sampling 
)
overridevirtual

Implements flutter::Texture.

Definition at line 35 of file mock_texture.cc.

38 {
39 // MockTexture objects that are not painted are allowed to have a null
40 // texture, but when we get to this method we must have a non-null texture.
41 FML_DCHECK(texture_ != nullptr);
42 DlRect src = DlRect::Make(texture_->GetBounds());
43 if (freeze) {
44 FML_DCHECK(src.GetWidth() > 2.0f && src.GetHeight() > 2.0f);
45 src = src.Expand(-1.0f, -1.0f);
46 }
47 context.canvas->DrawImageRect(texture_, src, bounds, sampling, context.paint);
48}
#define FML_DCHECK(condition)
Definition logging.h:122
impeller::Rect DlRect
static constexpr std::enable_if_t< std::is_floating_point_v< FT >, TRect > Make(const TRect< U > &rect)
Definition rect.h:157

References flutter::Texture::PaintContext::canvas, flutter::DlCanvas::DrawImageRect(), impeller::TRect< T >::Expand(), FML_DCHECK, impeller::TRect< T >::GetHeight(), impeller::TRect< T >::GetWidth(), impeller::TRect< Scalar >::Make(), and flutter::Texture::PaintContext::paint.

◆ Paint() [2/2]

void flutter::testing::MockTexture::Paint ( PaintContext context,
const DlRect bounds,
bool  freeze,
const DlImageSampling   
)
inlineoverridevirtual

Implements flutter::Texture.

Definition at line 2010 of file shell_unittests.cc.

2013 {}

◆ unregistered() [1/2]

bool flutter::testing::MockTexture::unregistered ( )
inline

Definition at line 40 of file mock_texture.h.

40{ return unregistered_; }

◆ unregistered() [2/2]

bool flutter::testing::MockTexture::unregistered ( )
inline

Definition at line 2029 of file shell_unittests.cc.

2029{ return unregistered_; }

The documentation for this class was generated from the following files: