Flutter Engine
The 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
5#include "flutter/flow/testing/mock_texture.h"
6#include "flutter/flow/layers/layer.h"
7#include "flutter/testing/display_list_testing.h"
8
9namespace flutter {
10namespace testing {
11
12sk_sp<DlImage> MockTexture::MakeTestTexture(int w, int h, int checker_size) {
15 SkCanvas* canvas = surface->getCanvas();
16 SkPaint p0, p1;
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
33 : Texture(textureId), texture_(texture) {}
34
36 const SkRect& 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 SkRect src = SkRect::Make(texture_->bounds());
43 if (freeze) {
44 FML_DCHECK(src.width() > 2.0f && src.height() > 2.0f);
45 src = src.makeInset(1.0f, 1.0f);
46 }
47 context.canvas->DrawImageRect(texture_, src, bounds, sampling, context.paint);
48}
49
50} // namespace testing
51} // namespace flutter
constexpr SkColor SK_ColorBLUE
Definition SkColor.h:135
constexpr SkColor SK_ColorGREEN
Definition SkColor.h:131
void drawRect(const SkRect &rect, const SkPaint &paint)
void setStyle(Style style)
Definition SkPaint.cpp:105
void setColor(SkColor color)
Definition SkPaint.cpp:119
@ kFill_Style
set to fill geometry
Definition SkPaint.h:193
void setAlpha(U8CPU a)
Definition SkPaint.h:279
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
static sk_sp< DlImage > Make(const SkImage *image)
Definition dl_image.cc:11
void Paint(PaintContext &context, const SkRect &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)
VkSurfaceKHR surface
Definition main.cc:49
#define FML_DCHECK(condition)
Definition logging.h:103
FlTexture * texture
double y
double x
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
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 switches.h:59
SkScalar w
static SkImageInfo MakeN32Premul(int width, int height)
static SkRect Make(const SkISize &size)
Definition SkRect.h:669
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659