Flutter Engine
txt::RenderTest Class Reference

#include <render_test.h>

Inheritance diagram for txt::RenderTest:

Public Member Functions

 RenderTest ()
 
 ~RenderTest ()
 
SkCanvas * GetCanvas ()
 
bool Snapshot ()
 
size_t GetTestCanvasWidth () const
 
size_t GetTestCanvasHeight () const
 
std::shared_ptr< txt::FontCollectionGetTestFontCollection () const
 

Protected Member Functions

void SetUp () override
 
void TearDown () override
 

Detailed Description

Definition at line 28 of file render_test.h.

Constructor & Destructor Documentation

◆ RenderTest()

txt::RenderTest::RenderTest ( )

Definition at line 30 of file render_test.cc.

References ~RenderTest().

31  : snapshots_(0), font_collection_(txt::GetTestFontCollection()) {}
std::shared_ptr< FontCollection > GetTestFontCollection()

◆ ~RenderTest()

txt::RenderTest::~RenderTest ( )
default

Referenced by RenderTest().

Member Function Documentation

◆ GetCanvas()

SkCanvas * txt::RenderTest::GetCanvas ( )

Definition at line 35 of file render_test.cc.

35  {
36  return canvas_ == nullptr ? nullptr : canvas_.get();
37 }

◆ GetTestCanvasHeight()

size_t txt::RenderTest::GetTestCanvasHeight ( ) const

Definition at line 80 of file render_test.cc.

Referenced by SetUp().

80  {
81  return 600;
82 }

◆ GetTestCanvasWidth()

size_t txt::RenderTest::GetTestCanvasWidth ( ) const

Definition at line 76 of file render_test.cc.

Referenced by SetUp().

76  {
77  return 1000;
78 }

◆ GetTestFontCollection()

std::shared_ptr< FontCollection > txt::RenderTest::GetTestFontCollection ( ) const

Definition at line 91 of file render_test.cc.

91  {
92  return font_collection_;
93 }

◆ SetUp()

void txt::RenderTest::SetUp ( )
overrideprotected

Definition at line 84 of file render_test.cc.

References GetTestCanvasHeight(), and GetTestCanvasWidth().

84  {
85  bitmap_ = std::make_unique<SkBitmap>();
86  bitmap_->allocN32Pixels(GetTestCanvasWidth(), GetTestCanvasHeight());
87  canvas_ = std::make_unique<SkCanvas>(*bitmap_);
88  canvas_->clear(SK_ColorWHITE);
89 }
size_t GetTestCanvasHeight() const
Definition: render_test.cc:80
size_t GetTestCanvasWidth() const
Definition: render_test.cc:76

◆ Snapshot()

bool txt::RenderTest::Snapshot ( )

Definition at line 51 of file render_test.cc.

References error, and FML_LOG.

51  {
52  if (!canvas_ || !bitmap_) {
53  return false;
54  }
55  std::string snapshot_dir = "snapshots";
56  int error = 0;
57 // _WIN32 defined by Windows Visual compiler.
58 #if defined(_WIN32)
59  // Handle windows path creation.
60  error = _mkdir(snapshot_dir.c_str());
61 #else
62  // Handle non-windows path creation with Unix permissions.
63  mode_t permissions = 0733;
64  error = mkdir(snapshot_dir.c_str(), permissions);
65 #endif
66  if (error > 0) {
67  FML_LOG(ERROR) << "'snapshot/' Directory not available and could not be "
68  "created. Please create manually to save snapshot.";
69  return false;
70  }
71  auto file_name = GetNextSnapshotName();
72  SkFILEWStream file(file_name.c_str());
73  return SkEncodeImage(&file, *bitmap_, SkEncodedImageFormat::kPNG, 100);
74 }
FlMethodResponse GError ** error
#define FML_LOG(severity)
Definition: logging.h:65

◆ TearDown()

void txt::RenderTest::TearDown ( )
overrideprotected

Definition at line 95 of file render_test.cc.

95  {
96  canvas_ = nullptr;
97  bitmap_ = nullptr;
98 }

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