experimental/fiddle: update to work again
NOTRY=true Review URL: https://codereview.chromium.org/1834993003
This commit is contained in:
parent
b0ac1af7fa
commit
d096459b2b
@ -20,11 +20,9 @@ void draw(SkCanvas* canvas) {
|
|||||||
SkMatrix matrix;
|
SkMatrix matrix;
|
||||||
matrix.setScale(0.75f, 0.75f);
|
matrix.setScale(0.75f, 0.75f);
|
||||||
matrix.preRotate(30.0f);
|
matrix.preRotate(30.0f);
|
||||||
SkAutoTUnref<SkShader> shader(
|
SkPaint paint;
|
||||||
image->newShader(SkShader::kRepeat_TileMode,
|
paint.setShader(image->makeShader(SkShader::kRepeat_TileMode,
|
||||||
SkShader::kRepeat_TileMode,
|
SkShader::kRepeat_TileMode,
|
||||||
&matrix));
|
&matrix));
|
||||||
SkPaint paint;
|
|
||||||
paint.setShader(shader);
|
|
||||||
canvas->drawPaint(paint);
|
canvas->drawPaint(paint);
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,8 @@ static void encode_to_base64(const void* data, size_t size, FILE* out) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dump_output(SkData* data, const char* name, bool last = true) {
|
static void dump_output(const sk_sp<SkData>& data,
|
||||||
|
const char* name, bool last = true) {
|
||||||
if (data) {
|
if (data) {
|
||||||
printf("\t\"%s\": \"", name);
|
printf("\t\"%s\": \"", name);
|
||||||
encode_to_base64(data->data(), data->size(), stdout);
|
encode_to_base64(data->data(), data->size(), stdout);
|
||||||
@ -56,8 +57,8 @@ static void dump_output(SkData* data, const char* name, bool last = true) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkData* encode_snapshot(SkSurface* surface) {
|
static SkData* encode_snapshot(const sk_sp<SkSurface>& surface) {
|
||||||
SkAutoTUnref<SkImage> img(surface->newImageSnapshot());
|
sk_sp<SkImage> img(surface->newImageSnapshot());
|
||||||
return img ? img->encode() : nullptr;
|
return img ? img->encode() : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +73,7 @@ static OSMesaContext create_osmesa_context() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static GrContext* create_mesa_grcontext() {
|
static GrContext* create_mesa_grcontext() {
|
||||||
SkAutoTUnref<const GrGLInterface> mesa(GrGLCreateMesaInterface());
|
sk_sp<const GrGLInterface> mesa(GrGLCreateMesaInterface());
|
||||||
intptr_t backend = reinterpret_cast<intptr_t>(mesa.get());
|
intptr_t backend = reinterpret_cast<intptr_t>(mesa.get());
|
||||||
return backend ? GrContext::Create(kOpenGL_GrBackend, backend) : nullptr;
|
return backend ? GrContext::Create(kOpenGL_GrBackend, backend) : nullptr;
|
||||||
}
|
}
|
||||||
@ -82,12 +83,12 @@ int main() {
|
|||||||
const DrawOptions options = GetDrawOptions();
|
const DrawOptions options = GetDrawOptions();
|
||||||
fprintf(stderr, "%s\n", options.source);
|
fprintf(stderr, "%s\n", options.source);
|
||||||
if (options.source) {
|
if (options.source) {
|
||||||
SkAutoTUnref<SkData> data(SkData::NewFromFileName(options.source));
|
sk_sp<SkData> data(SkData::NewFromFileName(options.source));
|
||||||
if (!data) {
|
if (!data) {
|
||||||
perror(options.source);
|
perror(options.source);
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
image = SkImage::NewFromEncoded(data);
|
image = SkImage::NewFromEncoded(data.get());
|
||||||
if (!image) {
|
if (!image) {
|
||||||
perror("Unable to decode the source image.");
|
perror("Unable to decode the source image.");
|
||||||
return 1;
|
return 1;
|
||||||
@ -96,24 +97,23 @@ int main() {
|
|||||||
&source, SkImage::kRO_LegacyBitmapMode));
|
&source, SkImage::kRO_LegacyBitmapMode));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SkAutoTUnref<SkData> rasterData, gpuData, pdfData, skpData;
|
sk_sp<SkData> rasterData, gpuData, pdfData, skpData;
|
||||||
if (options.raster) {
|
if (options.raster) {
|
||||||
SkAutoTUnref<SkSurface> rasterSurface(
|
auto rasterSurface =
|
||||||
SkSurface::NewRaster(SkImageInfo::MakeN32Premul(options.size)));
|
SkSurface::MakeRaster(SkImageInfo::MakeN32Premul(options.size));
|
||||||
draw(rasterSurface->getCanvas());
|
draw(rasterSurface->getCanvas());
|
||||||
rasterData.reset(encode_snapshot(rasterSurface));
|
rasterData.reset(encode_snapshot(rasterSurface));
|
||||||
}
|
}
|
||||||
if (options.gpu) {
|
if (options.gpu) {
|
||||||
OSMesaContext osMesaContext = create_osmesa_context();
|
OSMesaContext osMesaContext = create_osmesa_context();
|
||||||
SkAutoTUnref<GrContext> grContext(create_mesa_grcontext());
|
sk_sp<GrContext> grContext(create_mesa_grcontext());
|
||||||
if (!grContext) {
|
if (!grContext) {
|
||||||
fputs("Unable to get Mesa GrContext.\n", stderr);
|
fputs("Unable to get Mesa GrContext.\n", stderr);
|
||||||
} else {
|
} else {
|
||||||
SkAutoTUnref<SkSurface> surface(
|
auto surface = SkSurface::MakeRenderTarget(
|
||||||
SkSurface::NewRenderTarget(
|
grContext.get(),
|
||||||
grContext,
|
|
||||||
SkBudgeted::kNo,
|
SkBudgeted::kNo,
|
||||||
SkImageInfo::MakeN32Premul(options.size)));
|
SkImageInfo::MakeN32Premul(options.size));
|
||||||
if (!surface) {
|
if (!surface) {
|
||||||
fputs("Unable to get render surface.\n", stderr);
|
fputs("Unable to get render surface.\n", stderr);
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -127,7 +127,7 @@ int main() {
|
|||||||
}
|
}
|
||||||
if (options.pdf) {
|
if (options.pdf) {
|
||||||
SkDynamicMemoryWStream pdfStream;
|
SkDynamicMemoryWStream pdfStream;
|
||||||
SkAutoTUnref<SkDocument> document(SkDocument::CreatePDF(&pdfStream));
|
sk_sp<SkDocument> document(SkDocument::CreatePDF(&pdfStream));
|
||||||
draw(document->beginPage(options.size.width(), options.size.height()));
|
draw(document->beginPage(options.size.width(), options.size.height()));
|
||||||
document->close();
|
document->close();
|
||||||
pdfData.reset(pdfStream.copyToData());
|
pdfData.reset(pdfStream.copyToData());
|
||||||
@ -137,7 +137,7 @@ int main() {
|
|||||||
size = options.size;
|
size = options.size;
|
||||||
SkPictureRecorder recorder;
|
SkPictureRecorder recorder;
|
||||||
draw(recorder.beginRecording(size.width(), size.height()));
|
draw(recorder.beginRecording(size.width(), size.height()));
|
||||||
SkAutoTUnref<SkPicture> picture(recorder.endRecordingAsPicture());
|
auto picture = recorder.finishRecordingAsPicture();
|
||||||
SkDynamicMemoryWStream skpStream;
|
SkDynamicMemoryWStream skpStream;
|
||||||
picture->serialize(&skpStream);
|
picture->serialize(&skpStream);
|
||||||
skpData.reset(skpStream.copyToData());
|
skpData.reset(skpStream.copyToData());
|
||||||
|
18
experimental/fiddle/fiddle_test
Normal file → Executable file
18
experimental/fiddle/fiddle_test
Normal file → Executable file
@ -11,17 +11,19 @@ set -x
|
|||||||
|
|
||||||
cd "$(dirname "$0")/../.."
|
cd "$(dirname "$0")/../.."
|
||||||
skia_dir="$PWD"
|
skia_dir="$PWD"
|
||||||
cores=32
|
|
||||||
|
|
||||||
echo "Bootstrapping CMake"
|
if ! command -v cmake > /dev/null 2>&1 ; then
|
||||||
cmake_dir="${skia_dir}/third_party/externals/cmake"
|
cores=32
|
||||||
cd "$cmake_dir"
|
echo "Bootstrapping CMake"
|
||||||
./bootstrap --parallel=$cores
|
cmake_dir="${skia_dir}/third_party/externals/cmake"
|
||||||
make -j $cores cmake
|
cd "$cmake_dir"
|
||||||
|
./bootstrap --parallel=$cores
|
||||||
|
make -j $cores cmake
|
||||||
|
export PATH="${cmake_dir}/bin:${PATH}"
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Building fiddle bootstrapped CMake"
|
echo "Building Skia and Fiddle"
|
||||||
cd "${skia_dir}/experimental/fiddle"
|
cd "${skia_dir}/experimental/fiddle"
|
||||||
export PATH="${cmake_dir}/bin:${PATH}"
|
|
||||||
go build fiddler.go
|
go build fiddler.go
|
||||||
./fiddler "$skia_dir"
|
./fiddler "$skia_dir"
|
||||||
./fiddler "$skia_dir" draw.cpp > /dev/null
|
./fiddler "$skia_dir" draw.cpp > /dev/null
|
||||||
|
@ -150,7 +150,7 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("unable to open \"%s\": %v", os.Args[2], err)
|
glog.Fatalf("unable to open \"%s\": %v", os.Args[2], err)
|
||||||
}
|
}
|
||||||
util.Close(inputFile)
|
defer util.Close(inputFile)
|
||||||
if err = fiddler(skiaSrc, inputFile, os.Stdout, tempDir); err != nil {
|
if err = fiddler(skiaSrc, inputFile, os.Stdout, tempDir); err != nil {
|
||||||
glog.Fatal(err)
|
glog.Fatal(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user