Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
WrappedSurfaceCopyOnWriteTest.cpp File Reference
#include "include/core/SkAlphaType.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkColorType.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.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/gpu/GpuTypes.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrTypes.h"
#include "include/private/SkColorData.h"
#include "include/private/chromium/GrDeferredDisplayListRecorder.h"
#include "include/private/chromium/GrSurfaceCharacterization.h"
#include "include/private/gpu/ganesh/GrTypesPriv.h"
#include "src/core/SkAutoPixmapStorage.h"
#include "src/gpu/SkBackingFit.h"
#include "src/gpu/ganesh/GrCanvas.h"
#include "src/gpu/ganesh/GrDirectContextPriv.h"
#include "src/gpu/ganesh/GrDrawingManager.h"
#include "src/gpu/ganesh/GrImageInfo.h"
#include "src/gpu/ganesh/GrRenderTargetProxy.h"
#include "src/gpu/ganesh/GrRenderTask.h"
#include "src/gpu/ganesh/GrSamplerState.h"
#include "src/gpu/ganesh/GrSurfaceProxy.h"
#include "src/gpu/ganesh/GrSurfaceProxyView.h"
#include "src/gpu/ganesh/GrTextureProxy.h"
#include "src/gpu/ganesh/SurfaceContext.h"
#include "src/gpu/ganesh/SurfaceFillContext.h"
#include "tests/CtsEnforcement.h"
#include "tests/Test.h"
#include "tests/TestUtils.h"
#include "tools/gpu/BackendSurfaceFactory.h"
#include "tools/gpu/ProxyUtils.h"
#include <functional>
#include <memory>

Go to the source code of this file.

Functions

 DEF_GANESH_TEST_FOR_ALL_CONTEXTS (WrappedSurfaceCopyOnWrite, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (SkipCopyTaskTest, reporter, ctxInfo, CtsEnforcement::kNever)
 

Function Documentation

◆ DEF_GANESH_TEST_FOR_ALL_CONTEXTS()

DEF_GANESH_TEST_FOR_ALL_CONTEXTS ( WrappedSurfaceCopyOnWrite  ,
reporter  ,
ctxInfo  ,
CtsEnforcement::kApiLevel_T   
)

Definition at line 52 of file WrappedSurfaceCopyOnWriteTest.cpp.

55 {
56 using namespace skgpu;
57
58 GrDirectContext* dContext = ctxInfo.directContext();
59
60 Protected isProtected = Protected(dContext->priv().caps()->supportsProtectedContent());
61
62 auto makeDirectBackendSurface = [&]() {
65 info,
67 /* sampleCnt= */ 1,
68 Mipmapped::kNo,
69 isProtected);
70 };
71
72 auto imageProxyID = [&](const sk_sp<SkImage>& img) {
73 return sk_gpu_test::GetTextureImageProxy(img.get(), dContext)->uniqueID();
74 };
75
76 auto surfaceProxyID = [&](const sk_sp<SkSurface>& surf) {
78 return rtp->uniqueID();
79 };
80
81 sk_sp<SkSurface> surf = makeDirectBackendSurface();
82 surf->getCanvas()->clear(SkColor4f{1, 0, 0, 1});
83 sk_sp<SkImage> img = surf->makeImageSnapshot();
84 // Initially they share
85 REPORTER_ASSERT(reporter, surfaceProxyID(surf) == imageProxyID(img));
86 // Using the image on the direct context shouldn't affect sharing.
87 sk_sp<SkSurface> surf2 = makeDirectBackendSurface();
88 surf2->getCanvas()->drawImage(img, 0, 0);
89 REPORTER_ASSERT(reporter, surfaceProxyID(surf) == imageProxyID(img));
90 // Modifying the original surface should trigger using the copy proxy.
91 surf->getCanvas()->clear({0, 0, 1, 1});
92 REPORTER_ASSERT(reporter, surfaceProxyID(surf) != imageProxyID(img));
93 // Image caching on surface should mean another snapshot gives us the same image.
94 GrSurfaceProxy::UniqueID imageID = imageProxyID(img);
95 img = surf->makeImageSnapshot();
96 REPORTER_ASSERT(reporter, imageProxyID(img) != imageID);
97
98 GrSurfaceCharacterization characterization;
99 REPORTER_ASSERT(reporter, surf->characterize(&characterization));
100 GrDeferredDisplayListRecorder recorder(characterization);
101
102 // Using an image from a direct context on a recording context should trigger using the copy.
103 surf = makeDirectBackendSurface();
104 img = surf->makeImageSnapshot();
105 REPORTER_ASSERT(reporter, surfaceProxyID(surf) == imageProxyID(img));
106 recorder.getCanvas()->drawImage(img, 0, 0);
107 REPORTER_ASSERT(reporter, surfaceProxyID(surf) != imageProxyID(img));
108
109 // Same as above but if the surface goes out of scope first we keep using the original
110 surf = makeDirectBackendSurface();
111 img = surf->makeImageSnapshot();
112 GrSurfaceProxy::UniqueID surfID = surfaceProxyID(surf);
113 REPORTER_ASSERT(reporter, surfaceProxyID(surf) == imageProxyID(img));
114 surf.reset();
115 recorder.getCanvas()->drawImage(img, 0, 0);
116 REPORTER_ASSERT(reporter, surfID == imageProxyID(img));
117}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
reporter
@ kTopLeft_GrSurfaceOrigin
Definition GrTypes.h:148
skgpu::Protected Protected
@ 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
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
const GrCaps * caps() const
bool supportsProtectedContent() const
Definition GrCaps.h:422
GrDirectContextPriv priv()
UniqueID uniqueID() const
void reset(T *ptr=nullptr)
Definition SkRefCnt.h:310
GrTextureProxy * GetTextureImageProxy(SkImage *image, GrRecordingContext *rContext)
sk_sp< SkSurface > MakeBackendTextureSurface(GrDirectContext *dContext, const SkImageInfo &ii, GrSurfaceOrigin origin, int sampleCnt, skgpu::Mipmapped mipmapped, GrProtected isProtected, const SkSurfaceProps *props)
GrRenderTargetProxy * TopDeviceTargetProxy(const SkCanvas *canvas)
Definition GrCanvas.cpp:34
Protected
Definition GpuTypes.h:61
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS()

DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS ( SkipCopyTaskTest  ,
reporter  ,
ctxInfo  ,
CtsEnforcement::kNever   
)

Definition at line 120 of file WrappedSurfaceCopyOnWriteTest.cpp.

123 {
124 GrDirectContext* dContext = ctxInfo.directContext();
125
128 /*color space*/ nullptr,
129 10, 10);
130
131 auto dstSC = CreateSurfaceContext(dContext,
132 info,
135 GrRenderable::kYes);
136 dstSC->asFillContext()->clear(SkPMColor4f{1, 0, 0, 1});
137
138 auto srcSC = CreateSurfaceContext(dContext,
139 info,
142 GrRenderable::kYes);
143 srcSC->asFillContext()->clear(SkPMColor4f{0, 0, 1, 1});
144
146 dContext->priv().drawingManager()->newCopyRenderTask(dstSC->asSurfaceProxyRef(),
147 SkIRect::MakeWH(10, 10),
148 srcSC->asSurfaceProxyRef(),
149 SkIRect::MakeWH(10, 10),
150 GrSamplerState::Filter::kNearest,
152
153 if (!task) {
154 ERRORF(reporter, "Couldn't make a copy task.");
155 return;
156 }
157
158 task->makeSkippable();
159
160 SkAutoPixmapStorage pixels;
162 dstSC->readPixels(dContext, pixels, {0, 0});
163 float kTol[4] = {};
164 std::function<ComparePixmapsErrorReporter> errorReporter(
165 [&](int x, int y, const float diffs[4]) {
166 ERRORF(reporter, "Expected {1, 0, 0, 1}. diff {%f, %f, %f, %f}",
167 diffs[0], diffs[1], diffs[2], diffs[3]);
168 });
169 CheckSolidPixels(SkColor4f{1, 0, 0, 1}, pixels, kTol, errorReporter);
170}
@ kBottomLeft_GrSurfaceOrigin
Definition GrTypes.h:149
std::unique_ptr< skgpu::ganesh::SurfaceContext > CreateSurfaceContext(GrRecordingContext *rContext, const GrImageInfo &info, SkBackingFit fit, GrSurfaceOrigin origin, GrRenderable renderable, int sampleCount, skgpu::Mipmapped mipmapped, GrProtected isProtected, skgpu::Budgeted budgeted)
bool CheckSolidPixels(const SkColor4f &col, const SkPixmap &pixmap, const float tolRGBA[4], std::function< ComparePixmapsErrorReporter > &error)
#define ERRORF(r,...)
Definition Test.h:293
sk_sp< GrRenderTask > newCopyRenderTask(sk_sp< GrSurfaceProxy > dst, SkIRect dstRect, const sk_sp< GrSurfaceProxy > &src, SkIRect srcRect, GrSamplerState::Filter filter, GrSurfaceOrigin)
GrDrawingManager * drawingManager()
void alloc(const SkImageInfo &)
double y
double x
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition SkRect.h:56