10#include <emscripten.h>
11#include <emscripten/bind.h>
12#include <emscripten/html5.h>
46 JSArray gms = emscripten::val::array();
48 std::unique_ptr<skiagm::GM> gm(fact());
49 SkDebugf(
"gm %s\n", gm->getName().c_str());
50 gms.call<
void>(
"push", std::string(gm->getName().c_str()));
57 std::unique_ptr<skiagm::GM> gm(fact());
58 if (gm->getName().c_str() ==
name) {
71 EMSCRIPTEN_RESULT r = emscripten_webgl_make_context_current(context);
73 printf(
"failed to make webgl context current %d\n", r);
101 const uint8_t* bytes =
reinterpret_cast<const uint8_t*
>(bPtr);
120 SkDebugf(
"Could not find gm with name %s\n",
name.c_str());
126 auto colorType = SkColorType::kN32_SkColorType;
132 SkDebugf(
"Could not make surface\n");
135 auto canvas =
surface->getCanvas();
137 gm->onceBeforeDraw();
140 auto gpuSetupResult = gm->gpuSetup(canvas, &msg);
148 auto drawResult = gm->draw(canvas, &msg);
160 if (!canvas->readPixels(
bitmap, 0, 0)) {
161 SkDebugf(
"Could not read pixels back\n");
167 std::unique_ptr<HashAndEncode> hashAndEncode = std::make_unique<HashAndEncode>(
bitmap);
170 hashAndEncode->feedHash(&
hash);
172 for (
int i = 0; i < 16; i++) {
173 md5.appendf(
"%02x", digest.
data[i]);
183 hashAndEncode->encodePNG(&stream,
md5.c_str(),
empty,
empty);
185 auto data = stream.detachAsData();
193 typed_memory_view(data->size(), data->bytes())
196 result.set(
"png", pngData);
208 tests.call<
void>(
"push", std::string(
test.fName));
230 fResult.set(
"result",
"failed");
248 SkDebugf(
"Could not find test with name %s\n",
name.c_str());
253 result.set(
"result",
"passed");
255 test.modifyGrContextOptions(&grOpts);
259 SkDebugf(
"Graphite test %s not yet supported\n",
name.c_str());
263 result.set(
"result",
"passed");
278 return ct == skgpu::ContextType::kMock;
288 for (
auto contextType : {skgpu::ContextType::kGLES, skgpu::ContextType::kMock}) {
289 if (filter && !(*filter)(contextType)) {
316 WasmWebGlTestContext() {}
317 ~WasmWebGlTestContext()
override {
323 std::unique_ptr<GLTestContext>
makeNew()
const override {
342 return new WasmWebGlTestContext();
362 class_<GrDirectContext>(
"GrDirectContext")
static SkMD5::Digest md5(const SkBitmap &bm)
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
SK_API sk_sp< const GrGLInterface > GrGLMakeNativeInterface()
@ kBottomLeft_GrSurfaceOrigin
sk_sp< SkData >(* gResourceFactory)(const char *)
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
static bool ok(int result)
static uint32_t hash(const SkShaderBase::GradientInfo &v)
#define REPORTER_ASSERT(r, cond,...)
emscripten::val Uint8Array
void flushAndSubmit(GrSyncCpu sync=GrSyncCpu::kNo)
static sk_sp< SkData > MakeFromMalloc(const void *data, size_t length)
const char * c_str() const
GrDirectContext * directContext() const
TestContext * testContext() const
virtual std::unique_ptr< GLTestContext > makeNew() const
virtual GrGLFuncPtr onPlatformGetProcAddress(const char *) const =0
virtual std::function< void()> onPlatformGetAutoContextRestore() const =0
virtual void onPlatformMakeNotCurrent() const =0
virtual void onPlatformMakeCurrent() const =0
EMSCRIPTEN_KEEPALIVE void empty()
Dart_NativeFunction function
static std::unique_ptr< skiagm::GM > getGMWithName(std::string name)
static std::map< std::string, sk_sp< SkData > > gResources
static std::set< std::string > gKnownDigests
static sk_sp< SkData > getResource(const char *name)
static void LoadKnownDigest(std::string md5)
static JSArray ListTests()
static sk_sp< GrDirectContext > MakeGrContext(EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context)
TestHarness CurrentTestHarness()
static skiatest::Test getTestWithName(std::string name, bool *ok)
static JSObject RunGM(sk_sp< GrDirectContext > ctx, std::string name)
static JSObject RunTest(std::string name)
static void LoadResource(std::string name, WASMPointerU8 bPtr, size_t len)
SK_API sk_sp< GrDirectContext > MakeGL()
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)
GLTestContext * CreatePlatformGLTestContext(GrGLStandard forcedGpuAPI, GLTestContext *shareContext)
GrBackendApi ContextTypeBackend(skgpu::ContextType type)
std::function< std::unique_ptr< skiagm::GM >()> GMFactory
void RunWithGaneshTestContexts(GrContextTestFn *testFn, ContextTypeFilterFn *filter, Reporter *reporter, const GrContextOptions &options)
bool IsMetalContextType(skgpu::ContextType type)
bool IsGLContextType(skgpu::ContextType type)
bool ContextTypeFilterFn(GpuContextType)
bool IsMockContextType(skgpu::ContextType type)
bool IsDirect3DContextType(skgpu::ContextType type)
void GrContextTestFn(Reporter *, const sk_gpu_test::ContextInfo &)
bool IsDawnContextType(skgpu::ContextType type)
bool IsVulkanContextType(skgpu::ContextType type)
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
void reportFailed(const skiatest::Failure &failure) override
WasmReporter(std::string name, JSObject result)
SkString toString() const
static Test MakeCPU(const char *name, CPUTestProc proc)