Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
RepeatedClippedBlurTest.cpp File Reference
#include "include/core/SkAlphaType.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorType.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageFilter.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkSamplingOptions.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTypes.h"
#include "include/effects/SkImageFilters.h"
#include "include/gpu/GpuTypes.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrTypes.h"
#include "include/gpu/ganesh/SkImageGanesh.h"
#include "include/gpu/ganesh/SkSurfaceGanesh.h"
#include "src/gpu/ganesh/GrDirectContextPriv.h"
#include "src/gpu/ganesh/GrResourceCache.h"
#include "tests/CtsEnforcement.h"
#include "tests/Test.h"
#include <cstddef>

Go to the source code of this file.

Functions

 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (RepeatedClippedBlurTest, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 

Function Documentation

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS()

DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS ( RepeatedClippedBlurTest  ,
reporter  ,
ctxInfo  ,
CtsEnforcement::kApiLevel_T   
)

Definition at line 46 of file RepeatedClippedBlurTest.cpp.

49 {
50 auto dContext = ctxInfo.directContext();
51 GrResourceCache* cache = dContext->priv().getResourceCache();
52
55
57 if (!dst) {
58 ERRORF(reporter, "Could not create surfaces for repeated clipped blur test.");
59 return;
60 }
61
62 SkCanvas* dstCanvas = dst->getCanvas();
63
64 sk_sp<SkImage> bigImg;
65
66 // Create the initial big image (this corresponds to the album artwork - which is larger
67 // than the screen)
68 {
71
72 // Make a red ring around a field of green. When rendered the blurred red ring
73 // should still be visible on all sides of the dest image.
74 SkBitmap bm;
75 bm.allocPixels(srcImageII);
77 bm.eraseArea(SkIRect::MakeXYWH(1, 2, 1277, 1274), SK_ColorGREEN);
78
79 sk_sp<SkImage> rasterImg = bm.asImage();
80 bigImg = SkImages::TextureFromImage(dContext, rasterImg);
81 }
82
83 sk_sp<SkImage> smImg;
84
85 // Shrink the album artwork down to the screen's size
86 {
89
91 dContext, skgpu::Budgeted::kYes, screenII, 1, kTopLeft_GrSurfaceOrigin, nullptr);
92 SkCanvas* c = s->getCanvas();
93
94 c->drawImageRect(bigImg, SkRect::MakeWH(1024, 600), SkSamplingOptions());
95
96 smImg = s->makeImageSnapshot();
97 }
98
99 // flush here just to clear the playing field
100 dContext->flushAndSubmit();
101
102 size_t beforeBytes = cache->getResourceBytes();
103
104 // Now draw the screen-sized image, blurred, multiple times with a shrinking clip.
105 // This simulates the swipe away where the screen-sized album artwork is moved off
106 // screen.
107 // Note that the blur has to big enough to kick the blur code into the decimate then
108 // re-expand case.
109 const SkIRect subset = SkIRect::MakeWH(1024, 600);
110 SkIRect clip = SkIRect::MakeWH(1024, 600);
111
112 for (int i = 0; i < 30; ++i) {
113 dstCanvas->clear(SK_ColorBLUE);
114
115 sk_sp<SkImageFilter> blur = SkImageFilters::Blur(20, 20, nullptr);
116
117 SkIRect outSubset;
119 sk_sp<SkImage> filteredImg = SkImages::MakeWithFilter(dContext, smImg, blur.get(), subset,
120 clip, &outSubset, &offset);
121
122 SkRect dstRect = SkRect::MakeXYWH(offset.fX, offset.fY,
123 outSubset.width(), outSubset.height());
124 dstCanvas->drawImageRect(filteredImg, SkRect::Make(outSubset), dstRect, SkSamplingOptions(),
126
127 // Flush here to mimic Chrome's SkiaHelper::ApplyImageFilter
128 dContext->flushAndSubmit();
129
130 clip.fRight -= 16;
131 }
132
133 size_t afterBytes = cache->getResourceBytes();
134
135 // When the bug manifests the resource cache will accumulate ~80MB. If texture recycling
136 // is working as expected the cache size will level off at ~20MB.
137 REPORTER_ASSERT(reporter, afterBytes < beforeBytes + 20000000);
138}
reporter
@ kTopLeft_GrSurfaceOrigin
Definition GrTypes.h:148
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition SkColorType.h:24
constexpr SkColor SK_ColorBLUE
Definition SkColor.h:135
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
constexpr SkColor SK_ColorGREEN
Definition SkColor.h:131
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition SkPath.cpp:3824
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
#define ERRORF(r,...)
Definition Test.h:293
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition SkBitmap.cpp:258
sk_sp< SkImage > asImage() const
Definition SkBitmap.cpp:645
void eraseArea(const SkIRect &area, SkColor c) const
Definition SkBitmap.h:854
void eraseColor(SkColor4f) const
Definition SkBitmap.cpp:442
@ kStrict_SrcRectConstraint
sample only inside bounds; slower
Definition SkCanvas.h:1542
void clear(SkColor color)
Definition SkCanvas.h:1199
void drawImageRect(const SkImage *, const SkRect &src, const SkRect &dst, const SkSamplingOptions &, const SkPaint *, SrcRectConstraint)
static sk_sp< SkImageFilter > Blur(SkScalar sigmaX, SkScalar sigmaY, SkTileMode tileMode, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
T * get() const
Definition SkRefCnt.h:303
struct MyStruct s
SK_API sk_sp< SkImage > TextureFromImage(GrDirectContext *, const SkImage *, skgpu::Mipmapped=skgpu::Mipmapped::kNo, skgpu::Budgeted=skgpu::Budgeted::kYes)
SK_API sk_sp< SkImage > MakeWithFilter(sk_sp< SkImage > src, const SkImageFilter *filter, const SkIRect &subset, const SkIRect &clipBounds, SkIRect *outSubset, SkIPoint *offset)
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)
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 which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets Path to the Flutter assets directory enable service port Allow the VM service to fallback to automatic port selection if binding to a specified port fails trace Trace early application lifecycle Automatically switches to an endless trace buffer trace skia Filters out all Skia trace event categories except those that are specified in this comma separated list dump skp on shader Automatically dump the skp that triggers new shader compilations This is useful for writing custom ShaderWarmUp to reduce jank By this is not enabled to reduce the overhead purge persistent cache
Definition switches.h:191
dst
Definition cp.py:12
Point offset
constexpr int32_t height() const
Definition SkRect.h:165
constexpr int32_t width() const
Definition SkRect.h:158
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition SkRect.h:56
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition SkRect.h:104
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
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
static constexpr SkRect MakeWH(float w, float h)
Definition SkRect.h:609