aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rwxr-xr-xtools/VisualBench/VisualInteractiveModule.cpp4
-rw-r--r--tools/VisualBench/VisualLightweightBenchModule.cpp4
-rwxr-xr-xtools/find_bad_images_in_skps.py197
-rw-r--r--tools/imgconv.cpp43
-rw-r--r--tools/json/SkJSONCanvas.cpp918
-rw-r--r--tools/json/SkJSONCanvas.h292
-rw-r--r--tools/json/SkJSONRenderer.cpp972
-rw-r--r--tools/json/SkJSONRenderer.h21
-rw-r--r--tools/kilobench/kilobench.cpp5
-rw-r--r--tools/lua/lua_pictures.cpp1
-rw-r--r--tools/pinspect.cpp1
-rw-r--r--tools/skiaserve/skiaserve.cpp5
-rw-r--r--tools/test_image_decoder.cpp39
13 files changed, 0 insertions, 2502 deletions
diff --git a/tools/VisualBench/VisualInteractiveModule.cpp b/tools/VisualBench/VisualInteractiveModule.cpp
index 73bc53ed5a..986709af99 100755
--- a/tools/VisualBench/VisualInteractiveModule.cpp
+++ b/tools/VisualBench/VisualInteractiveModule.cpp
@@ -9,10 +9,6 @@
#include "SkCanvas.h"
#include "SkCommandLineFlags.h"
-#include "SkForceLinking.h"
-#include "SkImageDecoder.h"
-
-__SK_FORCE_IMAGE_DECODER_LINKING;
VisualInteractiveModule::VisualInteractiveModule(VisualBench* owner)
: INHERITED(owner)
diff --git a/tools/VisualBench/VisualLightweightBenchModule.cpp b/tools/VisualBench/VisualLightweightBenchModule.cpp
index 182a9d9b4e..4aeeaff09a 100644
--- a/tools/VisualBench/VisualLightweightBenchModule.cpp
+++ b/tools/VisualBench/VisualLightweightBenchModule.cpp
@@ -11,17 +11,13 @@
#include "SkApplication.h"
#include "SkCanvas.h"
#include "SkCommandLineFlags.h"
-#include "SkForceLinking.h"
#include "SkGraphics.h"
#include "SkGr.h"
-#include "SkImageDecoder.h"
#include "SkOSFile.h"
#include "SkStream.h"
#include "Stats.h"
#include "gl/GrGLInterface.h"
-__SK_FORCE_IMAGE_DECODER_LINKING;
-
// Between samples we reset context
// Between frames we swap buffers
DEFINE_bool2(verbose, v, false, "enable verbose output from the test driver.");
diff --git a/tools/find_bad_images_in_skps.py b/tools/find_bad_images_in_skps.py
deleted file mode 100755
index 5dcf6a477e..0000000000
--- a/tools/find_bad_images_in_skps.py
+++ /dev/null
@@ -1,197 +0,0 @@
-#!/usr/bin/env python
-
-# Copyright 2013 Google Inc. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-"""
-This script will take as an argument either a list of skp files or a
-set of directories that contains skp files. It will then test each
-skp file with the `render_pictures` program. If that program either
-spits out any unexpected output or doesn't return 0, I will flag that
-skp file as problematic. We then extract all of the embedded images
-inside the skp and test each one of them against the
-SkImageDecoder::DecodeFile function. Again, we consider any
-extraneous output or a bad return value an error. In the event of an
-error, we retain the image and print out information about the error.
-The output (on stdout) is formatted as a csv document.
-
-A copy of each bad image is left in a directory created by
-tempfile.mkdtemp().
-"""
-
-import glob
-import os
-import re
-import shutil
-import subprocess
-import sys
-import tempfile
-import threading
-
-import test_rendering # skia/trunk/tools. reuse FindPathToProgram()
-
-USAGE = """
-Usage:
- {command} SKP_FILE [SKP_FILES]
- {command} SKP_DIR [SKP_DIRS]\n
-Environment variables:
- To run multiple worker threads, set NUM_THREADS.
- To use a different temporary storage location, set TMPDIR.
-
-"""
-
-def execute_program(args, ignores=None):
- """
- Execute a process and waits for it to complete. Returns all
- output (stderr and stdout) after (optional) filtering.
-
- @param args is passed into subprocess.Popen().
-
- @param ignores (optional) is a list of regular expression strings
- that will be ignored in the output.
-
- @returns a tuple (returncode, output)
- """
- if ignores is None:
- ignores = []
- else:
- ignores = [re.compile(ignore) for ignore in ignores]
- proc = subprocess.Popen(
- args,
- stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT)
- output = ''.join(
- line for line in proc.stdout
- if not any(bool(ignore.match(line)) for ignore in ignores))
- returncode = proc.wait()
- return (returncode, output)
-
-
-def list_files(paths):
- """
- Accepts a list of directories or filenames on the command line.
- We do not choose to recurse into directories beyond one level.
- """
- class NotAFileException(Exception):
- pass
- for path in paths:
- for globbedpath in glob.iglob(path): # useful on win32
- if os.path.isdir(globbedpath):
- for filename in os.listdir(globbedpath):
- newpath = os.path.join(globbedpath, filename)
- if os.path.isfile(newpath):
- yield newpath
- elif os.path.isfile(globbedpath):
- yield globbedpath
- else:
- raise NotAFileException('{} is not a file'.format(globbedpath))
-
-
-class BadImageFinder(object):
-
- def __init__(self, directory=None):
- self.render_pictures = test_rendering.FindPathToProgram(
- 'render_pictures')
- self.test_image_decoder = test_rendering.FindPathToProgram(
- 'test_image_decoder')
- assert os.path.isfile(self.render_pictures)
- assert os.path.isfile(self.test_image_decoder)
- if directory is None:
- self.saved_image_dir = tempfile.mkdtemp(prefix='skia_skp_test_')
- else:
- assert os.path.isdir(directory)
- self.saved_image_dir = directory
- self.bad_image_count = 0
-
- def process_files(self, skp_files):
- for path in skp_files:
- self.process_file(path)
-
- def process_file(self, skp_file):
- assert self.saved_image_dir is not None
- assert os.path.isfile(skp_file)
- args = [self.render_pictures, '--readPath', skp_file]
- ignores = ['^process_in', '^deserializ', '^drawing...', '^Non-defaul']
- returncode, output = execute_program(args, ignores)
- if (returncode == 0) and not output:
- return
- temp_image_dir = tempfile.mkdtemp(prefix='skia_skp_test___')
- args = [ self.render_pictures, '--readPath', skp_file,
- '--writePath', temp_image_dir, '--writeEncodedImages']
- subprocess.call(args, stderr=open(os.devnull,'w'),
- stdout=open(os.devnull,'w'))
- for image_name in os.listdir(temp_image_dir):
- image_path = os.path.join(temp_image_dir, image_name)
- assert(os.path.isfile(image_path))
- args = [self.test_image_decoder, image_path]
- returncode, output = execute_program(args, [])
- if (returncode == 0) and not output:
- os.remove(image_path)
- continue
- try:
- shutil.move(image_path, self.saved_image_dir)
- except (shutil.Error,):
- # If this happens, don't stop the entire process,
- # just warn the user.
- os.remove(image_path)
- sys.stderr.write('{0} is a repeat.\n'.format(image_name))
- self.bad_image_count += 1
- if returncode == 2:
- returncode = 'SkImageDecoder::DecodeFile returns false'
- elif returncode == 0:
- returncode = 'extra verbosity'
- assert output
- elif returncode == -11:
- returncode = 'segmentation violation'
- else:
- returncode = 'returncode: {}'.format(returncode)
- output = output.strip().replace('\n',' ').replace('"','\'')
- suffix = image_name[-3:]
- output_line = '"{0}","{1}","{2}","{3}","{4}"\n'.format(
- returncode, suffix, skp_file, image_name, output)
- sys.stdout.write(output_line)
- sys.stdout.flush()
- os.rmdir(temp_image_dir)
- return
-
-def main(main_argv):
- if not main_argv or main_argv[0] in ['-h', '-?', '-help', '--help']:
- sys.stderr.write(USAGE.format(command=__file__))
- return 1
- if 'NUM_THREADS' in os.environ:
- number_of_threads = int(os.environ['NUM_THREADS'])
- if number_of_threads < 1:
- number_of_threads = 1
- else:
- number_of_threads = 1
- os.environ['skia_images_png_suppressDecoderWarnings'] = 'true'
- os.environ['skia_images_jpeg_suppressDecoderWarnings'] = 'true'
-
- temp_dir = tempfile.mkdtemp(prefix='skia_skp_test_')
- sys.stderr.write('Directory for bad images: {}\n'.format(temp_dir))
- sys.stdout.write('"Error","Filetype","SKP File","Image File","Output"\n')
- sys.stdout.flush()
-
- finders = [
- BadImageFinder(temp_dir) for index in xrange(number_of_threads)]
- arguments = [[] for index in xrange(number_of_threads)]
- for index, item in enumerate(list_files(main_argv)):
- ## split up the given targets among the worker threads
- arguments[index % number_of_threads].append(item)
- threads = [
- threading.Thread(
- target=BadImageFinder.process_files, args=(finder,argument))
- for finder, argument in zip(finders, arguments)]
- for thread in threads:
- thread.start()
- for thread in threads:
- thread.join()
- number = sum(finder.bad_image_count for finder in finders)
- sys.stderr.write('Number of bad images found: {}\n'.format(number))
- return 0
-
-if __name__ == '__main__':
- exit(main(sys.argv[1:]))
-
-# LocalWords: skp stdout csv
diff --git a/tools/imgconv.cpp b/tools/imgconv.cpp
deleted file mode 100644
index 4c9fb600bb..0000000000
--- a/tools/imgconv.cpp
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright 2014 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkBitmap.h"
-#include "SkGraphics.h"
-#include "SkImageDecoder.h"
-#include "SkImageEncoder.h"
-#include "SkString.h"
-
-int tool_main(int argc, char** argv);
-int tool_main(int argc, char** argv) {
- SkAutoGraphics ag;
-
- for (int i = 1; i < argc; ++i) {
- SkString src(argv[i]);
- if (src.endsWith(".png")) {
- SkString dst(src.c_str(), src.size() - 4);
- dst.append(".jpg");
-
- SkBitmap bm;
- if (SkImageDecoder::DecodeFile(src.c_str(), &bm)) {
- if (SkImageEncoder::EncodeFile(dst.c_str(), bm, SkImageEncoder::kJPEG_Type, 100)) {
- SkDebugf("converted %s to %s\n", src.c_str(), dst.c_str());
- } else {
- SkDebugf("failed to encode %s\n", src.c_str());
- }
- } else {
- SkDebugf("failed to decode %s\n", src.c_str());
- }
- }
- }
- return 0;
-}
-
-#if !defined SK_BUILD_FOR_IOS
-int main(int argc, char * const argv[]) {
- return tool_main(argc, (char**) argv);
-}
-#endif
diff --git a/tools/json/SkJSONCanvas.cpp b/tools/json/SkJSONCanvas.cpp
deleted file mode 100644
index 07c0aeb5d2..0000000000
--- a/tools/json/SkJSONCanvas.cpp
+++ /dev/null
@@ -1,918 +0,0 @@
-/*
- * Copyright 2016 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkJSONCanvas.h"
-#include "SkColorFilter.h"
-#include "SkImageFilter.h"
-#include "SkMaskFilter.h"
-#include "SkPaintDefaults.h"
-#include "SkPath.h"
-#include "SkPathEffect.h"
-#include "SkRRect.h"
-#include "SkTextBlob.h"
-#include "SkTextBlobRunIterator.h"
-#include "SkTypeface.h"
-#include "SkWriteBuffer.h"
-
-SkJSONCanvas::SkJSONCanvas(int width, int height, SkWStream& out, bool sendBinaries)
- : INHERITED(width, height)
- , fOut(out)
- , fRoot(Json::objectValue)
- , fCommands(Json::arrayValue)
- , fSendBinaries(sendBinaries) {
- fRoot[SKJSONCANVAS_VERSION] = Json::Value(1);
-}
-
-void SkJSONCanvas::finish() {
- fRoot[SKJSONCANVAS_COMMANDS] = fCommands;
- fOut.writeText(Json::FastWriter().write(fRoot).c_str());
-}
-
-Json::Value SkJSONCanvas::makePoint(const SkPoint& point) {
- Json::Value result(Json::arrayValue);
- result.append(Json::Value(point.x()));
- result.append(Json::Value(point.y()));
- return result;
-}
-
-Json::Value SkJSONCanvas::makePoint(SkScalar x, SkScalar y) {
- Json::Value result(Json::arrayValue);
- result.append(Json::Value(x));
- result.append(Json::Value(y));
- return result;
-}
-
-Json::Value SkJSONCanvas::makeRect(const SkRect& rect) {
- Json::Value result(Json::arrayValue);
- result.append(Json::Value(rect.left()));
- result.append(Json::Value(rect.top()));
- result.append(Json::Value(rect.right()));
- result.append(Json::Value(rect.bottom()));
- return result;
-}
-
-Json::Value SkJSONCanvas::makeRRect(const SkRRect& rrect) {
- Json::Value result(Json::arrayValue);
- result.append(this->makeRect(rrect.rect()));
- result.append(this->makePoint(rrect.radii(SkRRect::kUpperLeft_Corner)));
- result.append(this->makePoint(rrect.radii(SkRRect::kUpperRight_Corner)));
- result.append(this->makePoint(rrect.radii(SkRRect::kLowerRight_Corner)));
- result.append(this->makePoint(rrect.radii(SkRRect::kLowerLeft_Corner)));
- return result;
-}
-
-Json::Value SkJSONCanvas::makePath(const SkPath& path) {
- Json::Value result(Json::objectValue);
- switch (path.getFillType()) {
- case SkPath::kWinding_FillType:
- result[SKJSONCANVAS_ATTRIBUTE_FILLTYPE] = SKJSONCANVAS_FILLTYPE_WINDING;
- break;
- case SkPath::kEvenOdd_FillType:
- result[SKJSONCANVAS_ATTRIBUTE_FILLTYPE] = SKJSONCANVAS_FILLTYPE_EVENODD;
- break;
- case SkPath::kInverseWinding_FillType:
- result[SKJSONCANVAS_ATTRIBUTE_FILLTYPE] = SKJSONCANVAS_FILLTYPE_INVERSEWINDING;
- break;
- case SkPath::kInverseEvenOdd_FillType:
- result[SKJSONCANVAS_ATTRIBUTE_FILLTYPE] = SKJSONCANVAS_FILLTYPE_INVERSEEVENODD;
- break;
- }
- Json::Value verbs(Json::arrayValue);
- SkPath::Iter iter(path, false);
- SkPoint pts[4];
- SkPath::Verb verb;
- while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
- switch (verb) {
- case SkPath::kLine_Verb: {
- Json::Value line(Json::objectValue);
- line[SKJSONCANVAS_VERB_LINE] = this->makePoint(pts[1]);
- verbs.append(line);
- break;
- }
- case SkPath::kQuad_Verb: {
- Json::Value quad(Json::objectValue);
- Json::Value coords(Json::arrayValue);
- coords.append(this->makePoint(pts[1]));
- coords.append(this->makePoint(pts[2]));
- quad[SKJSONCANVAS_VERB_QUAD] = coords;
- verbs.append(quad);
- break;
- }
- case SkPath::kCubic_Verb: {
- Json::Value cubic(Json::objectValue);
- Json::Value coords(Json::arrayValue);
- coords.append(this->makePoint(pts[1]));
- coords.append(this->makePoint(pts[2]));
- coords.append(this->makePoint(pts[3]));
- cubic[SKJSONCANVAS_VERB_CUBIC] = coords;
- verbs.append(cubic);
- break;
- }
- case SkPath::kConic_Verb: {
- Json::Value conic(Json::objectValue);
- Json::Value coords(Json::arrayValue);
- coords.append(this->makePoint(pts[1]));
- coords.append(this->makePoint(pts[2]));
- coords.append(Json::Value(iter.conicWeight()));
- conic[SKJSONCANVAS_VERB_CONIC] = coords;
- verbs.append(conic);
- break;
- }
- case SkPath::kMove_Verb: {
- Json::Value move(Json::objectValue);
- move[SKJSONCANVAS_VERB_MOVE] = this->makePoint(pts[0]);
- verbs.append(move);
- break;
- }
- case SkPath::kClose_Verb:
- verbs.append(Json::Value(SKJSONCANVAS_VERB_CLOSE));
- break;
- case SkPath::kDone_Verb:
- break;
- }
- }
- result[SKJSONCANVAS_ATTRIBUTE_VERBS] = verbs;
- return result;
-}
-
-Json::Value SkJSONCanvas::makeRegion(const SkRegion& region) {
- return Json::Value("<unimplemented>");
-}
-
-static void store_scalar(Json::Value* target, const char* key, SkScalar value,
- SkScalar defaultValue) {
- if (value != defaultValue) {
- (*target)[key] = Json::Value(value);
- }
-}
-
-static void store_bool(Json::Value* target, const char* key, bool value, bool defaultValue) {
- if (value != defaultValue) {
- (*target)[key] = Json::Value(value);
- }
-}
-
-static void encode_data(const void* data, size_t count, Json::Value* target) {
- // just use a brain-dead JSON array for now, switch to base64 or something else smarter down the
- // road
- for (size_t i = 0; i < count; i++) {
- target->append(((const uint8_t*)data)[i]);
- }
-}
-
-static void flatten(const SkFlattenable* flattenable, Json::Value* target, bool sendBinaries) {
- if (sendBinaries) {
- SkWriteBuffer buffer;
- flattenable->flatten(buffer);
- void* data = sk_malloc_throw(buffer.bytesWritten());
- buffer.writeToMemory(data);
- Json::Value bytes;
- encode_data(data, buffer.bytesWritten(), &bytes);
- Json::Value jsonFlattenable;
- jsonFlattenable[SKJSONCANVAS_ATTRIBUTE_NAME] = Json::Value(flattenable->getTypeName());
- jsonFlattenable[SKJSONCANVAS_ATTRIBUTE_BYTES] = bytes;
- (*target) = jsonFlattenable;
- free(data);
- }
- else {
- (*target)[SKJSONCANVAS_ATTRIBUTE_DESCRIPTION] = Json::Value(flattenable->getTypeName());
- }
-}
-
-static bool SK_WARN_UNUSED_RESULT flatten(const SkImage& image, Json::Value* target,
- bool sendBinaries) {
- if (sendBinaries) {
- SkData* encoded = image.encode(SkImageEncoder::kPNG_Type, 100);
- if (encoded == nullptr) {
- // PNG encode doesn't necessarily support all color formats, convert to a different
- // format
- size_t rowBytes = 4 * image.width();
- void* buffer = sk_malloc_throw(rowBytes * image.height());
- SkImageInfo dstInfo = SkImageInfo::Make(image.width(), image.height(),
- kN32_SkColorType, kPremul_SkAlphaType);
- if (!image.readPixels(dstInfo, buffer, rowBytes, 0, 0)) {
- SkDebugf("readPixels failed\n");
- return false;
- }
- SkImage* converted = SkImage::NewRasterCopy(dstInfo, buffer, rowBytes);
- encoded = converted->encode(SkImageEncoder::kPNG_Type, 100);
- if (encoded == nullptr) {
- SkDebugf("image encode failed\n");
- return false;
- }
- free(converted);
- free(buffer);
- }
- Json::Value bytes;
- encode_data(encoded->data(), encoded->size(), &bytes);
- (*target)[SKJSONCANVAS_ATTRIBUTE_BYTES] = bytes;
- encoded->unref();
- }
- else {
- SkString description = SkStringPrintf("%dx%d pixel image", image.width(), image.height());
- (*target)[SKJSONCANVAS_ATTRIBUTE_DESCRIPTION] = Json::Value(description.c_str());
- }
- return true;
-}
-
-static const char* color_type_name(SkColorType colorType) {
- switch (colorType) {
- case kARGB_4444_SkColorType:
- return SKJSONCANVAS_COLORTYPE_ARGB4444;
- case kRGBA_8888_SkColorType:
- return SKJSONCANVAS_COLORTYPE_RGBA8888;
- case kBGRA_8888_SkColorType:
- return SKJSONCANVAS_COLORTYPE_BGRA8888;
- case kRGB_565_SkColorType:
- return SKJSONCANVAS_COLORTYPE_565;
- case kGray_8_SkColorType:
- return SKJSONCANVAS_COLORTYPE_GRAY8;
- case kIndex_8_SkColorType:
- return SKJSONCANVAS_COLORTYPE_INDEX8;
- case kAlpha_8_SkColorType:
- return SKJSONCANVAS_COLORTYPE_ALPHA8;
- default:
- SkASSERT(false);
- return SKJSONCANVAS_COLORTYPE_RGBA8888;
- }
-}
-
-static const char* alpha_type_name(SkAlphaType alphaType) {
- switch (alphaType) {
- case kOpaque_SkAlphaType:
- return SKJSONCANVAS_ALPHATYPE_OPAQUE;
- case kPremul_SkAlphaType:
- return SKJSONCANVAS_ALPHATYPE_PREMUL;
- case kUnpremul_SkAlphaType:
- return SKJSONCANVAS_ALPHATYPE_UNPREMUL;
- default:
- SkASSERT(false);
- return SKJSONCANVAS_ALPHATYPE_OPAQUE;
- }
-}
-
-static bool SK_WARN_UNUSED_RESULT flatten(const SkBitmap& bitmap, Json::Value* target,
- bool sendBinaries) {
- bitmap.lockPixels();
- SkAutoTUnref<SkImage> image(SkImage::NewFromBitmap(bitmap));
- bitmap.unlockPixels();
- (*target)[SKJSONCANVAS_ATTRIBUTE_COLOR] = Json::Value(color_type_name(bitmap.colorType()));
- (*target)[SKJSONCANVAS_ATTRIBUTE_ALPHA] = Json::Value(alpha_type_name(bitmap.alphaType()));
- bool success = flatten(*image, target, sendBinaries);
- return success;
-}
-
-static void apply_paint_color(const SkPaint& paint, Json::Value* target) {
- SkColor color = paint.getColor();
- if (color != SK_ColorBLACK) {
- Json::Value colorValue(Json::arrayValue);
- colorValue.append(Json::Value(SkColorGetA(color)));
- colorValue.append(Json::Value(SkColorGetR(color)));
- colorValue.append(Json::Value(SkColorGetG(color)));
- colorValue.append(Json::Value(SkColorGetB(color)));
- (*target)[SKJSONCANVAS_ATTRIBUTE_COLOR] = colorValue;;
- }
-}
-
-static void apply_paint_style(const SkPaint& paint, Json::Value* target) {
- SkPaint::Style style = paint.getStyle();
- if (style != SkPaint::kFill_Style) {
- switch (style) {
- case SkPaint::kStroke_Style: {
- Json::Value stroke(SKJSONCANVAS_STYLE_STROKE);
- (*target)[SKJSONCANVAS_ATTRIBUTE_STYLE] = stroke;
- break;
- }
- case SkPaint::kStrokeAndFill_Style: {
- Json::Value strokeAndFill(SKJSONCANVAS_STYLE_STROKEANDFILL);
- (*target)[SKJSONCANVAS_ATTRIBUTE_STYLE] = strokeAndFill;
- break;
- }
- default: SkASSERT(false);
- }
- }
-}
-
-static void apply_paint_cap(const SkPaint& paint, Json::Value* target) {
- SkPaint::Cap cap = paint.getStrokeCap();
- if (cap != SkPaint::kDefault_Cap) {
- switch (cap) {
- case SkPaint::kButt_Cap: {
- (*target)[SKJSONCANVAS_ATTRIBUTE_CAP] = Json::Value(SKJSONCANVAS_CAP_BUTT);
- break;
- }
- case SkPaint::kRound_Cap: {
- (*target)[SKJSONCANVAS_ATTRIBUTE_CAP] = Json::Value(SKJSONCANVAS_CAP_ROUND);
- break;
- }
- case SkPaint::kSquare_Cap: {
- (*target)[SKJSONCANVAS_ATTRIBUTE_CAP] = Json::Value(SKJSONCANVAS_CAP_SQUARE);
- break;
- }
- default: SkASSERT(false);
- }
- }
-}
-static void apply_paint_maskfilter(const SkPaint& paint, Json::Value* target, bool sendBinaries) {
- SkMaskFilter* maskFilter = paint.getMaskFilter();
- if (maskFilter != nullptr) {
- SkMaskFilter::BlurRec blurRec;
- if (maskFilter->asABlur(&blurRec)) {
- Json::Value blur(Json::objectValue);
- blur[SKJSONCANVAS_ATTRIBUTE_SIGMA] = Json::Value(blurRec.fSigma);
- switch (blurRec.fStyle) {
- case SkBlurStyle::kNormal_SkBlurStyle:
- blur[SKJSONCANVAS_ATTRIBUTE_STYLE] = Json::Value(SKJSONCANVAS_BLURSTYLE_NORMAL);
- break;
- case SkBlurStyle::kSolid_SkBlurStyle:
- blur[SKJSONCANVAS_ATTRIBUTE_STYLE] = Json::Value(SKJSONCANVAS_BLURSTYLE_SOLID);
- break;
- case SkBlurStyle::kOuter_SkBlurStyle:
- blur[SKJSONCANVAS_ATTRIBUTE_STYLE] = Json::Value(SKJSONCANVAS_BLURSTYLE_OUTER);
- break;
- case SkBlurStyle::kInner_SkBlurStyle:
- blur[SKJSONCANVAS_ATTRIBUTE_STYLE] = Json::Value(SKJSONCANVAS_BLURSTYLE_INNER);
- break;
- default:
- SkASSERT(false);
- }
- switch (blurRec.fQuality) {
- case SkBlurQuality::kLow_SkBlurQuality:
- blur[SKJSONCANVAS_ATTRIBUTE_QUALITY] = Json::Value(SKJSONCANVAS_BLURQUALITY_LOW);
- break;
- case SkBlurQuality::kHigh_SkBlurQuality:
- blur[SKJSONCANVAS_ATTRIBUTE_QUALITY] = Json::Value(SKJSONCANVAS_BLURQUALITY_HIGH);
- break;
- default:
- SkASSERT(false);
- }
- (*target)[SKJSONCANVAS_ATTRIBUTE_BLUR] = blur;
- }
- else {
- Json::Value jsonMaskFilter;
- flatten(maskFilter, &jsonMaskFilter, sendBinaries);
- (*target)[SKJSONCANVAS_ATTRIBUTE_MASKFILTER] = jsonMaskFilter;
- }
- }
-}
-
-static void apply_paint_patheffect(const SkPaint& paint, Json::Value* target, bool sendBinaries) {
- SkPathEffect* pathEffect = paint.getPathEffect();
- if (pathEffect != nullptr) {
- SkPathEffect::DashInfo dashInfo;
- SkPathEffect::DashType dashType = pathEffect->asADash(&dashInfo);
- if (dashType == SkPathEffect::kDash_DashType) {
- dashInfo.fIntervals = (SkScalar*) sk_malloc_throw(dashInfo.fCount * sizeof(SkScalar));
- pathEffect->asADash(&dashInfo);
- Json::Value dashing(Json::objectValue);
- Json::Value intervals(Json::arrayValue);
- for (int32_t i = 0; i < dashInfo.fCount; i++) {
- intervals.append(Json::Value(dashInfo.fIntervals[i]));
- }
- free(dashInfo.fIntervals);
- dashing[SKJSONCANVAS_ATTRIBUTE_INTERVALS] = intervals;
- dashing[SKJSONCANVAS_ATTRIBUTE_PHASE] = dashInfo.fPhase;
- (*target)[SKJSONCANVAS_ATTRIBUTE_DASHING] = dashing;
- }
- else {
- Json::Value jsonPathEffect;
- flatten(pathEffect, &jsonPathEffect, sendBinaries);
- (*target)[SKJSONCANVAS_ATTRIBUTE_PATHEFFECT] = jsonPathEffect;
- }
- }
-}
-
-static void apply_paint_textalign(const SkPaint& paint, Json::Value* target) {
- SkPaint::Align textAlign = paint.getTextAlign();
- if (textAlign != SkPaint::kLeft_Align) {
- switch (textAlign) {
- case SkPaint::kCenter_Align: {
- (*target)[SKJSONCANVAS_ATTRIBUTE_TEXTALIGN] = SKJSONCANVAS_ALIGN_CENTER;
- break;
- }
- case SkPaint::kRight_Align: {
- (*target)[SKJSONCANVAS_ATTRIBUTE_TEXTALIGN] = SKJSONCANVAS_ALIGN_RIGHT;
- break;
- }
- default: SkASSERT(false);
- }
- }
-}
-
-static void apply_paint_typeface(const SkPaint& paint, Json::Value* target,
- bool sendBinaries) {
- SkTypeface* typeface = paint.getTypeface();
- if (typeface != nullptr) {
- if (sendBinaries) {
- Json::Value jsonTypeface;
- SkDynamicMemoryWStream buffer;
- typeface->serialize(&buffer);
- void* data = sk_malloc_throw(buffer.bytesWritten());
- buffer.copyTo(data);
- Json::Value bytes;
- encode_data(data, buffer.bytesWritten(), &bytes);
- jsonTypeface[SKJSONCANVAS_ATTRIBUTE_BYTES] = bytes;
- free(data);
- (*target)[SKJSONCANVAS_ATTRIBUTE_TYPEFACE] = jsonTypeface;
- }
- }
-}
-
-static void apply_paint_shader(const SkPaint& paint, Json::Value* target, bool sendBinaries) {
- SkFlattenable* shader = paint.getShader();
- if (shader != nullptr) {
- Json::Value jsonShader;
- flatten(shader, &jsonShader, sendBinaries);
- (*target)[SKJSONCANVAS_ATTRIBUTE_SHADER] = jsonShader;
- }
-}
-
-static void apply_paint_xfermode(const SkPaint& paint, Json::Value* target, bool sendBinaries) {
- SkFlattenable* xfermode = paint.getXfermode();
- if (xfermode != nullptr) {
- Json::Value jsonXfermode;
- flatten(xfermode, &jsonXfermode, sendBinaries);
- (*target)[SKJSONCANVAS_ATTRIBUTE_XFERMODE] = jsonXfermode;
- }
-}
-
-static void apply_paint_imagefilter(const SkPaint& paint, Json::Value* target, bool sendBinaries) {
- SkFlattenable* imageFilter = paint.getImageFilter();
- if (imageFilter != nullptr) {
- Json::Value jsonImageFilter;
- flatten(imageFilter, &jsonImageFilter, sendBinaries);
- (*target)[SKJSONCANVAS_ATTRIBUTE_IMAGEFILTER] = jsonImageFilter;
- }
-}
-
-static void apply_paint_colorfilter(const SkPaint& paint, Json::Value* target, bool sendBinaries) {
- SkFlattenable* colorFilter = paint.getColorFilter();
- if (colorFilter != nullptr) {
- Json::Value jsonColorFilter;
- flatten(colorFilter, &jsonColorFilter, sendBinaries);
- (*target)[SKJSONCANVAS_ATTRIBUTE_COLORFILTER] = jsonColorFilter;
- }
-}
-
-Json::Value SkJSONCanvas::makePaint(const SkPaint& paint) {
- Json::Value result(Json::objectValue);
- store_scalar(&result, SKJSONCANVAS_ATTRIBUTE_STROKEWIDTH, paint.getStrokeWidth(), 0.0f);
- store_scalar(&result, SKJSONCANVAS_ATTRIBUTE_STROKEMITER, paint.getStrokeMiter(),
- SkPaintDefaults_MiterLimit);
- store_bool(&result, SKJSONCANVAS_ATTRIBUTE_ANTIALIAS, paint.isAntiAlias(), false);
- store_scalar(&result, SKJSONCANVAS_ATTRIBUTE_TEXTSIZE, paint.getTextSize(),
- SkPaintDefaults_TextSize);
- store_scalar(&result, SKJSONCANVAS_ATTRIBUTE_TEXTSCALEX, paint.getTextScaleX(), SK_Scalar1);
- store_scalar(&result, SKJSONCANVAS_ATTRIBUTE_TEXTSCALEX, paint.getTextSkewX(), 0.0f);
- apply_paint_color(paint, &result);
- apply_paint_style(paint, &result);
- apply_paint_cap(paint, &result);
- apply_paint_textalign(paint, &result);
- apply_paint_patheffect(paint, &result, fSendBinaries);
- apply_paint_maskfilter(paint, &result, fSendBinaries);
- apply_paint_shader(paint, &result, fSendBinaries);
- apply_paint_xfermode(paint, &result, fSendBinaries);
- apply_paint_imagefilter(paint, &result, fSendBinaries);
- apply_paint_colorfilter(paint, &result, fSendBinaries);
- apply_paint_typeface(paint, &result, fSendBinaries);
- return result;
-}
-
-Json::Value SkJSONCanvas::MakeIRect(const SkIRect& rect) {
- Json::Value result(Json::arrayValue);
- result.append(Json::Value(rect.left()));
- result.append(Json::Value(rect.top()));
- result.append(Json::Value(rect.right()));
- result.append(Json::Value(rect.bottom()));
- return result;
-}
-
-Json::Value SkJSONCanvas::MakeMatrix(const SkMatrix& matrix) {
- Json::Value result(Json::arrayValue);
- Json::Value row1(Json::arrayValue);
- row1.append(Json::Value(matrix[0]));
- row1.append(Json::Value(matrix[1]));
- row1.append(Json::Value(matrix[2]));
- result.append(row1);
- Json::Value row2(Json::arrayValue);
- row2.append(Json::Value(matrix[3]));
- row2.append(Json::Value(matrix[4]));
- row2.append(Json::Value(matrix[5]));
- result.append(row2);
- Json::Value row3(Json::arrayValue);
- row3.append(Json::Value(matrix[6]));
- row3.append(Json::Value(matrix[7]));
- row3.append(Json::Value(matrix[8]));
- result.append(row3);
- return result;
-}
-
-Json::Value SkJSONCanvas::makeRegionOp(SkRegion::Op op) {
- switch (op) {
- case SkRegion::kDifference_Op:
- return Json::Value(SKJSONCANVAS_REGIONOP_DIFFERENCE);
- case SkRegion::kIntersect_Op:
- return Json::Value(SKJSONCANVAS_REGIONOP_INTERSECT);
- case SkRegion::kUnion_Op:
- return Json::Value(SKJSONCANVAS_REGIONOP_UNION);
- case SkRegion::kXOR_Op:
- return Json::Value(SKJSONCANVAS_REGIONOP_XOR);
- case SkRegion::kReverseDifference_Op:
- return Json::Value(SKJSONCANVAS_REGIONOP_REVERSE_DIFFERENCE);
- case SkRegion::kReplace_Op:
- return Json::Value(SKJSONCANVAS_REGIONOP_REPLACE);
- default:
- SkASSERT(false);
- return Json::Value("<invalid region op>");
- };
-}
-
-Json::Value SkJSONCanvas::makePointMode(SkCanvas::PointMode mode) {
- switch (mode) {
- case SkCanvas::kPoints_PointMode:
- return Json::Value(SKJSONCANVAS_POINTMODE_POINTS);
- case SkCanvas::kLines_PointMode:
- return Json::Value(SKJSONCANVAS_POINTMODE_LINES);
- case SkCanvas::kPolygon_PointMode:
- return Json::Value(SKJSONCANVAS_POINTMODE_POLYGON);
- default:
- SkASSERT(false);
- return Json::Value("<invalid point mode>");
- };
-}
-
-void SkJSONCanvas::didConcat(const SkMatrix& matrix) {
- Json::Value command(Json::objectValue);
- switch (matrix.getType()) {
- case SkMatrix::kTranslate_Mask:
- command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_TRANSLATE);
- command[SKJSONCANVAS_ATTRIBUTE_X] = Json::Value(matrix.get(SkMatrix::kMTransX));
- command[SKJSONCANVAS_ATTRIBUTE_Y] = Json::Value(matrix.get(SkMatrix::kMTransY));
- break;
- case SkMatrix::kScale_Mask:
- command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_SCALE);
- command[SKJSONCANVAS_ATTRIBUTE_X] = Json::Value(matrix.get(SkMatrix::kMScaleX));
- command[SKJSONCANVAS_ATTRIBUTE_Y] = Json::Value(matrix.get(SkMatrix::kMScaleY));
- break;
- default:
- this->didSetMatrix(this->getTotalMatrix());
- return;
- }
- fCommands.append(command);
-}
-
-void SkJSONCanvas::didSetMatrix(const SkMatrix& matrix) {
- Json::Value command(Json::objectValue);
- command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_MATRIX);
- command[SKJSONCANVAS_ATTRIBUTE_MATRIX] = this->MakeMatrix(matrix);
- fCommands.append(command);
-}
-
-void SkJSONCanvas::onDrawPaint(const SkPaint& paint) {
- Json::Value command(Json::objectValue);
- command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_PAINT);
- command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint);
- fCommands.append(command);
-}
-
-void SkJSONCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) {
- Json::Value command(Json::objectValue);
- command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_RECT);
- command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makeRect(rect);
- command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint);
- fCommands.append(command);
-}
-
-void SkJSONCanvas::onDrawOval(const SkRect& rect, const SkPaint& paint) {
- Json::Value command(Json::objectValue);
- command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_OVAL);
- command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makeRect(rect);
- command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint);
- fCommands.append(command);
-}
-
-void SkJSONCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) {
- Json::Value command(Json::objectValue);
- command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_RRECT);
- command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makeRRect(rrect);
- command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint);
- fCommands.append(command);
-}
-
-void SkJSONCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint) {
- Json::Value command(Json::objectValue);
- command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_RRECT);
- command[SKJSONCANVAS_ATTRIBUTE_INNER] = this->makeRRect(inner);
- command[SKJSONCANVAS_ATTRIBUTE_OUTER] = this->makeRRect(outer);
- command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint);
- fCommands.append(command);
-}
-
-void SkJSONCanvas::onDrawPoints(SkCanvas::PointMode mode, size_t count, const SkPoint pts[],
- const SkPaint& paint) {
- Json::Value command(Json::objectValue);
- command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_POINTS);
- command[SKJSONCANVAS_ATTRIBUTE_MODE] = this->makePointMode(mode);
- Json::Value points(Json::arrayValue);
- for (size_t i = 0; i < count; i++) {
- points.append(this->makePoint(pts[i]));
- }
- command[SKJSONCANVAS_ATTRIBUTE_POINTS] = points;
- command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint);
- fCommands.append(command);
-}
-
-void SkJSONCanvas::onDrawVertices(SkCanvas::VertexMode, int vertexCount, const SkPoint vertices[],
- const SkPoint texs[], const SkColor colors[], SkXfermode*,
- const uint16_t indices[], int indexCount, const SkPaint&) {
- SkDebugf("unsupported: drawVertices\n");
- Json::Value command(Json::objectValue);
- command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_VERTICES);
- fCommands.append(command);
-}
-
-void SkJSONCanvas::onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[],
- int count, SkXfermode::Mode, const SkRect* cull, const SkPaint*) {
- SkDebugf("unsupported: drawAtlas\n");
- Json::Value command(Json::objectValue);
- command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_ATLAS);
- fCommands.append(command);
-}
-
-void SkJSONCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) {
- Json::Value command(Json::objectValue);
- command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_PATH);
- command[SKJSONCANVAS_ATTRIBUTE_PATH] = this->makePath(path);
- command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint);
- fCommands.append(command);
-}
-
-void SkJSONCanvas::onDrawImage(const SkImage* image, SkScalar dx, SkScalar dy,
- const SkPaint* paint) {
- Json::Value encoded;
- if (flatten(*image, &encoded, fSendBinaries)) {
- Json::Value command(Json::objectValue);
- command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_IMAGE);
- command[SKJSONCANVAS_ATTRIBUTE_IMAGE] = encoded;
- command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makePoint(dx, dy);
- if (paint != nullptr) {
- command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(*paint);
- }
- fCommands.append(command);
- }
-}
-
-void SkJSONCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
- const SkPaint* paint, SkCanvas::SrcRectConstraint constraint) {
- Json::Value encoded;
- if (flatten(*image, &encoded, fSendBinaries)) {
- Json::Value command(Json::objectValue);
- command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_IMAGERECT);
- command[SKJSONCANVAS_ATTRIBUTE_IMAGE] = encoded;
- if (src != nullptr) {
- command[SKJSONCANVAS_ATTRIBUTE_SRC] = this->makeRect(*src);
- }
- command[SKJSONCANVAS_ATTRIBUTE_DST] = this->makeRect(dst);
- if (paint != nullptr) {
- command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(*paint);
- }
- if (constraint == SkCanvas::kStrict_SrcRectConstraint) {
- command[SKJSONCANVAS_ATTRIBUTE_STRICT] = Json::Value(true);
- }
- fCommands.append(command);
- }
-}
-
-void SkJSONCanvas::onDrawImageNine(const SkImage*, const SkIRect& center, const SkRect& dst,
- const SkPaint*) {
- SkDebugf("unsupported: drawImageNine\n");
- Json::Value command(Json::objectValue);
- command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_IMAGENINE);
- fCommands.append(command);
-}
-
-void SkJSONCanvas::onDrawBitmap(const SkBitmap& bitmap, SkScalar dx, SkScalar dy,
- const SkPaint* paint) {
- Json::Value encoded;
- if (flatten(bitmap, &encoded, fSendBinaries)) {
- Json::Value command(Json::objectValue);
- command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_BITMAP);
- command[SKJSONCANVAS_ATTRIBUTE_BITMAP] = encoded;
- command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makePoint(dx, dy);
- if (paint != nullptr) {
- command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(*paint);
- }
- fCommands.append(command);
- }
-}
-
-void SkJSONCanvas::onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst,
- const SkPaint* paint, SkCanvas::SrcRectConstraint constraint) {
- Json::Value encoded;
- if (flatten(bitmap, &encoded, fSendBinaries)) {
- Json::Value command(Json::objectValue);
- command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_BITMAPRECT);
- command[SKJSONCANVAS_ATTRIBUTE_BITMAP] = encoded;
- if (src != nullptr) {
- command[SKJSONCANVAS_ATTRIBUTE_SRC] = this->makeRect(*src);
- }
- command[SKJSONCANVAS_ATTRIBUTE_DST] = this->makeRect(dst);
- if (paint != nullptr) {
- command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(*paint);
- }
- if (constraint == SkCanvas::kStrict_SrcRectConstraint) {
- command[SKJSONCANVAS_ATTRIBUTE_STRICT] = Json::Value(true);
- }
- fCommands.append(command);
- }
-}
-
-void SkJSONCanvas::onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst,
- const SkPaint*) {
- SkDebugf("unsupported: drawBitmapNine\n");
- Json::Value command(Json::objectValue);
- command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_BITMAPNINE);
- fCommands.append(command);
-}
-
-void SkJSONCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x,
- SkScalar y, const SkPaint& paint) {
- Json::Value command(Json::objectValue);
- command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_TEXT);
- command[SKJSONCANVAS_ATTRIBUTE_TEXT] = Json::Value((const char*) text,
- ((const char*) text) + byteLength);
- command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makePoint(x, y);
- command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint);
- fCommands.append(command);
-}
-
-void SkJSONCanvas::onDrawPosText(const void* text, size_t byteLength,
- const SkPoint pos[], const SkPaint& paint) {
- Json::Value command(Json::objectValue);
- command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_POSTEXT);
- command[SKJSONCANVAS_ATTRIBUTE_TEXT] = Json::Value((const char*) text,
- ((const char*) text) + byteLength);
- Json::Value coords(Json::arrayValue);
- for (size_t i = 0; i < byteLength; i++) {
- coords.append(this->makePoint(pos[i]));
- }
- command[SKJSONCANVAS_ATTRIBUTE_COORDS] = coords;
- command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint);
- fCommands.append(command);
-}
-
-void SkJSONCanvas::onDrawPosTextH(const void* text, size_t byteLength,
- const SkScalar xpos[], SkScalar constY,
- const SkPaint& paint) {
- SkDebugf("unsupported: drawPosTextH\n");
- Json::Value command(Json::objectValue);
- command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_POSTEXTH);
- fCommands.append(command);
-}
-
-void SkJSONCanvas::onDrawTextOnPath(const void* text, size_t byteLength,
- const SkPath& path, const SkMatrix* matrix,
- const SkPaint& paint) {
- Json::Value command(Json::objectValue);
- command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_TEXTONPATH);
- command[SKJSONCANVAS_ATTRIBUTE_TEXT] = Json::Value((const char*) text,
- ((const char*) text) + byteLength);
- command[SKJSONCANVAS_ATTRIBUTE_PATH] = this->makePath(path);
- if (matrix != nullptr) {
- command[SKJSONCANVAS_ATTRIBUTE_MATRIX] = this->MakeMatrix(*matrix);
- }
- command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint);
- fCommands.append(command);
-}
-
-void SkJSONCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
- const SkPaint& paint) {
- Json::Value command(Json::objectValue);
- command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_TEXTBLOB);
- Json::Value runs(Json::arrayValue);
- SkTextBlobRunIterator iter(blob);
- while (!iter.done()) {
- Json::Value run(Json::objectValue);
- Json::Value jsonPositions(Json::arrayValue);
- Json::Value jsonGlyphs(Json::arrayValue);
- const SkScalar* iterPositions = iter.pos();
- const uint16_t* iterGlyphs = iter.glyphs();
- for (uint32_t i = 0; i < iter.glyphCount(); i++) {
- switch (iter.positioning()) {
- case SkTextBlob::kFull_Positioning:
- jsonPositions.append(this->makePoint(iterPositions[i * 2],
- iterPositions[i * 2 + 1]));
- break;
- case SkTextBlob::kHorizontal_Positioning:
- jsonPositions.append(Json::Value(iterPositions[i]));
- break;
- case SkTextBlob::kDefault_Positioning:
- break;
- }
- jsonGlyphs.append(Json::Value(iterGlyphs[i]));
- }
- if (iter.positioning() != SkTextBlob::kDefault_Positioning) {
- run[SKJSONCANVAS_ATTRIBUTE_POSITIONS] = jsonPositions;
- }
- run[SKJSONCANVAS_ATTRIBUTE_GLYPHS] = jsonGlyphs;
- SkPaint fontPaint;
- iter.applyFontToPaint(&fontPaint);
- run[SKJSONCANVAS_ATTRIBUTE_FONT] = this->makePaint(fontPaint);
- run[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makePoint(iter.offset());
- runs.append(run);
- iter.next();
- }
- command[SKJSONCANVAS_ATTRIBUTE_RUNS] = runs;
- command[SKJSONCANVAS_ATTRIBUTE_X] = Json::Value(x);
- command[SKJSONCANVAS_ATTRIBUTE_Y] = Json::Value(y);
- command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(paint);
- fCommands.append(command);
-}
-
-void SkJSONCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
- const SkPoint texCoords[4], SkXfermode* xmode,
- const SkPaint& paint) {
- SkDebugf("unsupported: drawPatch\n");
- Json::Value command(Json::objectValue);
- command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_PATCH);
- fCommands.append(command);
-}
-
-void SkJSONCanvas::onDrawDrawable(SkDrawable*, const SkMatrix*) {
- SkDebugf("unsupported: drawDrawable\n");
- Json::Value command(Json::objectValue);
- command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_DRAWABLE);
- fCommands.append(command);
-}
-
-void SkJSONCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
- Json::Value command(Json::objectValue);
- command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_CLIPRECT);
- command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makeRect(rect);
- command[SKJSONCANVAS_ATTRIBUTE_REGIONOP] = this->makeRegionOp(op);
- command[SKJSONCANVAS_ATTRIBUTE_ANTIALIAS] = (edgeStyle == SkCanvas::kSoft_ClipEdgeStyle);
- fCommands.append(command);
-}
-
-void SkJSONCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
- Json::Value command(Json::objectValue);
- command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_CLIPRRECT);
- command[SKJSONCANVAS_ATTRIBUTE_COORDS] = this->makeRRect(rrect);
- command[SKJSONCANVAS_ATTRIBUTE_REGIONOP] = this->makeRegionOp(op);
- command[SKJSONCANVAS_ATTRIBUTE_ANTIALIAS] = (edgeStyle == SkCanvas::kSoft_ClipEdgeStyle);
- fCommands.append(command);
-}
-
-void SkJSONCanvas::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
- Json::Value command(Json::objectValue);
- command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_CLIPPATH);
- command[SKJSONCANVAS_ATTRIBUTE_PATH] = this->makePath(path);
- command[SKJSONCANVAS_ATTRIBUTE_REGIONOP] = this->makeRegionOp(op);
- command[SKJSONCANVAS_ATTRIBUTE_ANTIALIAS] = (edgeStyle == SkCanvas::kSoft_ClipEdgeStyle);
- fCommands.append(command);
-}
-
-void SkJSONCanvas::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) {
- Json::Value command(Json::objectValue);
- command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_CLIPREGION);
- command[SKJSONCANVAS_ATTRIBUTE_REGION] = this->makeRegion(deviceRgn);
- command[SKJSONCANVAS_ATTRIBUTE_REGIONOP] = this->makeRegionOp(op);
- fCommands.append(command);
-}
-
-void SkJSONCanvas::willSave() {
- Json::Value command(Json::objectValue);
- command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_SAVE);
- fCommands.append(command);
-}
-
-void SkJSONCanvas::willRestore() {
- Json::Value command(Json::objectValue);
- command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_RESTORE);
- fCommands.append(command);
-}
-
-SkCanvas::SaveLayerStrategy SkJSONCanvas::getSaveLayerStrategy(const SaveLayerRec& rec) {
- Json::Value command(Json::objectValue);
- command[SKJSONCANVAS_COMMAND] = Json::Value(SKJSONCANVAS_COMMAND_SAVELAYER);
- if (rec.fBounds != nullptr) {
- command[SKJSONCANVAS_ATTRIBUTE_BOUNDS] = this->makeRect(*rec.fBounds);
- }
- if (rec.fPaint != nullptr) {
- command[SKJSONCANVAS_ATTRIBUTE_PAINT] = this->makePaint(*rec.fPaint);
- }
- if (rec.fBackdrop != nullptr) {
- Json::Value backdrop;
- flatten(rec.fBackdrop, &backdrop, fSendBinaries);
- command[SKJSONCANVAS_ATTRIBUTE_BACKDROP] = backdrop;
- }
- if (rec.fSaveLayerFlags != 0) {
- SkDebugf("unsupported: saveLayer flags\n");
- }
- fCommands.append(command);
- return this->INHERITED::getSaveLayerStrategy(rec);
-}
diff --git a/tools/json/SkJSONCanvas.h b/tools/json/SkJSONCanvas.h
deleted file mode 100644
index b0f736f48a..0000000000
--- a/tools/json/SkJSONCanvas.h
+++ /dev/null
@@ -1,292 +0,0 @@
-/*
- * Copyright 2016 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkJSONCanvas_DEFINED
-#define SkJSONCanvas_DEFINED
-
-#include "SkCanvas.h"
-#include "SkStream.h"
-#include "SkJSONCPP.h"
-
-#define SKJSONCANVAS_VERSION "version"
-#define SKJSONCANVAS_COMMANDS "commands"
-#define SKJSONCANVAS_COMMAND "command"
-
-#define SKJSONCANVAS_COMMAND_TRANSLATE "Translate"
-#define SKJSONCANVAS_COMMAND_SCALE "Scale"
-#define SKJSONCANVAS_COMMAND_MATRIX "Matrix"
-#define SKJSONCANVAS_COMMAND_PAINT "Paint"
-#define SKJSONCANVAS_COMMAND_RECT "Rect"
-#define SKJSONCANVAS_COMMAND_OVAL "Oval"
-#define SKJSONCANVAS_COMMAND_RRECT "RRect"
-#define SKJSONCANVAS_COMMAND_DRRECT "DRRect"
-#define SKJSONCANVAS_COMMAND_POINTS "Points"
-#define SKJSONCANVAS_COMMAND_VERTICES "Vertices"
-#define SKJSONCANVAS_COMMAND_ATLAS "Atlas"
-#define SKJSONCANVAS_COMMAND_PATH "Path"
-#define SKJSONCANVAS_COMMAND_IMAGE "Image"
-#define SKJSONCANVAS_COMMAND_IMAGERECT "ImageRect"
-#define SKJSONCANVAS_COMMAND_IMAGENINE "ImageNine"
-#define SKJSONCANVAS_COMMAND_BITMAP "Bitmap"
-#define SKJSONCANVAS_COMMAND_BITMAPRECT "BitmapRect"
-#define SKJSONCANVAS_COMMAND_BITMAPNINE "BitmapNine"
-#define SKJSONCANVAS_COMMAND_TEXT "Text"
-#define SKJSONCANVAS_COMMAND_POSTEXT "PosText"
-#define SKJSONCANVAS_COMMAND_POSTEXTH "PosTextH"
-#define SKJSONCANVAS_COMMAND_TEXTONPATH "TextOnPath"
-#define SKJSONCANVAS_COMMAND_TEXTBLOB "TextBlob"
-#define SKJSONCANVAS_COMMAND_PATCH "Patch"
-#define SKJSONCANVAS_COMMAND_DRAWABLE "Drawable"
-#define SKJSONCANVAS_COMMAND_CLIPRECT "ClipRect"
-#define SKJSONCANVAS_COMMAND_CLIPRRECT "ClipRRect"
-#define SKJSONCANVAS_COMMAND_CLIPPATH "ClipPath"
-#define SKJSONCANVAS_COMMAND_CLIPREGION "ClipRegion"
-#define SKJSONCANVAS_COMMAND_SAVE "Save"
-#define SKJSONCANVAS_COMMAND_RESTORE "Restore"
-#define SKJSONCANVAS_COMMAND_SAVELAYER "SaveLayer"
-
-#define SKJSONCANVAS_ATTRIBUTE_MATRIX "matrix"
-#define SKJSONCANVAS_ATTRIBUTE_COORDS "coords"
-#define SKJSONCANVAS_ATTRIBUTE_BOUNDS "bounds"
-#define SKJSONCANVAS_ATTRIBUTE_PAINT "paint"
-#define SKJSONCANVAS_ATTRIBUTE_OUTER "outer"
-#define SKJSONCANVAS_ATTRIBUTE_INNER "inner"
-#define SKJSONCANVAS_ATTRIBUTE_MODE "mode"
-#define SKJSONCANVAS_ATTRIBUTE_POINTS "points"
-#define SKJSONCANVAS_ATTRIBUTE_PATH "path"
-#define SKJSONCANVAS_ATTRIBUTE_TEXT "text"
-#define SKJSONCANVAS_ATTRIBUTE_COLOR "color"
-#define SKJSONCANVAS_ATTRIBUTE_ALPHA "alpha"
-#define SKJSONCANVAS_ATTRIBUTE_STYLE "style"
-#define SKJSONCANVAS_ATTRIBUTE_STROKEWIDTH "strokeWidth"
-#define SKJSONCANVAS_ATTRIBUTE_STROKEMITER "strokeMiter"
-#define SKJSONCANVAS_ATTRIBUTE_CAP "cap"
-#define SKJSONCANVAS_ATTRIBUTE_ANTIALIAS "antiAlias"
-#define SKJSONCANVAS_ATTRIBUTE_REGION "region"
-#define SKJSONCANVAS_ATTRIBUTE_REGIONOP "op"
-#define SKJSONCANVAS_ATTRIBUTE_EDGESTYLE "edgeStyle"
-#define SKJSONCANVAS_ATTRIBUTE_DEVICEREGION "deviceRegion"
-#define SKJSONCANVAS_ATTRIBUTE_BLUR "blur"
-#define SKJSONCANVAS_ATTRIBUTE_SIGMA "sigma"
-#define SKJSONCANVAS_ATTRIBUTE_QUALITY "quality"
-#define SKJSONCANVAS_ATTRIBUTE_TEXTALIGN "textAlign"
-#define SKJSONCANVAS_ATTRIBUTE_TEXTSIZE "textSize"
-#define SKJSONCANVAS_ATTRIBUTE_TEXTSCALEX "textScaleX"
-#define SKJSONCANVAS_ATTRIBUTE_TEXTSKEWX "textSkewX"
-#define SKJSONCANVAS_ATTRIBUTE_DASHING "dashing"
-#define SKJSONCANVAS_ATTRIBUTE_INTERVALS "intervals"
-#define SKJSONCANVAS_ATTRIBUTE_PHASE "phase"
-#define SKJSONCANVAS_ATTRIBUTE_FILLTYPE "fillType"
-#define SKJSONCANVAS_ATTRIBUTE_VERBS "verbs"
-#define SKJSONCANVAS_ATTRIBUTE_NAME "name"
-#define SKJSONCANVAS_ATTRIBUTE_BYTES "bytes"
-#define SKJSONCANVAS_ATTRIBUTE_SHADER "shader"
-#define SKJSONCANVAS_ATTRIBUTE_PATHEFFECT "pathEffect"
-#define SKJSONCANVAS_ATTRIBUTE_MASKFILTER "maskFilter"
-#define SKJSONCANVAS_ATTRIBUTE_XFERMODE "xfermode"
-#define SKJSONCANVAS_ATTRIBUTE_BACKDROP "backdrop"
-#define SKJSONCANVAS_ATTRIBUTE_COLORFILTER "colorfilter"
-#define SKJSONCANVAS_ATTRIBUTE_IMAGEFILTER "imagefilter"
-#define SKJSONCANVAS_ATTRIBUTE_IMAGE "image"
-#define SKJSONCANVAS_ATTRIBUTE_BITMAP "bitmap"
-#define SKJSONCANVAS_ATTRIBUTE_SRC "src"
-#define SKJSONCANVAS_ATTRIBUTE_DST "dst"
-#define SKJSONCANVAS_ATTRIBUTE_STRICT "strict"
-#define SKJSONCANVAS_ATTRIBUTE_DESCRIPTION "description"
-#define SKJSONCANVAS_ATTRIBUTE_X "x"
-#define SKJSONCANVAS_ATTRIBUTE_Y "y"
-#define SKJSONCANVAS_ATTRIBUTE_RUNS "runs"
-#define SKJSONCANVAS_ATTRIBUTE_POSITIONS "positions"
-#define SKJSONCANVAS_ATTRIBUTE_GLYPHS "glyphs"
-#define SKJSONCANVAS_ATTRIBUTE_FONT "font"
-#define SKJSONCANVAS_ATTRIBUTE_TYPEFACE "typeface"
-
-#define SKJSONCANVAS_VERB_MOVE "move"
-#define SKJSONCANVAS_VERB_LINE "line"
-#define SKJSONCANVAS_VERB_QUAD "quad"
-#define SKJSONCANVAS_VERB_CUBIC "cubic"
-#define SKJSONCANVAS_VERB_CONIC "conic"
-#define SKJSONCANVAS_VERB_CLOSE "close"
-
-#define SKJSONCANVAS_STYLE_FILL "fill"
-#define SKJSONCANVAS_STYLE_STROKE "stroke"
-#define SKJSONCANVAS_STYLE_STROKEANDFILL "strokeAndFill"
-
-#define SKJSONCANVAS_POINTMODE_POINTS "points"
-#define SKJSONCANVAS_POINTMODE_LINES "lines"
-#define SKJSONCANVAS_POINTMODE_POLYGON "polygon"
-
-#define SKJSONCANVAS_REGIONOP_DIFFERENCE "difference"
-#define SKJSONCANVAS_REGIONOP_INTERSECT "intersect"
-#define SKJSONCANVAS_REGIONOP_UNION "union"
-#define SKJSONCANVAS_REGIONOP_XOR "xor"
-#define SKJSONCANVAS_REGIONOP_REVERSE_DIFFERENCE "reverseDifference"
-#define SKJSONCANVAS_REGIONOP_REPLACE "replace"
-
-#define SKJSONCANVAS_BLURSTYLE_NORMAL "normal"
-#define SKJSONCANVAS_BLURSTYLE_SOLID "solid"
-#define SKJSONCANVAS_BLURSTYLE_OUTER "outer"
-#define SKJSONCANVAS_BLURSTYLE_INNER "inner"
-
-#define SKJSONCANVAS_BLURQUALITY_LOW "low"
-#define SKJSONCANVAS_BLURQUALITY_HIGH "high"
-
-#define SKJSONCANVAS_ALIGN_LEFT "left"
-#define SKJSONCANVAS_ALIGN_CENTER "center"
-#define SKJSONCANVAS_ALIGN_RIGHT "right"
-
-#define SKJSONCANVAS_FILLTYPE_WINDING "winding"
-#define SKJSONCANVAS_FILLTYPE_EVENODD "evenOdd"
-#define SKJSONCANVAS_FILLTYPE_INVERSEWINDING "inverseWinding"
-#define SKJSONCANVAS_FILLTYPE_INVERSEEVENODD "inverseEvenOdd"
-
-#define SKJSONCANVAS_CAP_BUTT "butt"
-#define SKJSONCANVAS_CAP_ROUND "round"
-#define SKJSONCANVAS_CAP_SQUARE "square"
-
-#define SKJSONCANVAS_COLORTYPE_ARGB4444 "ARGB4444"
-#define SKJSONCANVAS_COLORTYPE_RGBA8888 "RGBA8888"
-#define SKJSONCANVAS_COLORTYPE_BGRA8888 "BGRA8888"
-#define SKJSONCANVAS_COLORTYPE_565 "565"
-#define SKJSONCANVAS_COLORTYPE_GRAY8 "Gray8"
-#define SKJSONCANVAS_COLORTYPE_INDEX8 "Index8"
-#define SKJSONCANVAS_COLORTYPE_ALPHA8 "Alpha8"
-
-#define SKJSONCANVAS_ALPHATYPE_OPAQUE "opaque"
-#define SKJSONCANVAS_ALPHATYPE_PREMUL "premul"
-#define SKJSONCANVAS_ALPHATYPE_UNPREMUL "unpremul"
-
-/*
- * Implementation of SkCanvas which writes JSON when drawn to. The JSON describes all of the draw
- * commands issued to the canvas, and can later be turned back into draw commands using
- * SkJSONRenderer. Be sure to call finish() when you are done drawing.
- */
-class SkJSONCanvas : public SkCanvas {
-public:
- /* Create a canvas which writes to the specified output stream. */
- SkJSONCanvas(int width, int height, SkWStream& out, bool sendBinaries = false);
-
- /* Complete the JSON document. */
- void finish();
-
- static Json::Value MakeMatrix(const SkMatrix& matrix);
-
- static Json::Value MakeIRect(const SkIRect& irect);
-
- // overridden SkCanvas API
-
- void didConcat(const SkMatrix&) override;
-
- void didSetMatrix(const SkMatrix&) override;
-
- void onDrawPaint(const SkPaint&) override;
-
- void onDrawRect(const SkRect&, const SkPaint&) override;
-
- void onDrawOval(const SkRect&, const SkPaint&) override;
-
- void onDrawRRect(const SkRRect&, const SkPaint&) override;
-
- void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override;
-
- void onDrawPoints(SkCanvas::PointMode, size_t count, const SkPoint pts[],
- const SkPaint&) override;
-
- void onDrawVertices(SkCanvas::VertexMode, int vertexCount, const SkPoint vertices[],
- const SkPoint texs[], const SkColor colors[], SkXfermode*,
- const uint16_t indices[], int indexCount, const SkPaint&) override;
-
- void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[],
- int count, SkXfermode::Mode, const SkRect* cull, const SkPaint*) override;
-
- void onDrawPath(const SkPath&, const SkPaint&) override;
-
- void onDrawImage(const SkImage*, SkScalar dx, SkScalar dy, const SkPaint*) override;
-
- void onDrawImageRect(const SkImage*, const SkRect*, const SkRect&, const SkPaint*,
- SrcRectConstraint) override;
-
- void onDrawImageNine(const SkImage*, const SkIRect& center, const SkRect& dst,
- const SkPaint*) override;
-
- void onDrawBitmap(const SkBitmap&, SkScalar dx, SkScalar dy, const SkPaint*) override;
-
- void onDrawBitmapRect(const SkBitmap&, const SkRect*, const SkRect&, const SkPaint*,
- SkCanvas::SrcRectConstraint) override;
-
- void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst,
- const SkPaint*) override;
-
- void onDrawText(const void* text, size_t byteLength, SkScalar x,
- SkScalar y, const SkPaint& paint) override;
-
- void onDrawPosText(const void* text, size_t byteLength,
- const SkPoint pos[], const SkPaint& paint) override;
-
- void onDrawPosTextH(const void* text, size_t byteLength,
- const SkScalar xpos[], SkScalar constY,
- const SkPaint& paint) override;
-
- void onDrawTextOnPath(const void* text, size_t byteLength,
- const SkPath& path, const SkMatrix* matrix,
- const SkPaint& paint) override;
-
- void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
- const SkPaint& paint) override;
-
- void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
- const SkPoint texCoords[4], SkXfermode* xmode, const SkPaint& paint) override;
-
- void onDrawDrawable(SkDrawable*, const SkMatrix*) override;
-
- void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle) override;
-
- void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle) override;
-
- void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle) override;
-
- void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) override;
-
- void willSave() override;
-
- void willRestore() override;
-
- SkCanvas::SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec& rec) override;
-
-private:
- // Helpers to turn values into JSON, these could probably be static
- Json::Value makePoint(const SkPoint& point);
-
- Json::Value makePoint(SkScalar x, SkScalar y);
-
- Json::Value makeRect(const SkRect& rect);
-
- Json::Value makeRRect(const SkRRect& rrect);
-
- Json::Value makePath(const SkPath& path);
-
- Json::Value makeRegion(const SkRegion& region);
-
- Json::Value makePaint(const SkPaint& paint);
-
- Json::Value makeRegionOp(SkRegion::Op op);
-
- Json::Value makeEdgeStyle(SkCanvas::ClipEdgeStyle edgeStyle);
-
- Json::Value makePointMode(SkCanvas::PointMode mode);
-
- void updateMatrix();
-
- SkWStream& fOut;
- Json::Value fRoot;
- Json::Value fCommands;
- bool fSendBinaries;
-
- typedef SkCanvas INHERITED;
-};
-
-#endif
diff --git a/tools/json/SkJSONRenderer.cpp b/tools/json/SkJSONRenderer.cpp
deleted file mode 100644
index 6332b2ae29..0000000000
--- a/tools/json/SkJSONRenderer.cpp
+++ /dev/null
@@ -1,972 +0,0 @@
-/*
- * Copyright 2016 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkJSONRenderer.h"
-
-#include "SkBlurMaskFilter.h"
-#include "SkDashPathEffect.h"
-#include "SkJSONCanvas.h"
-#include "SkJSONCPP.h"
-#include "SkPath.h"
-#include "SkTextBlob.h"
-#include "SkTypeface.h"
-#include "SkValidatingReadBuffer.h"
-
-namespace SkJSONRenderer {
-
-class Renderer {
-public:
- void getPaint(Json::Value& paint, SkPaint* result);
-
- void getRect(Json::Value& rect, SkRect* result);
-
- void getRRect(Json::Value& rrect, SkRRect* result);
-
- void getPath(Json::Value& path, SkPath* result);
-
- void getMatrix(Json::Value& matrix, SkMatrix* result);
-
- SkRegion::Op getRegionOp(Json::Value& op);
-
- void processCommand(Json::Value& command, SkCanvas* target);
-
- void processTranslate(Json::Value& command, SkCanvas* target);
-
- void processScale(Json::Value& command, SkCanvas* target);
-
- void processMatrix(Json::Value& command, SkCanvas* target);
-
- void processSave(Json::Value& command, SkCanvas* target);
-
- void processRestore(Json::Value& command, SkCanvas* target);
-
- void processSaveLayer(Json::Value& command, SkCanvas* target);
-
- void processPaint(Json::Value& command, SkCanvas* target);
-
- void processRect(Json::Value& command, SkCanvas* target);
-
- void processRRect(Json::Value& command, SkCanvas* target);
-
- void processOval(Json::Value& command, SkCanvas* target);
-
- void processPath(Json::Value& command, SkCanvas* target);
-
- void processText(Json::Value& command, SkCanvas* target);
-
- void processPosText(Json::Value& command, SkCanvas* target);
-
- void processTextOnPath(Json::Value& command, SkCanvas* target);
-
- void processTextBlob(Json::Value& command, SkCanvas* target);
-
- void processPoints(Json::Value& command, SkCanvas* target);
-
- void processImage(Json::Value& command, SkCanvas* target);
-
- void processImageRect(Json::Value& command, SkCanvas* target);
-
- void processBitmap(Json::Value& command, SkCanvas* target);
-
- void processBitmapRect(Json::Value& command, SkCanvas* target);
-
- void processClipRect(Json::Value& command, SkCanvas* target);
-
- void processClipRRect(Json::Value& command, SkCanvas* target);
-
- void processClipPath(Json::Value& command, SkCanvas* target);
-};
-
-void Renderer::processCommand(Json::Value& command, SkCanvas* target) {
- const char* name = command[SKJSONCANVAS_COMMAND].asCString();
- // TODO speed this up with a hash
- if (!strcmp(name, SKJSONCANVAS_COMMAND_TRANSLATE)) {
- this->processTranslate(command, target);
- }
- else if (!strcmp(name, SKJSONCANVAS_COMMAND_SCALE)) {
- this->processScale(command, target);
- }
- else if (!strcmp(name, SKJSONCANVAS_COMMAND_MATRIX)) {
- this->processMatrix(command, target);
- }
- else if (!strcmp(name, SKJSONCANVAS_COMMAND_SAVE)) {
- this->processSave(command, target);
- }
- else if (!strcmp(name, SKJSONCANVAS_COMMAND_RESTORE)) {
- this->processRestore(command, target);
- }
- else if (!strcmp(name, SKJSONCANVAS_COMMAND_SAVELAYER)) {
- this->processSaveLayer(command, target);
- }
- else if (!strcmp(name, SKJSONCANVAS_COMMAND_PAINT)) {
- this->processPaint(command, target);
- }
- else if (!strcmp(name, SKJSONCANVAS_COMMAND_RECT)) {
- this->processRect(command, target);
- }
- else if (!strcmp(name, SKJSONCANVAS_COMMAND_RRECT)) {
- this->processRRect(command, target);
- }
- else if (!strcmp(name, SKJSONCANVAS_COMMAND_OVAL)) {
- this->processOval(command, target);
- }
- else if (!strcmp(name, SKJSONCANVAS_COMMAND_PATH)) {
- this->processPath(command, target);
- }
- else if (!strcmp(name, SKJSONCANVAS_COMMAND_TEXT)) {
- this->processText(command, target);
- }
- else if (!strcmp(name, SKJSONCANVAS_COMMAND_POSTEXT)) {
- this->processPosText(command, target);
- }
- else if (!strcmp(name, SKJSONCANVAS_COMMAND_TEXTONPATH)) {
- this->processTextOnPath(command, target);
- }
- else if (!strcmp(name, SKJSONCANVAS_COMMAND_TEXTBLOB)) {
- this->processTextBlob(command, target);
- }
- else if (!strcmp(name, SKJSONCANVAS_COMMAND_POINTS)) {
- this->processPoints(command, target);
- }
- else if (!strcmp(name, SKJSONCANVAS_COMMAND_IMAGE)) {
- this->processImage(command, target);
- }
- else if (!strcmp(name, SKJSONCANVAS_COMMAND_IMAGERECT)) {
- this->processImageRect(command, target);
- }
- else if (!strcmp(name, SKJSONCANVAS_COMMAND_BITMAP)) {
- this->processBitmap(command, target);
- }
- else if (!strcmp(name, SKJSONCANVAS_COMMAND_BITMAPRECT)) {
- this->processBitmapRect(command, target);
- }
- else if (!strcmp(name, SKJSONCANVAS_COMMAND_CLIPRECT)) {
- this->processClipRect(command, target);
- }
- else if (!strcmp(name, SKJSONCANVAS_COMMAND_CLIPRRECT)) {
- this->processClipRRect(command, target);
- }
- else if (!strcmp(name, SKJSONCANVAS_COMMAND_CLIPPATH)) {
- this->processClipPath(command, target);
- }
- else {
- SkDebugf("unsupported JSON command: %s\n", name);
- }
-}
-
-static void apply_paint_color(Json::Value& jsonPaint, SkPaint* target) {
- if (jsonPaint.isMember(SKJSONCANVAS_ATTRIBUTE_COLOR)) {
- Json::Value color = jsonPaint[SKJSONCANVAS_ATTRIBUTE_COLOR];
- target->setColor(SkColorSetARGB(color[0].asInt(), color[1].asInt(), color[2].asInt(),
- color[3].asInt()));
- }
-}
-
-// note that the caller is responsible for freeing the pointer
-static Json::ArrayIndex decode_data(Json::Value bytes, void** target) {
- Json::ArrayIndex size = bytes.size();
- *target = sk_malloc_throw(size);
- for (Json::ArrayIndex i = 0; i < size; i++) {
- ((uint8_t*) *target)[i] = bytes[i].asInt();
- }
- return size;
-}
-
-static SkFlattenable* load_flattenable(Json::Value jsonFlattenable) {
- if (!jsonFlattenable.isMember(SKJSONCANVAS_ATTRIBUTE_NAME)) {
- return nullptr;
- }
- const char* name = jsonFlattenable[SKJSONCANVAS_ATTRIBUTE_NAME].asCString();
- SkFlattenable::Factory factory = SkFlattenable::NameToFactory(name);
- if (factory == nullptr) {
- SkDebugf("no factory for loading '%s'\n", name);
- return nullptr;
- }
- void* data;
- int size = decode_data(jsonFlattenable[SKJSONCANVAS_ATTRIBUTE_BYTES], &data);
- SkValidatingReadBuffer buffer(data, size);
- SkFlattenable* result = factory(buffer);
- free(data);
- if (!buffer.isValid()) {
- SkDebugf("invalid buffer loading flattenable\n");
- return nullptr;
- }
- return result;
-}
-
-static SkColorType colortype_from_name(const char* name) {
- if (!strcmp(name, SKJSONCANVAS_COLORTYPE_ARGB4444)) {
- return kARGB_4444_SkColorType;
- }
- else if (!strcmp(name, SKJSONCANVAS_COLORTYPE_RGBA8888)) {
- return kRGBA_8888_SkColorType;
- }
- else if (!strcmp(name, SKJSONCANVAS_COLORTYPE_BGRA8888)) {
- return kBGRA_8888_SkColorType;
- }
- else if (!strcmp(name, SKJSONCANVAS_COLORTYPE_565)) {
- return kRGB_565_SkColorType;
- }
- else if (!strcmp(name, SKJSONCANVAS_COLORTYPE_GRAY8)) {
- return kGray_8_SkColorType;
- }
- else if (!strcmp(name, SKJSONCANVAS_COLORTYPE_INDEX8)) {
- return kIndex_8_SkColorType;
- }
- else if (!strcmp(name, SKJSONCANVAS_COLORTYPE_ALPHA8)) {
- return kAlpha_8_SkColorType;
- }
- SkASSERT(false);
- return kN32_SkColorType;
-}
-
-static SkBitmap* convert_colortype(SkBitmap* bitmap, SkColorType colorType) {
- if (bitmap->colorType() == colorType ) {
- return bitmap;
- }
- SkBitmap* dst = new SkBitmap();
- if (bitmap->copyTo(dst, colorType)) {
- delete bitmap;
- return dst;
- }
- SkASSERT(false);
- delete dst;
- return bitmap;
-}
-
-// caller is responsible for freeing return value
-static SkBitmap* load_bitmap(const Json::Value& jsonBitmap) {
- if (!jsonBitmap.isMember(SKJSONCANVAS_ATTRIBUTE_BYTES)) {
- SkDebugf("invalid bitmap\n");
- return nullptr;
- }
- void* data;
- int size = decode_data(jsonBitmap[SKJSONCANVAS_ATTRIBUTE_BYTES], &data);
- SkMemoryStream stream(data, size);
- SkImageDecoder* decoder = SkImageDecoder::Factory(&stream);
- SkBitmap* bitmap = new SkBitmap();
- SkImageDecoder::Result result = decoder->decode(&stream, bitmap,
- SkImageDecoder::kDecodePixels_Mode);
- free(decoder);
- if (result != SkImageDecoder::kFailure) {
- free(data);
- if (jsonBitmap.isMember(SKJSONCANVAS_ATTRIBUTE_COLOR)) {
- const char* ctName = jsonBitmap[SKJSONCANVAS_ATTRIBUTE_COLOR].asCString();
- SkColorType ct = colortype_from_name(ctName);
- if (ct != kIndex_8_SkColorType) {
- bitmap = convert_colortype(bitmap, ct);
- }
- }
- return bitmap;
- }
- SkDebugf("image decode failed\n");
- free(data);
- return nullptr;
-}
-
-static SkImage* load_image(const Json::Value& jsonImage) {
- SkBitmap* bitmap = load_bitmap(jsonImage);
- if (bitmap == nullptr) {
- return nullptr;
- }
- SkImage* result = SkImage::NewFromBitmap(*bitmap);
- delete bitmap;
- return result;
-}
-
-static void apply_paint_shader(Json::Value& jsonPaint, SkPaint* target) {
- if (jsonPaint.isMember(SKJSONCANVAS_ATTRIBUTE_SHADER)) {
- Json::Value jsonShader = jsonPaint[SKJSONCANVAS_ATTRIBUTE_SHADER];
- SkShader* shader = (SkShader*) load_flattenable(jsonShader);
- if (shader != nullptr) {
- target->setShader(shader);
- shader->unref();
- }
- }
-}
-
-static void apply_paint_patheffect(Json::Value& jsonPaint, SkPaint* target) {
- if (jsonPaint.isMember(SKJSONCANVAS_ATTRIBUTE_PATHEFFECT)) {
- Json::Value jsonPathEffect = jsonPaint[SKJSONCANVAS_ATTRIBUTE_PATHEFFECT];
- SkPathEffect* pathEffect = (SkPathEffect*) load_flattenable(jsonPathEffect);
- if (pathEffect != nullptr) {
- target->setPathEffect(pathEffect);
- pathEffect->unref();
- }
- }
-}
-
-static void apply_paint_maskfilter(Json::Value& jsonPaint, SkPaint* target) {
- if (jsonPaint.isMember(SKJSONCANVAS_ATTRIBUTE_MASKFILTER)) {
- Json::Value jsonMaskFilter = jsonPaint[SKJSONCANVAS_ATTRIBUTE_MASKFILTER];
- SkMaskFilter* maskFilter = (SkMaskFilter*) load_flattenable(jsonMaskFilter);
- if (maskFilter != nullptr) {
- target->setMaskFilter(maskFilter);
- maskFilter->unref();
- }
- }
-}
-
-static void apply_paint_colorfilter(Json::Value& jsonPaint, SkPaint* target) {
- if (jsonPaint.isMember(SKJSONCANVAS_ATTRIBUTE_COLORFILTER)) {
- Json::Value jsonColorFilter = jsonPaint[SKJSONCANVAS_ATTRIBUTE_COLORFILTER];
- SkColorFilter* colorFilter = (SkColorFilter*) load_flattenable(jsonColorFilter);
- if (colorFilter != nullptr) {
- target->setColorFilter(colorFilter);
- colorFilter->unref();
- }
- }
-}
-
-static void apply_paint_xfermode(Json::Value& jsonPaint, SkPaint* target) {
- if (jsonPaint.isMember(SKJSONCANVAS_ATTRIBUTE_XFERMODE)) {
- Json::Value jsonXfermode = jsonPaint[SKJSONCANVAS_ATTRIBUTE_XFERMODE];
- SkXfermode* xfermode = (SkXfermode*) load_flattenable(jsonXfermode);
- if (xfermode != nullptr) {
- target->setXfermode(xfermode);
- xfermode->unref();
- }
- }
-}
-
-static void apply_paint_imagefilter(Json::Value& jsonPaint, SkPaint* target) {
- if (jsonPaint.isMember(SKJSONCANVAS_ATTRIBUTE_IMAGEFILTER)) {
- Json::Value jsonImageFilter = jsonPaint[SKJSONCANVAS_ATTRIBUTE_IMAGEFILTER];
- SkImageFilter* imageFilter = (SkImageFilter*) load_flattenable(jsonImageFilter);
- if (imageFilter != nullptr) {
- target->setImageFilter(imageFilter);
- imageFilter->unref();
- }
- }
-}
-
-static void apply_paint_style(Json::Value& jsonPaint, SkPaint* target) {
- if (jsonPaint.isMember(SKJSONCANVAS_ATTRIBUTE_STYLE)) {
- const char* style = jsonPaint[SKJSONCANVAS_ATTRIBUTE_STYLE].asCString();
- if (!strcmp(style, SKJSONCANVAS_STYLE_FILL)) {
- target->setStyle(SkPaint::kFill_Style);
- }
- else if (!strcmp(style, SKJSONCANVAS_STYLE_STROKE)) {
- target->setStyle(SkPaint::kStroke_Style);
- }
- else if (!strcmp(style, SKJSONCANVAS_STYLE_STROKEANDFILL)) {
- target->setStyle(SkPaint::kStrokeAndFill_Style);
- }
- }
-}
-
-static void apply_paint_strokewidth(Json::Value& jsonPaint, SkPaint* target) {
- if (jsonPaint.isMember(SKJSONCANVAS_ATTRIBUTE_STROKEWIDTH)) {
- float strokeWidth = jsonPaint[SKJSONCANVAS_ATTRIBUTE_STROKEWIDTH].asFloat();
- target->setStrokeWidth(strokeWidth);
- }
-}
-
-static void apply_paint_strokemiter(Json::Value& jsonPaint, SkPaint* target) {
- if (jsonPaint.isMember(SKJSONCANVAS_ATTRIBUTE_STROKEMITER)) {
- float strokeMiter = jsonPaint[SKJSONCANVAS_ATTRIBUTE_STROKEMITER].asFloat();
- target->setStrokeMiter(strokeMiter);
- }
-}
-
-static void apply_paint_cap(Json::Value& jsonPaint, SkPaint* target) {
- if (jsonPaint.isMember(SKJSONCANVAS_ATTRIBUTE_CAP)) {
- const char* cap = jsonPaint[SKJSONCANVAS_ATTRIBUTE_CAP].asCString();
- if (!strcmp(cap, SKJSONCANVAS_CAP_BUTT)) {
- target->setStrokeCap(SkPaint::kButt_Cap);
- }
- else if (!strcmp(cap, SKJSONCANVAS_CAP_ROUND)) {
- target->setStrokeCap(SkPaint::kRound_Cap);
- }
- else if (!strcmp(cap, SKJSONCANVAS_CAP_SQUARE)) {
- target->setStrokeCap(SkPaint::kSquare_Cap);
- }
- }
-}
-
-static void apply_paint_antialias(Json::Value& jsonPaint, SkPaint* target) {
- if (jsonPaint.isMember(SKJSONCANVAS_ATTRIBUTE_ANTIALIAS)) {
- target->setAntiAlias(jsonPaint[SKJSONCANVAS_ATTRIBUTE_ANTIALIAS].asBool());
- }
-}
-
-static void apply_paint_blur(Json::Value& jsonPaint, SkPaint* target) {
- if (jsonPaint.isMember(SKJSONCANVAS_ATTRIBUTE_BLUR)) {
- Json::Value blur = jsonPaint[SKJSONCANVAS_ATTRIBUTE_BLUR];
- SkScalar sigma = blur[SKJSONCANVAS_ATTRIBUTE_SIGMA].asFloat();
- SkBlurStyle style;
- const char* jsonStyle = blur[SKJSONCANVAS_ATTRIBUTE_STYLE].asCString();
- if (!strcmp(jsonStyle, SKJSONCANVAS_BLURSTYLE_NORMAL)) {
- style = SkBlurStyle::kNormal_SkBlurStyle;
- }
- else if (!strcmp(jsonStyle, SKJSONCANVAS_BLURSTYLE_SOLID)) {
- style = SkBlurStyle::kSolid_SkBlurStyle;
- }
- else if (!strcmp(jsonStyle, SKJSONCANVAS_BLURSTYLE_OUTER)) {
- style = SkBlurStyle::kOuter_SkBlurStyle;
- }
- else if (!strcmp(jsonStyle, SKJSONCANVAS_BLURSTYLE_INNER)) {
- style = SkBlurStyle::kInner_SkBlurStyle;
- }
- else {
- SkASSERT(false);
- style = SkBlurStyle::kNormal_SkBlurStyle;
- }
- SkBlurMaskFilter::BlurFlags flags;
- const char* jsonQuality = blur[SKJSONCANVAS_ATTRIBUTE_QUALITY].asCString();
- if (!strcmp(jsonQuality, SKJSONCANVAS_BLURQUALITY_LOW)) {
- flags = SkBlurMaskFilter::BlurFlags::kNone_BlurFlag;
- }
- else if (!strcmp(jsonQuality, SKJSONCANVAS_BLURQUALITY_HIGH)) {
- flags = SkBlurMaskFilter::BlurFlags::kHighQuality_BlurFlag;
- }
- else {
- SkASSERT(false);
- flags = SkBlurMaskFilter::BlurFlags::kNone_BlurFlag;
- }
- target->setMaskFilter(SkBlurMaskFilter::Create(style, sigma, flags));
- }
-}
-
-static void apply_paint_dashing(Json::Value& jsonPaint, SkPaint* target) {
- if (jsonPaint.isMember(SKJSONCANVAS_ATTRIBUTE_DASHING)) {
- Json::Value dash = jsonPaint[SKJSONCANVAS_ATTRIBUTE_DASHING];
- Json::Value jsonIntervals = dash[SKJSONCANVAS_ATTRIBUTE_INTERVALS];
- Json::ArrayIndex count = jsonIntervals.size();
- SkScalar* intervals = (SkScalar*) sk_malloc_throw(count * sizeof(SkScalar));
- for (Json::ArrayIndex i = 0; i < count; i++) {
- intervals[i] = jsonIntervals[i].asFloat();
- }
- SkScalar phase = dash[SKJSONCANVAS_ATTRIBUTE_PHASE].asFloat();
- target->setPathEffect(SkDashPathEffect::Create(intervals, count, phase));
- free(intervals);
- }
-}
-
-static void apply_paint_textalign(Json::Value& jsonPaint, SkPaint* target) {
- if (jsonPaint.isMember(SKJSONCANVAS_ATTRIBUTE_TEXTALIGN)) {
- SkPaint::Align textAlign;
- const char* jsonAlign = jsonPaint[SKJSONCANVAS_ATTRIBUTE_TEXTALIGN].asCString();
- if (!strcmp(jsonAlign, SKJSONCANVAS_ALIGN_LEFT)) {
- textAlign = SkPaint::kLeft_Align;
- }
- else if (!strcmp(jsonAlign, SKJSONCANVAS_ALIGN_CENTER)) {
- textAlign = SkPaint::kCenter_Align;
- }
- else if (!strcmp(jsonAlign, SKJSONCANVAS_ALIGN_RIGHT)) {
- textAlign = SkPaint::kRight_Align;
- }
- else {
- SkASSERT(false);
- textAlign = SkPaint::kLeft_Align;
- }
- target->setTextAlign(textAlign);
- }
-}
-
-static void apply_paint_textsize(Json::Value& jsonPaint, SkPaint* target) {
- if (jsonPaint.isMember(SKJSONCANVAS_ATTRIBUTE_TEXTSIZE)) {
- float textSize = jsonPaint[SKJSONCANVAS_ATTRIBUTE_TEXTSIZE].asFloat();
- target->setTextSize(textSize);
- }
-}
-
-static void apply_paint_textscalex(Json::Value& jsonPaint, SkPaint* target) {
- if (jsonPaint.isMember(SKJSONCANVAS_ATTRIBUTE_TEXTSCALEX)) {
- float textScaleX = jsonPaint[SKJSONCANVAS_ATTRIBUTE_TEXTSCALEX].asFloat();
- target->setTextScaleX(textScaleX);
- }
-}
-
-static void apply_paint_textskewx(Json::Value& jsonPaint, SkPaint* target) {
- if (jsonPaint.isMember(SKJSONCANVAS_ATTRIBUTE_TEXTSKEWX)) {
- float textSkewX = jsonPaint[SKJSONCANVAS_ATTRIBUTE_TEXTSKEWX].asFloat();
- target->setTextSkewX(textSkewX);
- }
-}
-
-static void apply_paint_typeface(Json::Value& jsonPaint, SkPaint* target) {
- if (jsonPaint.isMember(SKJSONCANVAS_ATTRIBUTE_TYPEFACE)) {
- Json::Value jsonTypeface = jsonPaint[SKJSONCANVAS_ATTRIBUTE_TYPEFACE];
- Json::Value bytes = jsonTypeface[SKJSONCANVAS_ATTRIBUTE_BYTES];
- void* data;
- Json::ArrayIndex length = decode_data(bytes, &data);
- SkMemoryStream buffer(data, length);
- SkTypeface* typeface = SkTypeface::Deserialize(&buffer);
- free(data);
- target->setTypeface(typeface);
- }
-}
-
-void Renderer::getPaint(Json::Value& paint, SkPaint* result) {
- apply_paint_color(paint, result);
- apply_paint_shader(paint, result);
- apply_paint_patheffect(paint, result);
- apply_paint_maskfilter(paint, result);
- apply_paint_colorfilter(paint, result);
- apply_paint_xfermode(paint, result);
- apply_paint_imagefilter(paint, result);
- apply_paint_style(paint, result);
- apply_paint_strokewidth(paint, result);
- apply_paint_strokemiter(paint, result);
- apply_paint_cap(paint, result);
- apply_paint_antialias(paint, result);
- apply_paint_blur(paint, result);
- apply_paint_dashing(paint, result);
- apply_paint_textalign(paint, result);
- apply_paint_textsize(paint, result);
- apply_paint_textscalex(paint, result);
- apply_paint_textskewx(paint, result);
- apply_paint_typeface(paint, result);
-}
-
-void Renderer::getRect(Json::Value& rect, SkRect* result) {
- result->set(rect[0].asFloat(), rect[1].asFloat(), rect[2].asFloat(), rect[3].asFloat());
-}
-
-void Renderer::getRRect(Json::Value& rrect, SkRRect* result) {
- SkVector radii[4] = {
- { rrect[1][0].asFloat(), rrect[1][1].asFloat() },
- { rrect[2][0].asFloat(), rrect[2][1].asFloat() },
- { rrect[3][0].asFloat(), rrect[3][1].asFloat() },
- { rrect[4][0].asFloat(), rrect[4][1].asFloat() }
- };
- result->setRectRadii(SkRect::MakeLTRB(rrect[0][0].asFloat(), rrect[0][1].asFloat(),
- rrect[0][2].asFloat(), rrect[0][3].asFloat()),
- radii);
-}
-
-void Renderer::getMatrix(Json::Value& matrix, SkMatrix* result) {
- SkScalar values[] = {
- matrix[0][0].asFloat(), matrix[0][1].asFloat(), matrix[0][2].asFloat(),
- matrix[1][0].asFloat(), matrix[1][1].asFloat(), matrix[1][2].asFloat(),
- matrix[2][0].asFloat(), matrix[2][1].asFloat(), matrix[2][2].asFloat()
- };
- result->set9(values);
-}
-
-void Renderer::getPath(Json::Value& path, SkPath* result) {
- const char* fillType = path[SKJSONCANVAS_ATTRIBUTE_FILLTYPE].asCString();
- if (!strcmp(fillType, SKJSONCANVAS_FILLTYPE_WINDING)) {
- result->setFillType(SkPath::kWinding_FillType);
- }
- else if (!strcmp(fillType, SKJSONCANVAS_FILLTYPE_EVENODD)) {
- result->setFillType(SkPath::kEvenOdd_FillType);
- }
- else if (!strcmp(fillType, SKJSONCANVAS_FILLTYPE_INVERSEWINDING)) {
- result->setFillType(SkPath::kInverseWinding_FillType);
- }
- else if (!strcmp(fillType, SKJSONCANVAS_FILLTYPE_INVERSEEVENODD)) {
- result->setFillType(SkPath::kInverseEvenOdd_FillType);
- }
- Json::Value verbs = path[SKJSONCANVAS_ATTRIBUTE_VERBS];
- for (Json::ArrayIndex i = 0; i < verbs.size(); i++) {
- Json::Value verb = verbs[i];
- if (verb.isString()) {
- SkASSERT(!strcmp(verb.asCString(), SKJSONCANVAS_VERB_CLOSE));
- result->close();
- }
- else {
- if (verb.isMember(SKJSONCANVAS_VERB_MOVE)) {
- Json::Value move = verb[SKJSONCANVAS_VERB_MOVE];
- result->moveTo(move[0].asFloat(), move[1].asFloat());
- }
- else if (verb.isMember(SKJSONCANVAS_VERB_LINE)) {
- Json::Value line = verb[SKJSONCANVAS_VERB_LINE];
- result->lineTo(line[0].asFloat(), line[1].asFloat());
- }
- else if (verb.isMember(SKJSONCANVAS_VERB_QUAD)) {
- Json::Value quad = verb[SKJSONCANVAS_VERB_QUAD];
- result->quadTo(quad[0][0].asFloat(), quad[0][1].asFloat(),
- quad[1][0].asFloat(), quad[1][1].asFloat());
- }
- else if (verb.isMember(SKJSONCANVAS_VERB_CUBIC)) {
- Json::Value cubic = verb[SKJSONCANVAS_VERB_CUBIC];
- result->cubicTo(cubic[0][0].asFloat(), cubic[0][1].asFloat(),
- cubic[1][0].asFloat(), cubic[1][1].asFloat(),
- cubic[2][0].asFloat(), cubic[2][1].asFloat());
- }
- else if (verb.isMember(SKJSONCANVAS_VERB_CONIC)) {
- Json::Value conic = verb[SKJSONCANVAS_VERB_CONIC];
- result->conicTo(conic[0][0].asFloat(), conic[0][1].asFloat(),
- conic[1][0].asFloat(), conic[1][1].asFloat(),
- conic[2].asFloat());
- }
- else {
- SkASSERT(false);
- }
- }
- }
-}
-
-SkRegion::Op Renderer::getRegionOp(Json::Value& jsonOp) {
- const char* op = jsonOp.asCString();
- if (!strcmp(op, SKJSONCANVAS_REGIONOP_DIFFERENCE)) {
- return SkRegion::kDifference_Op;
- }
- else if (!strcmp(op, SKJSONCANVAS_REGIONOP_INTERSECT)) {
- return SkRegion::kIntersect_Op;
- }
- else if (!strcmp(op, SKJSONCANVAS_REGIONOP_UNION)) {
- return SkRegion::kUnion_Op;
- }
- else if (!strcmp(op, SKJSONCANVAS_REGIONOP_XOR)) {
- return SkRegion::kXOR_Op;
- }
- else if (!strcmp(op, SKJSONCANVAS_REGIONOP_REVERSE_DIFFERENCE)) {
- return SkRegion::kReverseDifference_Op;
- }
- else if (!strcmp(op, SKJSONCANVAS_REGIONOP_REPLACE)) {
- return SkRegion::kReplace_Op;
- }
- SkASSERT(false);
- return SkRegion::kIntersect_Op;
-}
-
-void Renderer::processTranslate(Json::Value& command, SkCanvas* target) {
- target->translate(command[SKJSONCANVAS_ATTRIBUTE_X].asFloat(),
- command[SKJSONCANVAS_ATTRIBUTE_Y].asFloat());
-}
-
-void Renderer::processScale(Json::Value& command, SkCanvas* target) {
- target->scale(command[SKJSONCANVAS_ATTRIBUTE_X].asFloat(),
- command[SKJSONCANVAS_ATTRIBUTE_Y].asFloat());
-}
-
-void Renderer::processMatrix(Json::Value& command, SkCanvas* target) {
- SkMatrix matrix;
- this->getMatrix(command[SKJSONCANVAS_ATTRIBUTE_MATRIX], &matrix);
- target->setMatrix(matrix);
-}
-
-void Renderer::processSave(Json::Value& command, SkCanvas* target) {
- target->save();
-}
-
-void Renderer::processRestore(Json::Value& command, SkCanvas* target) {
- target->restore();
-}
-
-void Renderer::processSaveLayer(Json::Value& command, SkCanvas* target) {
- SkCanvas::SaveLayerRec rec;
- SkRect bounds;
- if (command.isMember(SKJSONCANVAS_ATTRIBUTE_BOUNDS)) {
- this->getRect(command[SKJSONCANVAS_ATTRIBUTE_BOUNDS], &bounds);
- rec.fBounds = &bounds;
- }
- SkPaint paint;
- if (command.isMember(SKJSONCANVAS_ATTRIBUTE_PAINT)) {
- this->getPaint(command[SKJSONCANVAS_ATTRIBUTE_PAINT], &paint);
- rec.fPaint = &paint;
- }
- if (command.isMember(SKJSONCANVAS_ATTRIBUTE_BACKDROP)) {
- rec.fBackdrop = (SkImageFilter*) load_flattenable(command[SKJSONCANVAS_ATTRIBUTE_BACKDROP]);
- }
- target->saveLayer(rec);
- if (rec.fBackdrop != nullptr) {
- rec.fBackdrop->unref();
- }
-}
-
-void Renderer::processPaint(Json::Value& command, SkCanvas* target) {
- SkPaint paint;
- this->getPaint(command[SKJSONCANVAS_ATTRIBUTE_PAINT], &paint);
- target->drawPaint(paint);
-}
-
-void Renderer::processRect(Json::Value& command, SkCanvas* target) {
- SkRect rect;
- this->getRect(command[SKJSONCANVAS_ATTRIBUTE_COORDS], &rect);
- SkPaint paint;
- this->getPaint(command[SKJSONCANVAS_ATTRIBUTE_PAINT], &paint);
- target->drawRect(rect, paint);
-}
-
-void Renderer::processRRect(Json::Value& command, SkCanvas* target) {
- SkRRect rrect;
- this->getRRect(command[SKJSONCANVAS_ATTRIBUTE_COORDS], &rrect);
- SkPaint paint;
- this->getPaint(command[SKJSONCANVAS_ATTRIBUTE_PAINT], &paint);
- target->drawRRect(rrect, paint);
-}
-
-void Renderer::processOval(Json::Value& command, SkCanvas* target) {
- SkRect rect;
- this->getRect(command[SKJSONCANVAS_ATTRIBUTE_COORDS], &rect);
- SkPaint paint;
- this->getPaint(command[SKJSONCANVAS_ATTRIBUTE_PAINT], &paint);
- target->drawOval(rect, paint);
-}
-
-void Renderer::processPath(Json::Value& command, SkCanvas* target) {
- SkPath path;
- this->getPath(command[SKJSONCANVAS_ATTRIBUTE_PATH], &path);
- SkPaint paint;
- this->getPaint(command[SKJSONCANVAS_ATTRIBUTE_PAINT], &paint);
- target->drawPath(path, paint);
-}
-
-void Renderer::processText(Json::Value& command, SkCanvas* target) {
- const char* text = command[SKJSONCANVAS_ATTRIBUTE_TEXT].asCString();
- SkPaint paint;
- this->getPaint(command[SKJSONCANVAS_ATTRIBUTE_PAINT], &paint);
- Json::Value coords = command[SKJSONCANVAS_ATTRIBUTE_COORDS];
- target->drawText(text, strlen(text), coords[0].asFloat(), coords[1].asFloat(), paint);
-}
-
-void Renderer::processPosText(Json::Value& command, SkCanvas* target) {
- const char* text = command[SKJSONCANVAS_ATTRIBUTE_TEXT].asCString();
- SkPaint paint;
- this->getPaint(command[SKJSONCANVAS_ATTRIBUTE_PAINT], &paint);
- Json::Value coords = command[SKJSONCANVAS_ATTRIBUTE_COORDS];
- int count = (int) coords.size();
- SkPoint* points = (SkPoint*) sk_malloc_throw(count * sizeof(SkPoint));
- for (int i = 0; i < count; i++) {
- points[i] = SkPoint::Make(coords[i][0].asFloat(), coords[i][1].asFloat());
- }
- target->drawPosText(text, strlen(text), points, paint);
- free(points);
-}
-
-void Renderer::processTextOnPath(Json::Value& command, SkCanvas* target) {
- const char* text = command[SKJSONCANVAS_ATTRIBUTE_TEXT].asCString();
- SkPath path;
- this->getPath(command[SKJSONCANVAS_ATTRIBUTE_PATH], &path);
- SkMatrix* matrixPtr;
- SkMatrix matrix;
- if (command.isMember(SKJSONCANVAS_ATTRIBUTE_MATRIX)) {
- this->getMatrix(command[SKJSONCANVAS_ATTRIBUTE_MATRIX], &matrix);
- matrixPtr = &matrix;
- }
- else {
- matrixPtr = nullptr;
- }
- SkPaint paint;
- this->getPaint(command[SKJSONCANVAS_ATTRIBUTE_PAINT], &paint);
- target->drawTextOnPath(text, strlen(text), path, matrixPtr, paint);
-}
-
-void Renderer::processTextBlob(Json::Value& command, SkCanvas* target) {
- SkTextBlobBuilder builder;
- Json::Value runs = command[SKJSONCANVAS_ATTRIBUTE_RUNS];
- for (Json::ArrayIndex i = 0 ; i < runs.size(); i++) {
- Json::Value run = runs[i];
- SkPaint font;
- font.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
- this->getPaint(run[SKJSONCANVAS_ATTRIBUTE_FONT], &font);
- Json::Value glyphs = run[SKJSONCANVAS_ATTRIBUTE_GLYPHS];
- int count = glyphs.size();
- Json::Value coords = run[SKJSONCANVAS_ATTRIBUTE_COORDS];
- SkScalar x = coords[0].asFloat();
- SkScalar y = coords[1].asFloat();
- if (run.isMember(SKJSONCANVAS_ATTRIBUTE_POSITIONS)) {
- Json::Value positions = run[SKJSONCANVAS_ATTRIBUTE_POSITIONS];
- if (positions.size() > 0 && positions[0].isNumeric()) {
- SkTextBlobBuilder::RunBuffer buffer = builder.allocRunPosH(font, count, y);
- for (int j = 0; j < count; j++) {
- buffer.glyphs[j] = glyphs[j].asUInt();
- buffer.pos[j] = positions[j].asFloat();
- }
- }
- else {
- SkTextBlobBuilder::RunBuffer buffer = builder.allocRunPos(font, count);
- for (int j = 0; j < count; j++) {
- buffer.glyphs[j] = glyphs[j].asUInt();
- buffer.pos[j * 2] = positions[j][0].asFloat();
- buffer.pos[j * 2 + 1] = positions[j][1].asFloat();
- }
- }
- }
- else {
- SkTextBlobBuilder::RunBuffer buffer = builder.allocRun(font, count, x, y);
- for (int j = 0; j < count; j++) {
- buffer.glyphs[j] = glyphs[j].asUInt();
- }
- }
- }
- SkScalar x = command[SKJSONCANVAS_ATTRIBUTE_X].asFloat();
- SkScalar y = command[SKJSONCANVAS_ATTRIBUTE_Y].asFloat();
- SkPaint paint;
- this->getPaint(command[SKJSONCANVAS_ATTRIBUTE_PAINT], &paint);
- target->drawTextBlob(builder.build(), x, y, paint);
-}
-
-void Renderer::processPoints(Json::Value& command, SkCanvas* target) {
- SkCanvas::PointMode mode;
- const char* jsonMode = command[SKJSONCANVAS_ATTRIBUTE_MODE].asCString();
- if (!strcmp(jsonMode, SKJSONCANVAS_POINTMODE_POINTS)) {
- mode = SkCanvas::kPoints_PointMode;
- }
- else if (!strcmp(jsonMode, SKJSONCANVAS_POINTMODE_LINES)) {
- mode = SkCanvas::kLines_PointMode;
- }
- else if (!strcmp(jsonMode, SKJSONCANVAS_POINTMODE_POLYGON)) {
- mode = SkCanvas::kPolygon_PointMode;
- }
- else {
- SkASSERT(false);
- return;
- }
- Json::Value jsonPoints = command[SKJSONCANVAS_ATTRIBUTE_POINTS];
- int count = (int) jsonPoints.size();
- SkPoint* points = (SkPoint*) sk_malloc_throw(count * sizeof(SkPoint));
- for (int i = 0; i < count; i++) {
- points[i] = SkPoint::Make(jsonPoints[i][0].asFloat(), jsonPoints[i][1].asFloat());
- }
- SkPaint paint;
- this->getPaint(command[SKJSONCANVAS_ATTRIBUTE_PAINT], &paint);
- target->drawPoints(mode, count, points, paint);
- free(points);
-}
-
-void Renderer::processClipRect(Json::Value& command, SkCanvas* target) {
- SkRect rect;
- this->getRect(command[SKJSONCANVAS_ATTRIBUTE_COORDS], &rect);
- target->clipRect(rect, this->getRegionOp(command[SKJSONCANVAS_ATTRIBUTE_REGIONOP]),
- command[SKJSONCANVAS_ATTRIBUTE_ANTIALIAS].asBool());
-}
-
-void Renderer::processClipRRect(Json::Value& command, SkCanvas* target) {
- SkRRect rrect;
- this->getRRect(command[SKJSONCANVAS_ATTRIBUTE_COORDS], &rrect);
- target->clipRRect(rrect, this->getRegionOp(command[SKJSONCANVAS_ATTRIBUTE_REGIONOP]),
- command[SKJSONCANVAS_ATTRIBUTE_ANTIALIAS].asBool());
-}
-
-void Renderer::processClipPath(Json::Value& command, SkCanvas* target) {
- SkPath path;
- this->getPath(command[SKJSONCANVAS_ATTRIBUTE_PATH], &path);
- target->clipPath(path, this->getRegionOp(command[SKJSONCANVAS_ATTRIBUTE_REGIONOP]),
- command[SKJSONCANVAS_ATTRIBUTE_ANTIALIAS].asBool());
-}
-
-void Renderer::processImage(Json::Value& command, SkCanvas* target) {
- SkImage* image = load_image(command[SKJSONCANVAS_ATTRIBUTE_IMAGE]);
- if (image == nullptr) {
- return;
- }
- Json::Value point = command[SKJSONCANVAS_ATTRIBUTE_COORDS];
- SkPaint* paintPtr;
- SkPaint paint;
- if (command.isMember(SKJSONCANVAS_ATTRIBUTE_PAINT)) {
- this->getPaint(command[SKJSONCANVAS_ATTRIBUTE_PAINT], &paint);
- paintPtr = &paint;
- }
- else {
- paintPtr = nullptr;
- }
- target->drawImage(image, point[0].asFloat(), point[1].asFloat(), paintPtr);
- image->unref();
-}
-
-void Renderer::processImageRect(Json::Value& command, SkCanvas* target) {
- SkImage* image = load_image(command[SKJSONCANVAS_ATTRIBUTE_IMAGE]);
- if (image == nullptr) {
- return;
- }
- SkRect dst;
- this->getRect(command[SKJSONCANVAS_ATTRIBUTE_DST], &dst);
- SkPaint* paintPtr;
- SkPaint paint;
- if (command.isMember(SKJSONCANVAS_ATTRIBUTE_PAINT)) {
- this->getPaint(command[SKJSONCANVAS_ATTRIBUTE_PAINT], &paint);
- paintPtr = &paint;
- }
- else {
- paintPtr = nullptr;
- }
- SkCanvas::SrcRectConstraint constraint;
- if (command.isMember(SKJSONCANVAS_ATTRIBUTE_STRICT) &&
- command[SKJSONCANVAS_ATTRIBUTE_STRICT].asBool()) {
- constraint = SkCanvas::kStrict_SrcRectConstraint;
- }
- else {
- constraint = SkCanvas::kFast_SrcRectConstraint;
- }
- if (command.isMember(SKJSONCANVAS_ATTRIBUTE_SRC)) {
- SkRect src;
- this->getRect(command[SKJSONCANVAS_ATTRIBUTE_SRC], &src);
- target->drawImageRect(image, src, dst, paintPtr, constraint);
- }
- else {
- target->drawImageRect(image, dst, paintPtr, constraint);
- }
- image->unref();
-}
-
-void Renderer::processBitmap(Json::Value& command, SkCanvas* target) {
- SkImage* image = load_image(command[SKJSONCANVAS_ATTRIBUTE_BITMAP]);
- if (image == nullptr) {
- return;
- }
- Json::Value point = command[SKJSONCANVAS_ATTRIBUTE_COORDS];
- SkPaint* paintPtr;
- SkPaint paint;
- if (command.isMember(SKJSONCANVAS_ATTRIBUTE_PAINT)) {
- this->getPaint(command[SKJSONCANVAS_ATTRIBUTE_PAINT], &paint);
- paintPtr = &paint;
- }
- else {
- paintPtr = nullptr;
- }
- target->drawImage(image, point[0].asFloat(), point[1].asFloat(), paintPtr);
- image->unref();
-}
-
-void Renderer::processBitmapRect(Json::Value& command, SkCanvas* target) {
- SkBitmap* bitmap = load_bitmap(command[SKJSONCANVAS_ATTRIBUTE_BITMAP]);
- if (bitmap == nullptr) {
- return;
- }
- SkRect dst;
- this->getRect(command[SKJSONCANVAS_ATTRIBUTE_DST], &dst);
- SkPaint* paintPtr;
- SkPaint paint;
- if (command.isMember(SKJSONCANVAS_ATTRIBUTE_PAINT)) {
- this->getPaint(command[SKJSONCANVAS_ATTRIBUTE_PAINT], &paint);
- paintPtr = &paint;
- }
- else {
- paintPtr = nullptr;
- }
- SkCanvas::SrcRectConstraint constraint;
- if (command.isMember(SKJSONCANVAS_ATTRIBUTE_STRICT) &&
- command[SKJSONCANVAS_ATTRIBUTE_STRICT].asBool()) {
- constraint = SkCanvas::kStrict_SrcRectConstraint;
- }
- else {
- constraint = SkCanvas::kFast_SrcRectConstraint;
- }
- if (command.isMember(SKJSONCANVAS_ATTRIBUTE_SRC)) {
- SkRect src;
- this->getRect(command[SKJSONCANVAS_ATTRIBUTE_SRC], &src);
- target->drawBitmapRect(*bitmap, src, dst, paintPtr, constraint);
- }
- else {
- target->drawBitmapRect(*bitmap, dst, paintPtr, constraint);
- }
- free(bitmap);
-}
-
-void render(const char* json, SkCanvas* target) {
- Renderer renderer;
- Json::Reader reader;
- Json::Value root;
- if (reader.parse(std::string(json), root)) {
- SkASSERT(root[SKJSONCANVAS_VERSION].asInt() == 1);
- Json::Value commands = root[SKJSONCANVAS_COMMANDS];
- for (Json::ArrayIndex i = 0; i < commands.size(); i++) {
- renderer.processCommand(commands[i], target);
- }
- }
- else {
- SkDebugf(json);
- SkFAIL("json parse failure");
- }
-}
-
-} // namespace
diff --git a/tools/json/SkJSONRenderer.h b/tools/json/SkJSONRenderer.h
deleted file mode 100644
index 2df2f50673..0000000000
--- a/tools/json/SkJSONRenderer.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright 2016 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkJSONRenderer_DEFINED
-#define SkJSONRenderer_DEFINED
-
-#include "SkCanvas.h"
-
-namespace SkJSONRenderer {
- /*
- * Takes a JSON document produced by SkJSONCanvas and issues its draw commands to the target
- * canvas.
- */
- void render(const char* json, SkCanvas* target);
-}
-
-#endif
diff --git a/tools/kilobench/kilobench.cpp b/tools/kilobench/kilobench.cpp
index 551ff3ef0e..1f92d5341a 100644
--- a/tools/kilobench/kilobench.cpp
+++ b/tools/kilobench/kilobench.cpp
@@ -34,11 +34,6 @@
* support SKPs.
*/
-// To get image decoders linked in we have to do the below magic
-#include "SkForceLinking.h"
-#include "SkImageDecoder.h"
-__SK_FORCE_IMAGE_DECODER_LINKING;
-
static const int kAutoTuneLoops = 0;
static const int kDefaultLoops =
diff --git a/tools/lua/lua_pictures.cpp b/tools/lua/lua_pictures.cpp
index 57b0dcce8e..c526406f1c 100644
--- a/tools/lua/lua_pictures.cpp
+++ b/tools/lua/lua_pictures.cpp
@@ -14,7 +14,6 @@
#include "SkData.h"
#include "picture_utils.h"
#include "SkOSFile.h"
-#include "SkImageDecoder.h"
#include <stdlib.h>
diff --git a/tools/pinspect.cpp b/tools/pinspect.cpp
index b8deba707a..419b2ab5d5 100644
--- a/tools/pinspect.cpp
+++ b/tools/pinspect.cpp
@@ -9,7 +9,6 @@
#include "SkCanvas.h"
#include "SkGraphics.h"
#include "SkOSFile.h"
-#include "SkImageDecoder.h"
#include "SkPicture.h"
#include "SkStream.h"
#include "SkString.h"
diff --git a/tools/skiaserve/skiaserve.cpp b/tools/skiaserve/skiaserve.cpp
index d4a84ac795..0d099e74f2 100644
--- a/tools/skiaserve/skiaserve.cpp
+++ b/tools/skiaserve/skiaserve.cpp
@@ -18,11 +18,6 @@
using namespace Response;
-// To get image decoders linked in we have to do the below magic
-#include "SkForceLinking.h"
-#include "SkImageDecoder.h"
-__SK_FORCE_IMAGE_DECODER_LINKING;
-
DEFINE_int32(port, 8888, "The port to listen on.");
DEFINE_string(address, "localhost", "The address to bind to.");
diff --git a/tools/test_image_decoder.cpp b/tools/test_image_decoder.cpp
deleted file mode 100644
index 106cf782f2..0000000000
--- a/tools/test_image_decoder.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright 2013 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkBitmap.h"
-#include "SkForceLinking.h"
-#include "SkGraphics.h"
-#include "SkImageDecoder.h"
-
-__SK_FORCE_IMAGE_DECODER_LINKING;
-
-/**
- Simple program to test Skia's ability to decode images without
- errors or debug messages. */
-int tool_main(int argc, char** argv);
-int tool_main(int argc, char** argv) {
- if (argc < 2) {
- SkDebugf("Usage:\n %s imagefile\n\n", argv[0]);
- return 3;
- }
- SkAutoGraphics ag; // Enable use of SkRTConfig
- SkBitmap bitmap;
- if (!(SkImageDecoder::DecodeFile(argv[1], &bitmap))) {
- return 2;
- }
- if (bitmap.empty()) {
- return 1;
- }
- return 0;
-}
-
-#if !defined SK_BUILD_FOR_IOS
-int main(int argc, char * const argv[]) {
- return tool_main(argc, (char**) argv);
-}
-#endif