2019-03-05 15:45:40 +00:00
|
|
|
/*
|
2020-09-02 19:40:37 +00:00
|
|
|
* This file defines SkpDebugPlayer, a class which loads a SKP or MSKP file and draws it
|
|
|
|
* to an SkSurface with annotation, and detailed playback controls. It holds as many DebugCanvases
|
|
|
|
* as there are frames in the file.
|
|
|
|
*
|
|
|
|
* It also defines emscripten bindings for SkpDebugPlayer and other classes necessary to us it.
|
|
|
|
*
|
2019-03-05 15:45:40 +00:00
|
|
|
* Copyright 2019 Google LLC
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkPicture.h"
|
2020-08-14 13:43:11 +00:00
|
|
|
#include "include/core/SkString.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkSurface.h"
|
2019-09-20 14:08:25 +00:00
|
|
|
#include "include/utils/SkBase64.h"
|
2020-08-14 13:43:11 +00:00
|
|
|
#include "src/core/SkPicturePriv.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/utils/SkJSONWriter.h"
|
2019-06-21 15:09:19 +00:00
|
|
|
#include "src/utils/SkMultiPictureDocument.h"
|
|
|
|
#include "tools/SkSharingProc.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/UrlDataManager.h"
|
|
|
|
#include "tools/debugger/DebugCanvas.h"
|
2019-12-12 16:05:10 +00:00
|
|
|
#include "tools/debugger/DebugLayerManager.h"
|
2019-03-13 17:31:13 +00:00
|
|
|
|
2019-12-12 16:05:10 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <string_view>
|
|
|
|
#include <vector>
|
2020-09-16 14:35:22 +00:00
|
|
|
#include <map>
|
2019-03-05 15:45:40 +00:00
|
|
|
#include <emscripten.h>
|
|
|
|
#include <emscripten/bind.h>
|
|
|
|
|
2020-03-19 19:54:28 +00:00
|
|
|
#ifdef SK_GL
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/GrBackendSurface.h"
|
Reland "Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext""
This reverts commit cf43fc676856c4db0122ff3bcb49d90b0e7b1115.
Reason for revert: Fixed g3
Original change's description:
> Revert "Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext""
>
> This reverts commit ff13ffbeacec5335cfdb84c8a9d20bb78e10da58.
>
> Reason for revert: Blink in g3
>
> Original change's description:
> > Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext"
> >
> > This reverts commit 89bdc90ac877dc8cd49c86c35a20d9df0d3b9016.
> >
> > Reason for revert: Fix metal
> >
> > Original change's description:
> > > Revert "Take GrContext private, GrDDLContext inherit from GrRecordingContext"
> > >
> > > This reverts commit d2daa94edeca88281796524fae45f38f11a7bef2.
> > >
> > > Reason for revert: Metaru
> > >
> > > Original change's description:
> > > > Take GrContext private, GrDDLContext inherit from GrRecordingContext
> > > >
> > > > Woo!
> > > >
> > > > Change-Id: I8d201b709343dc18cad31ea740575285dd035f35
> > > > Docs-Preview: https://skia.org/?cl=317436
> > > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/317436
> > > > Reviewed-by: Robert Phillips <robertphillips@google.com>
> > > > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > > > Commit-Queue: Adlai Holler <adlai@google.com>
> > >
> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
> > >
> > > Change-Id: I9b58dee285fbdc49ebc8e76df5da0fe224cf9787
> > > No-Presubmit: true
> > > No-Tree-Checks: true
> > > No-Try: true
> > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/318758
> > > Reviewed-by: Adlai Holler <adlai@google.com>
> > > Commit-Queue: Adlai Holler <adlai@google.com>
> >
> > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
> >
> >
> > Change-Id: Id4b10795193a904cd4ed8c36e60e74abe3b6702a
> > Docs-Preview: https://skia.org/?cl=318759
> > Cq-Include-Trybots: luci.skia.skia.primary:Build-Mac10.15.5-Clang-arm64-Debug-iOS_Metal,Build-Mac-Clang-x86_64-Debug-Metal
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/318759
> > Commit-Queue: Adlai Holler <adlai@google.com>
> > Reviewed-by: Adlai Holler <adlai@google.com>
>
> TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
>
> Change-Id: Ib20fe933120d56b72efaec73a0bedec60bc28def
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/319184
> Commit-Queue: Adlai Holler <adlai@google.com>
> Reviewed-by: Adlai Holler <adlai@google.com>
TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
Change-Id: I4f01291f4b3bfbb8fd7dd8cf2bf8415430c3392e
Docs-Preview: https://skia.org/?cl=322437
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/322437
Reviewed-by: Adlai Holler <adlai@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Adlai Holler <adlai@google.com>
Auto-Submit: Adlai Holler <adlai@google.com>
2020-10-06 18:04:35 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/gl/GrGLInterface.h"
|
|
|
|
#include "include/gpu/gl/GrGLTypes.h"
|
2019-03-15 14:58:31 +00:00
|
|
|
|
|
|
|
#include <GL/gl.h>
|
|
|
|
#include <emscripten/html5.h>
|
|
|
|
#endif
|
|
|
|
|
2019-03-05 15:45:40 +00:00
|
|
|
using JSColor = int32_t;
|
2019-09-20 14:08:25 +00:00
|
|
|
using Uint8Array = emscripten::val;
|
2020-11-12 19:34:27 +00:00
|
|
|
using JSArray = emscripten::val;
|
|
|
|
using JSObject = emscripten::val;
|
2019-03-05 15:45:40 +00:00
|
|
|
|
2019-06-21 15:09:19 +00:00
|
|
|
// file signature for SkMultiPictureDocument
|
|
|
|
// TODO(nifong): make public and include from SkMultiPictureDocument.h
|
|
|
|
static constexpr char kMultiMagic[] = "Skia Multi-Picture Doc\n\n";
|
|
|
|
|
2019-03-05 15:45:40 +00:00
|
|
|
struct SimpleImageInfo {
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
SkColorType colorType;
|
|
|
|
SkAlphaType alphaType;
|
|
|
|
};
|
|
|
|
|
|
|
|
SkImageInfo toSkImageInfo(const SimpleImageInfo& sii) {
|
|
|
|
return SkImageInfo::Make(sii.width, sii.height, sii.colorType, sii.alphaType);
|
|
|
|
}
|
|
|
|
|
2020-01-03 15:29:13 +00:00
|
|
|
SimpleImageInfo toSimpleImageInfo(const SkImageInfo& ii) {
|
|
|
|
return (SimpleImageInfo){ii.width(), ii.height(), ii.colorType(), ii.alphaType()};
|
2019-09-20 14:08:25 +00:00
|
|
|
}
|
|
|
|
|
2020-11-16 21:06:21 +00:00
|
|
|
uint32_t MinVersion() { return SkPicturePriv::kMin_Version; }
|
|
|
|
|
2019-03-05 15:45:40 +00:00
|
|
|
class SkpDebugPlayer {
|
|
|
|
public:
|
2019-09-20 14:08:25 +00:00
|
|
|
SkpDebugPlayer() :
|
|
|
|
udm(UrlDataManager(SkString("/data"))){}
|
2019-03-05 15:45:40 +00:00
|
|
|
|
2019-03-06 17:56:54 +00:00
|
|
|
/* loadSkp deserializes a skp file that has been copied into the shared WASM memory.
|
|
|
|
* cptr - a pointer to the data to deserialize.
|
|
|
|
* length - length of the data in bytes.
|
|
|
|
* The caller must allocate the memory with M._malloc where M is the wasm module in javascript
|
|
|
|
* and copy the data into M.buffer at the pointer returned by malloc.
|
|
|
|
*
|
|
|
|
* uintptr_t is used here because emscripten will not allow binding of functions with pointers
|
|
|
|
* to primitive types. We can instead pass a number and cast it to whatever kind of
|
|
|
|
* pointer we're expecting.
|
2020-08-14 13:43:11 +00:00
|
|
|
*
|
|
|
|
* Returns an error string which is populated in the case that the file cannot be read.
|
2019-03-06 17:56:54 +00:00
|
|
|
*/
|
2020-08-14 13:43:11 +00:00
|
|
|
std::string loadSkp(uintptr_t cptr, int length) {
|
2019-06-21 15:09:19 +00:00
|
|
|
const uint8_t* data = reinterpret_cast<const uint8_t*>(cptr);
|
|
|
|
// Both traditional and multi-frame skp files have a magic word
|
|
|
|
SkMemoryStream stream(data, length);
|
|
|
|
SkDebugf("make stream at %p, with %d bytes\n",data, length);
|
2020-11-16 21:06:21 +00:00
|
|
|
const bool isMulti = memcmp(data, kMultiMagic, sizeof(kMultiMagic) - 1) == 0;
|
|
|
|
|
|
|
|
|
2020-08-14 13:43:11 +00:00
|
|
|
if (isMulti) {
|
2019-06-21 15:09:19 +00:00
|
|
|
SkDebugf("Try reading as a multi-frame skp\n");
|
2020-08-14 13:43:11 +00:00
|
|
|
const auto& error = loadMultiFrame(&stream);
|
|
|
|
if (!error.empty()) { return error; }
|
2019-06-21 15:09:19 +00:00
|
|
|
} else {
|
|
|
|
SkDebugf("Try reading as single-frame skp\n");
|
2020-08-14 13:43:11 +00:00
|
|
|
// TODO(nifong): Rely on SkPicture's return errors once it provides some.
|
2019-06-21 15:09:19 +00:00
|
|
|
frames.push_back(loadSingleFrame(&stream));
|
2019-03-06 17:56:54 +00:00
|
|
|
}
|
2020-08-14 13:43:11 +00:00
|
|
|
return "";
|
2019-03-05 15:45:40 +00:00
|
|
|
}
|
|
|
|
|
2019-03-06 17:56:54 +00:00
|
|
|
/* drawTo asks the debug canvas to draw from the beginning of the picture
|
|
|
|
* to the given command and flush the canvas.
|
|
|
|
*/
|
2019-03-05 15:45:40 +00:00
|
|
|
void drawTo(SkSurface* surface, int32_t index) {
|
2019-12-19 17:54:15 +00:00
|
|
|
// Set the command within the frame or layer event being drawn.
|
|
|
|
if (fInspectedLayer >= 0) {
|
|
|
|
fLayerManager->setCommand(fInspectedLayer, fp, index);
|
|
|
|
} else {
|
|
|
|
index = constrainFrameCommand(index);
|
2019-06-21 15:09:19 +00:00
|
|
|
}
|
2019-12-19 17:54:15 +00:00
|
|
|
|
2019-12-12 16:05:10 +00:00
|
|
|
auto* canvas = surface->getCanvas();
|
|
|
|
canvas->clear(SK_ColorTRANSPARENT);
|
2019-12-19 17:54:15 +00:00
|
|
|
if (fInspectedLayer >= 0) {
|
|
|
|
// when it's a layer event we're viewing, we use the layer manager to render it.
|
2020-11-20 18:49:37 +00:00
|
|
|
fLayerManager->drawLayerEventTo(surface, fInspectedLayer, fp);
|
2019-12-19 17:54:15 +00:00
|
|
|
} else {
|
|
|
|
// otherwise, its a frame at the top level.
|
|
|
|
frames[fp]->drawTo(surface->getCanvas(), index);
|
|
|
|
}
|
2020-11-20 18:49:37 +00:00
|
|
|
surface->flush();
|
2019-03-05 15:45:40 +00:00
|
|
|
}
|
|
|
|
|
2019-12-12 16:05:10 +00:00
|
|
|
// Draws to the end of the current frame.
|
|
|
|
void draw(SkSurface* surface) {
|
|
|
|
auto* canvas = surface->getCanvas();
|
|
|
|
canvas->clear(SK_ColorTRANSPARENT);
|
|
|
|
frames[fp]->draw(surface->getCanvas());
|
|
|
|
surface->getCanvas()->flush();
|
|
|
|
}
|
|
|
|
|
2020-12-04 21:47:36 +00:00
|
|
|
// Gets the bounds for the given frame
|
|
|
|
// (or layer update, assuming there is one at that frame for fInspectedLayer)
|
|
|
|
const SkIRect getBoundsForFrame(int32_t frame) {
|
2019-12-19 17:54:15 +00:00
|
|
|
if (fInspectedLayer < 0) {
|
2020-12-04 21:47:36 +00:00
|
|
|
return fBoundsArray[frame];
|
2019-12-19 17:54:15 +00:00
|
|
|
}
|
|
|
|
auto summary = fLayerManager->event(fInspectedLayer, fp);
|
|
|
|
return SkIRect::MakeWH(summary.layerWidth, summary.layerHeight);
|
|
|
|
}
|
|
|
|
|
2020-12-04 21:47:36 +00:00
|
|
|
// Gets the bounds for the current frame
|
|
|
|
const SkIRect getBounds() {
|
|
|
|
return getBoundsForFrame(fp);
|
|
|
|
}
|
|
|
|
|
2019-12-19 17:54:15 +00:00
|
|
|
// returns the debugcanvas of the current frame, or the current draw event when inspecting
|
|
|
|
// a layer.
|
|
|
|
DebugCanvas* visibleCanvas() {
|
|
|
|
if (fInspectedLayer >=0) {
|
|
|
|
return fLayerManager->getEventDebugCanvas(fInspectedLayer, fp);
|
|
|
|
} else {
|
|
|
|
return frames[fp].get();
|
|
|
|
}
|
|
|
|
}
|
2019-03-13 17:31:13 +00:00
|
|
|
|
2019-12-19 17:54:15 +00:00
|
|
|
// The following three operations apply to every debugcanvas because they are overdraw features.
|
2019-12-11 20:24:48 +00:00
|
|
|
// There is only one toggle for them on the app, they are global settings.
|
2019-12-19 17:54:15 +00:00
|
|
|
// However, there's not a simple way to make the debugcanvases pull settings from a central
|
|
|
|
// location so we set it on all of them at once.
|
2019-06-21 15:09:19 +00:00
|
|
|
void setOverdrawVis(bool on) {
|
2019-12-11 20:24:48 +00:00
|
|
|
for (int i=0; i < frames.size(); i++) {
|
|
|
|
frames[i]->setOverdrawViz(on);
|
|
|
|
}
|
2019-12-19 17:54:15 +00:00
|
|
|
fLayerManager->setOverdrawViz(on);
|
2019-06-21 15:09:19 +00:00
|
|
|
}
|
2019-03-28 17:08:51 +00:00
|
|
|
void setGpuOpBounds(bool on) {
|
2019-12-11 20:24:48 +00:00
|
|
|
for (int i=0; i < frames.size(); i++) {
|
|
|
|
frames[i]->setDrawGpuOpBounds(on);
|
|
|
|
}
|
2019-12-19 17:54:15 +00:00
|
|
|
fLayerManager->setDrawGpuOpBounds(on);
|
2019-03-28 17:08:51 +00:00
|
|
|
}
|
2019-03-13 17:31:13 +00:00
|
|
|
void setClipVizColor(JSColor color) {
|
2019-12-11 20:24:48 +00:00
|
|
|
for (int i=0; i < frames.size(); i++) {
|
|
|
|
frames[i]->setClipVizColor(SkColor(color));
|
|
|
|
}
|
2019-12-19 17:54:15 +00:00
|
|
|
fLayerManager->setClipVizColor(SkColor(color));
|
2019-06-21 15:09:19 +00:00
|
|
|
}
|
2020-01-10 19:38:00 +00:00
|
|
|
void setAndroidClipViz(bool on) {
|
|
|
|
for (int i=0; i < frames.size(); i++) {
|
|
|
|
frames[i]->setAndroidClipViz(on);
|
|
|
|
}
|
|
|
|
// doesn't matter in layers
|
|
|
|
}
|
2020-08-20 16:33:46 +00:00
|
|
|
void setOriginVisible(bool on) {
|
|
|
|
for (int i=0; i < frames.size(); i++) {
|
|
|
|
frames[i]->setOriginVisible(on);
|
|
|
|
}
|
|
|
|
}
|
2019-12-11 20:24:48 +00:00
|
|
|
// The two operations below only apply to the current frame, because they concern the command
|
|
|
|
// list, which is unique to each frame.
|
2019-06-21 15:09:19 +00:00
|
|
|
void deleteCommand(int index) {
|
2019-12-19 17:54:15 +00:00
|
|
|
visibleCanvas()->deleteDrawCommandAt(index);
|
2019-03-13 17:31:13 +00:00
|
|
|
}
|
|
|
|
void setCommandVisibility(int index, bool visible) {
|
2019-12-19 17:54:15 +00:00
|
|
|
visibleCanvas()->toggleCommand(index, visible);
|
2019-06-21 15:09:19 +00:00
|
|
|
}
|
|
|
|
int getSize() const {
|
2019-12-19 17:54:15 +00:00
|
|
|
if (fInspectedLayer >=0) {
|
|
|
|
return fLayerManager->event(fInspectedLayer, fp).commandCount;
|
|
|
|
} else {
|
|
|
|
return frames[fp]->getSize();
|
|
|
|
}
|
2019-06-21 15:09:19 +00:00
|
|
|
}
|
|
|
|
int getFrameCount() const {
|
|
|
|
return frames.size();
|
2019-03-13 17:31:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return the command list in JSON representation as a string
|
|
|
|
std::string jsonCommandList(sk_sp<SkSurface> surface) {
|
|
|
|
SkDynamicMemoryWStream stream;
|
|
|
|
SkJSONWriter writer(&stream, SkJSONWriter::Mode::kFast);
|
|
|
|
writer.beginObject(); // root
|
2019-12-19 17:54:15 +00:00
|
|
|
visibleCanvas()->toJSON(writer, udm, surface->getCanvas());
|
2019-03-28 17:08:51 +00:00
|
|
|
writer.endObject(); // root
|
|
|
|
writer.flush();
|
|
|
|
auto skdata = stream.detachAsData();
|
|
|
|
// Convert skdata to string_view, which accepts a length
|
|
|
|
std::string_view data_view(reinterpret_cast<const char*>(skdata->data()), skdata->size());
|
|
|
|
// and string_view to string, which emscripten understands.
|
|
|
|
return std::string(data_view);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Gets the clip and matrix of the last command drawn
|
|
|
|
std::string lastCommandInfo() {
|
2020-12-03 18:04:54 +00:00
|
|
|
SkM44 vm = visibleCanvas()->getCurrentMatrix();
|
2019-12-19 17:54:15 +00:00
|
|
|
SkIRect clip = visibleCanvas()->getCurrentClip();
|
2019-03-28 17:08:51 +00:00
|
|
|
|
|
|
|
SkDynamicMemoryWStream stream;
|
|
|
|
SkJSONWriter writer(&stream, SkJSONWriter::Mode::kFast);
|
|
|
|
writer.beginObject(); // root
|
|
|
|
|
|
|
|
writer.appendName("ViewMatrix");
|
2020-12-03 18:04:54 +00:00
|
|
|
DrawCommand::MakeJsonMatrix44(writer, vm);
|
2019-03-28 17:08:51 +00:00
|
|
|
writer.appendName("ClipRect");
|
|
|
|
DrawCommand::MakeJsonIRect(writer, clip);
|
2019-03-13 17:31:13 +00:00
|
|
|
|
|
|
|
writer.endObject(); // root
|
|
|
|
writer.flush();
|
|
|
|
auto skdata = stream.detachAsData();
|
|
|
|
// Convert skdata to string_view, which accepts a length
|
|
|
|
std::string_view data_view(reinterpret_cast<const char*>(skdata->data()), skdata->size());
|
|
|
|
// and string_view to string, which emscripten understands.
|
|
|
|
return std::string(data_view);
|
|
|
|
}
|
|
|
|
|
2019-06-21 15:09:19 +00:00
|
|
|
void changeFrame(int index) {
|
|
|
|
fp = index;
|
|
|
|
}
|
|
|
|
|
2019-09-20 14:08:25 +00:00
|
|
|
// Return the png file at the requested index in
|
|
|
|
// the skp file's vector of shared images. this is the set of images referred to by the
|
|
|
|
// filenames like "\\1" in DrawImage commands.
|
|
|
|
// Return type is the PNG data as a base64 encoded string with prepended URI.
|
|
|
|
std::string getImageResource(int index) {
|
|
|
|
sk_sp<SkData> pngData = fImages[index]->encodeToData();
|
|
|
|
size_t len = SkBase64::Encode(pngData->data(), pngData->size(), nullptr);
|
|
|
|
SkString dst;
|
|
|
|
dst.resize(len);
|
|
|
|
SkBase64::Encode(pngData->data(), pngData->size(), dst.writable_str());
|
|
|
|
dst.prepend("data:image/png;base64,");
|
|
|
|
return std::string(dst.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
int getImageCount() {
|
|
|
|
return fImages.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the image info of one of the resource images.
|
|
|
|
SimpleImageInfo getImageInfo(int index) {
|
2020-01-03 15:29:13 +00:00
|
|
|
return toSimpleImageInfo(fImages[index]->imageInfo());
|
2019-09-20 14:08:25 +00:00
|
|
|
}
|
|
|
|
|
2020-11-12 19:34:27 +00:00
|
|
|
// return data on which commands each image is used in.
|
2020-11-24 16:23:09 +00:00
|
|
|
// (frame, -1) returns info for the given frame,
|
|
|
|
// (frame, nodeid) return info for a layer update
|
2020-11-12 19:34:27 +00:00
|
|
|
// { imageid: [commandid, commandid, ...], ... }
|
2020-11-24 16:23:09 +00:00
|
|
|
JSObject imageUseInfo(int framenumber, int nodeid) {
|
2020-11-12 19:34:27 +00:00
|
|
|
JSObject result = emscripten::val::object();
|
2020-11-24 16:23:09 +00:00
|
|
|
DebugCanvas* debugCanvas = frames[framenumber].get();
|
|
|
|
if (nodeid >= 0) {
|
|
|
|
debugCanvas = fLayerManager->getEventDebugCanvas(nodeid, framenumber);
|
|
|
|
}
|
|
|
|
const auto& map = debugCanvas->getImageIdToCommandMap(udm);
|
|
|
|
for (auto it = map.begin(); it != map.end(); ++it) {
|
|
|
|
JSArray list = emscripten::val::array();
|
2020-11-12 19:34:27 +00:00
|
|
|
for (const int commandId : it->second) {
|
|
|
|
list.call<void>("push", commandId);
|
|
|
|
}
|
|
|
|
result.set(std::to_string(it->first), list);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return information on every layer (offscreeen buffer) that is available for drawing at
|
|
|
|
// the current frame.
|
|
|
|
JSArray getLayerSummariesJs() {
|
|
|
|
JSArray result = emscripten::val::array();
|
|
|
|
for (auto summary : fLayerManager->summarizeLayers(fp)) {
|
|
|
|
result.call<void>("push", summary);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-11-24 16:23:09 +00:00
|
|
|
JSArray getLayerKeys() {
|
|
|
|
JSArray result = emscripten::val::array();
|
|
|
|
for (auto key : fLayerManager->getKeys()) {
|
|
|
|
JSObject item = emscripten::val::object();
|
|
|
|
item.set("frame", key.frame);
|
|
|
|
item.set("nodeId", key.nodeId);
|
|
|
|
result.call<void>("push", item);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-12-19 17:54:15 +00:00
|
|
|
// When set to a valid layer index, causes this class to playback the layer draw event at nodeId
|
|
|
|
// on frame fp. No validation of nodeId or fp is performed, this must be valid values obtained
|
|
|
|
// from either fLayerManager.listNodesForFrame or fLayerManager.summarizeEvents
|
|
|
|
// Set to -1 to return to viewing the top level animation
|
|
|
|
void setInspectedLayer(int nodeId) {
|
|
|
|
fInspectedLayer = nodeId;
|
|
|
|
}
|
|
|
|
|
2020-11-04 17:10:11 +00:00
|
|
|
// Finds a command that left the given pixel in it's current state.
|
|
|
|
// Note that this method may fail to find the absolute last command that leaves a pixel
|
|
|
|
// the given color, but there is probably only one candidate in most cases, and the log(n)
|
|
|
|
// makes it worth it.
|
|
|
|
int findCommandByPixel(SkSurface* surface, int x, int y, int commandIndex) {
|
|
|
|
// What color is the pixel now?
|
|
|
|
SkColor finalColor = evaluateCommandColor(surface, commandIndex, x, y);
|
|
|
|
|
|
|
|
int lowerBound = 0;
|
|
|
|
int upperBound = commandIndex;
|
|
|
|
|
|
|
|
while (upperBound - lowerBound > 1) {
|
|
|
|
int command = (upperBound - lowerBound) / 2 + lowerBound;
|
|
|
|
auto c = evaluateCommandColor(surface, command, x, y);
|
|
|
|
if (c == finalColor) {
|
|
|
|
upperBound = command;
|
|
|
|
} else {
|
|
|
|
lowerBound = command;
|
|
|
|
}
|
|
|
|
}
|
2020-11-12 19:34:27 +00:00
|
|
|
// clean up after side effects
|
|
|
|
drawTo(surface, commandIndex);
|
2020-11-04 17:10:11 +00:00
|
|
|
return upperBound;
|
|
|
|
}
|
|
|
|
|
2019-03-05 15:45:40 +00:00
|
|
|
private:
|
2019-06-21 15:09:19 +00:00
|
|
|
|
2020-11-12 19:34:27 +00:00
|
|
|
// Helper for findCommandByPixel.
|
|
|
|
// Has side effect of flushing to surface.
|
|
|
|
// TODO(nifong) eliminate side effect.
|
2020-11-04 17:10:11 +00:00
|
|
|
SkColor evaluateCommandColor(SkSurface* surface, int command, int x, int y) {
|
|
|
|
drawTo(surface, command);
|
|
|
|
|
|
|
|
SkColor c;
|
|
|
|
SkImageInfo info = SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kOpaque_SkAlphaType);
|
|
|
|
SkPixmap pixmap(info, &c, 4);
|
|
|
|
surface->readPixels(pixmap, x, y);
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2019-06-21 15:09:19 +00:00
|
|
|
// Loads a single frame (traditional) skp file from the provided data stream and returns
|
|
|
|
// a newly allocated DebugCanvas initialized with the SkPicture that was in the file.
|
|
|
|
std::unique_ptr<DebugCanvas> loadSingleFrame(SkMemoryStream* stream) {
|
|
|
|
// note overloaded = operator that actually does a move
|
|
|
|
sk_sp<SkPicture> picture = SkPicture::MakeFromStream(stream);
|
|
|
|
if (!picture) {
|
|
|
|
SkDebugf("Unable to deserialze frame.\n");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
SkDebugf("Parsed SKP file.\n");
|
|
|
|
// Make debug canvas using bounds from SkPicture
|
2020-12-04 21:47:36 +00:00
|
|
|
fBoundsArray.push_back(picture->cullRect().roundOut());
|
|
|
|
std::unique_ptr<DebugCanvas> debugCanvas = std::make_unique<DebugCanvas>(fBoundsArray.back());
|
2019-06-21 15:09:19 +00:00
|
|
|
|
|
|
|
// Only draw picture to the debug canvas once.
|
2019-12-12 16:05:10 +00:00
|
|
|
debugCanvas->drawPicture(picture);
|
|
|
|
return debugCanvas;
|
2019-06-21 15:09:19 +00:00
|
|
|
}
|
|
|
|
|
2020-08-14 13:43:11 +00:00
|
|
|
std::string loadMultiFrame(SkMemoryStream* stream) {
|
2019-12-12 16:05:10 +00:00
|
|
|
// Attempt to deserialize with an image sharing serial proc.
|
|
|
|
auto deserialContext = std::make_unique<SkSharingDeserialContext>();
|
|
|
|
SkDeserialProcs procs;
|
|
|
|
procs.fImageProc = SkSharingDeserialContext::deserializeImage;
|
|
|
|
procs.fImageCtx = deserialContext.get();
|
|
|
|
|
|
|
|
int page_count = SkMultiPictureDocumentReadPageCount(stream);
|
|
|
|
if (!page_count) {
|
2020-08-14 13:43:11 +00:00
|
|
|
// MSKP's have a version separate from the SKP subpictures they contain.
|
|
|
|
return "Not a MultiPictureDocument, MultiPictureDocument file version too old, or MultiPictureDocument contained 0 frames.";
|
2019-12-12 16:05:10 +00:00
|
|
|
}
|
|
|
|
SkDebugf("Expecting %d frames\n", page_count);
|
2019-06-21 15:09:19 +00:00
|
|
|
|
2019-12-12 16:05:10 +00:00
|
|
|
std::vector<SkDocumentPage> pages(page_count);
|
|
|
|
if (!SkMultiPictureDocumentRead(stream, pages.data(), page_count, &procs)) {
|
2020-08-14 13:43:11 +00:00
|
|
|
return "Reading frames from MultiPictureDocument failed";
|
2019-12-12 16:05:10 +00:00
|
|
|
}
|
2019-06-21 15:09:19 +00:00
|
|
|
|
2019-12-12 16:05:10 +00:00
|
|
|
fLayerManager = std::make_unique<DebugLayerManager>();
|
2019-06-21 15:09:19 +00:00
|
|
|
|
2019-12-12 16:05:10 +00:00
|
|
|
int i = 0;
|
|
|
|
for (const auto& page : pages) {
|
|
|
|
// Make debug canvas using bounds from SkPicture
|
2020-12-04 21:47:36 +00:00
|
|
|
fBoundsArray.push_back(page.fPicture->cullRect().roundOut());
|
|
|
|
std::unique_ptr<DebugCanvas> debugCanvas = std::make_unique<DebugCanvas>(fBoundsArray.back());
|
2019-12-12 16:05:10 +00:00
|
|
|
debugCanvas->setLayerManagerAndFrame(fLayerManager.get(), i);
|
2019-06-21 15:09:19 +00:00
|
|
|
|
2019-12-12 16:05:10 +00:00
|
|
|
// Only draw picture to the debug canvas once.
|
|
|
|
debugCanvas->drawPicture(page.fPicture);
|
|
|
|
|
|
|
|
if (debugCanvas->getSize() <=0 ){
|
|
|
|
SkDebugf("Skipped corrupted frame, had %d commands \n", debugCanvas->getSize());
|
|
|
|
continue;
|
2019-06-21 15:09:19 +00:00
|
|
|
}
|
2019-12-12 16:05:10 +00:00
|
|
|
// If you don't set these, they're undefined.
|
|
|
|
debugCanvas->setOverdrawViz(false);
|
|
|
|
debugCanvas->setDrawGpuOpBounds(false);
|
|
|
|
debugCanvas->setClipVizColor(SK_ColorTRANSPARENT);
|
2020-01-10 19:38:00 +00:00
|
|
|
debugCanvas->setAndroidClipViz(false);
|
2019-12-12 16:05:10 +00:00
|
|
|
frames.push_back(std::move(debugCanvas));
|
2019-12-19 17:54:15 +00:00
|
|
|
i++;
|
2019-12-12 16:05:10 +00:00
|
|
|
}
|
|
|
|
fImages = deserialContext->fImages;
|
2020-01-03 15:29:13 +00:00
|
|
|
|
|
|
|
udm.indexImages(fImages);
|
2020-08-14 13:43:11 +00:00
|
|
|
return "";
|
2019-06-21 15:09:19 +00:00
|
|
|
}
|
|
|
|
|
2019-12-19 17:54:15 +00:00
|
|
|
// constrains the draw command index to the frame's command list length.
|
|
|
|
int constrainFrameCommand(int index) {
|
|
|
|
int cmdlen = frames[fp]->getSize();
|
|
|
|
if (index >= cmdlen) {
|
|
|
|
return cmdlen-1;
|
|
|
|
}
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2019-06-21 15:09:19 +00:00
|
|
|
// A vector of DebugCanvas, each one initialized to a frame of the animation.
|
|
|
|
std::vector<std::unique_ptr<DebugCanvas>> frames;
|
|
|
|
// The index of the current frame (into the vector above)
|
|
|
|
int fp = 0;
|
2020-12-04 21:47:36 +00:00
|
|
|
// The width and height of every frame.
|
|
|
|
// frame sizes are known to change in Android Skia RenderEngine because it interleves pictures from different applications.
|
|
|
|
std::vector<SkIRect> fBoundsArray;
|
2019-09-20 14:08:25 +00:00
|
|
|
// image resources from a loaded file
|
|
|
|
std::vector<sk_sp<SkImage>> fImages;
|
|
|
|
|
|
|
|
// The URLDataManager here is a cache that accepts encoded data (pngs) and puts
|
|
|
|
// numbers on them. We have our own collection of images (fImages) that was populated by the
|
2020-01-03 15:29:13 +00:00
|
|
|
// SkSharingDeserialContext when mskp files are loaded which it can use for IDing images
|
|
|
|
// without having to serialize them.
|
2019-09-20 14:08:25 +00:00
|
|
|
UrlDataManager udm;
|
|
|
|
|
2019-12-12 16:05:10 +00:00
|
|
|
// A structure holding the picture information needed to draw any layers used in an mskp file
|
|
|
|
// individual frames hold a pointer to it, store draw events, and request images from it.
|
|
|
|
// it is stateful and is set to the current frame at all times.
|
|
|
|
std::unique_ptr<DebugLayerManager> fLayerManager;
|
2019-12-19 17:54:15 +00:00
|
|
|
|
|
|
|
// The node id of a layer being inspected, if any.
|
|
|
|
// -1 means we are viewing the top level animation, not a layer.
|
|
|
|
// the exact draw event being inspected depends also on the selected frame `fp`.
|
|
|
|
int fInspectedLayer = -1;
|
2019-03-05 15:45:40 +00:00
|
|
|
};
|
|
|
|
|
2020-03-19 19:54:28 +00:00
|
|
|
#ifdef SK_GL
|
2020-10-15 15:13:24 +00:00
|
|
|
sk_sp<GrDirectContext> MakeGrContext(EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context)
|
2019-03-15 14:58:31 +00:00
|
|
|
{
|
|
|
|
EMSCRIPTEN_RESULT r = emscripten_webgl_make_context_current(context);
|
|
|
|
if (r < 0) {
|
|
|
|
SkDebugf("failed to make webgl context current %d\n", r);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2020-10-15 15:13:24 +00:00
|
|
|
// setup interface
|
2019-03-15 14:58:31 +00:00
|
|
|
auto interface = GrGLMakeNativeInterface();
|
2020-09-02 19:40:37 +00:00
|
|
|
if (!interface) {
|
|
|
|
SkDebugf("failed to make GrGLMakeNativeInterface\n");
|
|
|
|
return nullptr;
|
|
|
|
}
|
2020-10-15 15:13:24 +00:00
|
|
|
// setup context
|
|
|
|
return GrDirectContext::MakeGL(interface);
|
2019-03-15 14:58:31 +00:00
|
|
|
}
|
|
|
|
|
2020-10-15 15:13:24 +00:00
|
|
|
sk_sp<SkSurface> MakeOnScreenGLSurface(sk_sp<GrDirectContext> dContext, int width, int height) {
|
2019-03-15 14:58:31 +00:00
|
|
|
glClearColor(0, 0, 0, 0);
|
|
|
|
glClearStencil(0);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
|
|
|
|
|
|
|
|
|
|
|
// Wrap the frame buffer object attached to the screen in a Skia render
|
|
|
|
// target so Skia can render to it
|
|
|
|
GrGLint buffer;
|
|
|
|
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &buffer);
|
|
|
|
GrGLFramebufferInfo info;
|
|
|
|
info.fFBOID = (GrGLuint) buffer;
|
|
|
|
SkColorType colorType;
|
|
|
|
|
|
|
|
info.fFormat = GL_RGBA8;
|
|
|
|
colorType = kRGBA_8888_SkColorType;
|
|
|
|
|
|
|
|
GrBackendRenderTarget target(width, height, 0, 8, info);
|
|
|
|
|
2020-10-15 15:13:24 +00:00
|
|
|
sk_sp<SkSurface> surface(SkSurface::MakeFromBackendRenderTarget(dContext.get(), target,
|
2019-03-15 14:58:31 +00:00
|
|
|
kBottomLeft_GrSurfaceOrigin,
|
|
|
|
colorType, nullptr, nullptr));
|
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
|
2020-10-15 15:13:24 +00:00
|
|
|
sk_sp<SkSurface> MakeRenderTarget(sk_sp<GrDirectContext> dContext, int width, int height) {
|
2019-03-15 14:58:31 +00:00
|
|
|
SkImageInfo info = SkImageInfo::MakeN32(width, height, SkAlphaType::kPremul_SkAlphaType);
|
|
|
|
|
2020-10-15 15:13:24 +00:00
|
|
|
sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(dContext.get(),
|
2019-03-15 14:58:31 +00:00
|
|
|
SkBudgeted::kYes,
|
|
|
|
info, 0,
|
|
|
|
kBottomLeft_GrSurfaceOrigin,
|
|
|
|
nullptr, true));
|
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
|
2020-10-15 15:13:24 +00:00
|
|
|
sk_sp<SkSurface> MakeRenderTarget(sk_sp<GrDirectContext> dContext, SimpleImageInfo sii) {
|
|
|
|
sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(dContext.get(),
|
2019-03-15 14:58:31 +00:00
|
|
|
SkBudgeted::kYes,
|
|
|
|
toSkImageInfo(sii), 0,
|
|
|
|
kBottomLeft_GrSurfaceOrigin,
|
|
|
|
nullptr, true));
|
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-03-05 15:45:40 +00:00
|
|
|
using namespace emscripten;
|
|
|
|
EMSCRIPTEN_BINDINGS(my_module) {
|
|
|
|
|
2020-11-16 21:06:21 +00:00
|
|
|
function("MinVersion", &MinVersion);
|
|
|
|
|
2019-03-05 15:45:40 +00:00
|
|
|
// The main class that the JavaScript in index.html uses
|
|
|
|
class_<SkpDebugPlayer>("SkpDebugPlayer")
|
|
|
|
.constructor<>()
|
2019-12-19 17:54:15 +00:00
|
|
|
.function("changeFrame", &SkpDebugPlayer::changeFrame)
|
|
|
|
.function("deleteCommand", &SkpDebugPlayer::deleteCommand)
|
2019-12-12 16:05:10 +00:00
|
|
|
.function("draw", &SkpDebugPlayer::draw, allow_raw_pointers())
|
2019-12-19 17:54:15 +00:00
|
|
|
.function("drawTo", &SkpDebugPlayer::drawTo, allow_raw_pointers())
|
2020-11-04 17:10:11 +00:00
|
|
|
.function("findCommandByPixel", &SkpDebugPlayer::findCommandByPixel, allow_raw_pointers())
|
2019-03-13 17:31:13 +00:00
|
|
|
.function("getBounds", &SkpDebugPlayer::getBounds)
|
2020-12-04 21:47:36 +00:00
|
|
|
.function("getBoundsForFrame", &SkpDebugPlayer::getBoundsForFrame)
|
2019-09-20 14:08:25 +00:00
|
|
|
.function("getFrameCount", &SkpDebugPlayer::getFrameCount)
|
|
|
|
.function("getImageResource", &SkpDebugPlayer::getImageResource)
|
|
|
|
.function("getImageCount", &SkpDebugPlayer::getImageCount)
|
2019-12-12 16:05:10 +00:00
|
|
|
.function("getImageInfo", &SkpDebugPlayer::getImageInfo)
|
2020-11-24 16:23:09 +00:00
|
|
|
.function("getLayerKeys", &SkpDebugPlayer::getLayerKeys)
|
2020-11-12 19:34:27 +00:00
|
|
|
.function("getLayerSummariesJs", &SkpDebugPlayer::getLayerSummariesJs)
|
2019-12-19 17:54:15 +00:00
|
|
|
.function("getSize", &SkpDebugPlayer::getSize)
|
2020-11-24 16:23:09 +00:00
|
|
|
.function("imageUseInfo", &SkpDebugPlayer::imageUseInfo)
|
|
|
|
.function("imageUseInfoForFrameJs", optional_override([](SkpDebugPlayer& self, const int frame)->JSObject {
|
|
|
|
// -1 as a node id is used throughout the application to mean no layer inspected.
|
|
|
|
return self.imageUseInfo(frame, -1);
|
|
|
|
}))
|
2019-12-19 17:54:15 +00:00
|
|
|
.function("jsonCommandList", &SkpDebugPlayer::jsonCommandList, allow_raw_pointers())
|
|
|
|
.function("lastCommandInfo", &SkpDebugPlayer::lastCommandInfo)
|
|
|
|
.function("loadSkp", &SkpDebugPlayer::loadSkp, allow_raw_pointers())
|
|
|
|
.function("setClipVizColor", &SkpDebugPlayer::setClipVizColor)
|
|
|
|
.function("setCommandVisibility", &SkpDebugPlayer::setCommandVisibility)
|
|
|
|
.function("setGpuOpBounds", &SkpDebugPlayer::setGpuOpBounds)
|
|
|
|
.function("setInspectedLayer", &SkpDebugPlayer::setInspectedLayer)
|
2020-08-20 16:33:46 +00:00
|
|
|
.function("setOriginVisible", &SkpDebugPlayer::setOriginVisible)
|
2020-01-10 19:38:00 +00:00
|
|
|
.function("setOverdrawVis", &SkpDebugPlayer::setOverdrawVis)
|
|
|
|
.function("setAndroidClipViz", &SkpDebugPlayer::setAndroidClipViz);
|
2019-03-13 17:31:13 +00:00
|
|
|
|
|
|
|
// Structs used as arguments or returns to the functions above
|
|
|
|
value_object<SkIRect>("SkIRect")
|
|
|
|
.field("fLeft", &SkIRect::fLeft)
|
|
|
|
.field("fTop", &SkIRect::fTop)
|
|
|
|
.field("fRight", &SkIRect::fRight)
|
|
|
|
.field("fBottom", &SkIRect::fBottom);
|
2019-12-12 16:05:10 +00:00
|
|
|
// emscripten provided the following convenience function for binding vector<T>
|
|
|
|
// https://emscripten.org/docs/api_reference/bind.h.html#_CPPv415register_vectorPKc
|
2020-01-29 20:06:22 +00:00
|
|
|
register_vector<DebugLayerManager::LayerSummary>("VectorLayerSummary");
|
2020-11-12 19:34:27 +00:00
|
|
|
value_object<DebugLayerManager::LayerSummary>("LayerSummary")
|
2020-01-29 20:06:22 +00:00
|
|
|
.field("nodeId", &DebugLayerManager::LayerSummary::nodeId)
|
|
|
|
.field("frameOfLastUpdate", &DebugLayerManager::LayerSummary::frameOfLastUpdate)
|
|
|
|
.field("fullRedraw", &DebugLayerManager::LayerSummary::fullRedraw)
|
|
|
|
.field("layerWidth", &DebugLayerManager::LayerSummary::layerWidth)
|
|
|
|
.field("layerHeight", &DebugLayerManager::LayerSummary::layerHeight);
|
2019-03-05 15:45:40 +00:00
|
|
|
|
|
|
|
// Symbols needed by cpu.js to perform surface creation and flushing.
|
|
|
|
enum_<SkColorType>("ColorType")
|
|
|
|
.value("RGBA_8888", SkColorType::kRGBA_8888_SkColorType);
|
|
|
|
enum_<SkAlphaType>("AlphaType")
|
2019-03-28 17:08:51 +00:00
|
|
|
.value("Opaque", SkAlphaType::kOpaque_SkAlphaType)
|
|
|
|
.value("Premul", SkAlphaType::kPremul_SkAlphaType)
|
|
|
|
.value("Unpremul", SkAlphaType::kUnpremul_SkAlphaType);
|
2019-03-05 15:45:40 +00:00
|
|
|
value_object<SimpleImageInfo>("SkImageInfo")
|
|
|
|
.field("width", &SimpleImageInfo::width)
|
|
|
|
.field("height", &SimpleImageInfo::height)
|
|
|
|
.field("colorType", &SimpleImageInfo::colorType)
|
2020-01-03 15:29:13 +00:00
|
|
|
.field("alphaType", &SimpleImageInfo::alphaType);
|
2019-03-05 15:45:40 +00:00
|
|
|
constant("TRANSPARENT", (JSColor) SK_ColorTRANSPARENT);
|
|
|
|
function("_getRasterDirectSurface", optional_override([](const SimpleImageInfo ii,
|
|
|
|
uintptr_t /* uint8_t* */ pPtr,
|
|
|
|
size_t rowBytes)->sk_sp<SkSurface> {
|
|
|
|
uint8_t* pixels = reinterpret_cast<uint8_t*>(pPtr);
|
|
|
|
SkImageInfo imageInfo = toSkImageInfo(ii);
|
2019-03-28 17:08:51 +00:00
|
|
|
SkDebugf("Made raster direct surface.\n");
|
2019-03-05 15:45:40 +00:00
|
|
|
return SkSurface::MakeRasterDirect(imageInfo, pixels, rowBytes, nullptr);
|
|
|
|
}), allow_raw_pointers());
|
|
|
|
class_<SkSurface>("SkSurface")
|
|
|
|
.smart_ptr<sk_sp<SkSurface>>("sk_sp<SkSurface>")
|
|
|
|
.function("width", &SkSurface::width)
|
|
|
|
.function("height", &SkSurface::height)
|
2020-10-06 18:54:58 +00:00
|
|
|
.function("_flush", optional_override([](SkSurface& self) {
|
|
|
|
self.flushAndSubmit(false);
|
|
|
|
}))
|
2020-11-12 19:34:27 +00:00
|
|
|
.function("clear", optional_override([](SkSurface& self, JSColor color)->void {
|
|
|
|
self.getCanvas()->clear(SkColor(color));
|
|
|
|
}))
|
2019-03-05 15:45:40 +00:00
|
|
|
.function("getCanvas", &SkSurface::getCanvas, allow_raw_pointers());
|
2020-11-12 19:34:27 +00:00
|
|
|
// TODO(nifong): remove
|
2019-03-05 15:45:40 +00:00
|
|
|
class_<SkCanvas>("SkCanvas")
|
|
|
|
.function("clear", optional_override([](SkCanvas& self, JSColor color)->void {
|
|
|
|
// JS side gives us a signed int instead of an unsigned int for color
|
|
|
|
// Add a optional_override to change it out.
|
|
|
|
self.clear(SkColor(color));
|
|
|
|
}));
|
2019-03-15 14:58:31 +00:00
|
|
|
|
2020-03-19 19:54:28 +00:00
|
|
|
#ifdef SK_GL
|
2020-10-15 15:13:24 +00:00
|
|
|
class_<GrDirectContext>("GrDirectContext")
|
|
|
|
.smart_ptr<sk_sp<GrDirectContext>>("sk_sp<GrDirectContext>");
|
2019-03-15 14:58:31 +00:00
|
|
|
function("currentContext", &emscripten_webgl_get_current_context);
|
|
|
|
function("setCurrentContext", &emscripten_webgl_make_context_current);
|
|
|
|
function("MakeGrContext", &MakeGrContext);
|
|
|
|
function("MakeOnScreenGLSurface", &MakeOnScreenGLSurface);
|
|
|
|
function("MakeRenderTarget", select_overload<sk_sp<SkSurface>(
|
2020-10-15 15:13:24 +00:00
|
|
|
sk_sp<GrDirectContext>, int, int)>(&MakeRenderTarget));
|
2019-03-15 14:58:31 +00:00
|
|
|
function("MakeRenderTarget", select_overload<sk_sp<SkSurface>(
|
2020-10-15 15:13:24 +00:00
|
|
|
sk_sp<GrDirectContext>, SimpleImageInfo)>(&MakeRenderTarget));
|
2019-03-15 14:58:31 +00:00
|
|
|
constant("gpu", true);
|
|
|
|
#endif
|
2019-03-05 15:45:40 +00:00
|
|
|
}
|