Flutter Engine
 
Loading...
Searching...
No Matches
mock_texture.cc
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
8
9namespace flutter {
10namespace testing {
11
12sk_sp<DlImage> MockTexture::MakeTestTexture(int w, int h, int checker_size) {
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}
31
32MockTexture::MockTexture(int64_t textureId, const sk_sp<DlImage>& texture)
33 : Texture(textureId), texture_(texture) {}
34
36 const DlRect& bounds,
37 bool freeze,
38 const DlImageSampling sampling) {
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}
49
50} // namespace testing
51} // namespace flutter
virtual void DrawImageRect(const sk_sp< DlImage > &image, const DlRect &src, const DlRect &dst, DlImageSampling sampling, const DlPaint *paint=nullptr, DlSrcRectConstraint constraint=DlSrcRectConstraint::kFast)=0
static sk_sp< DlImage > Make(const SkImage *image)
Definition dl_image.cc:11
void Paint(PaintContext &context, const DlRect &bounds, bool freeze, const DlImageSampling sampling) override
MockTexture(int64_t textureId, const sk_sp< DlImage > &texture=nullptr)
static sk_sp< DlImage > MakeTestTexture(int w, int h, int checker_size)
int32_t x
VkSurfaceKHR surface
Definition main.cc:65
#define FML_DCHECK(condition)
Definition logging.h:122
FlTexture * texture
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
constexpr Type GetHeight() const
Returns the height of the rectangle, equivalent to |GetSize().height|.
Definition rect.h:347
static constexpr std::enable_if_t< std::is_floating_point_v< FT >, TRect > Make(const TRect< U > &rect)
Definition rect.h:157
constexpr Type GetWidth() const
Returns the width of the rectangle, equivalent to |GetSize().width|.
Definition rect.h:341
constexpr TRect< T > Expand(T left, T top, T right, T bottom) const
Returns a rectangle with expanded edges. Negative expansion results in shrinking.
Definition rect.h:618