summaryrefslogtreecommitdiffstats
path: root/gpu
diff options
context:
space:
mode:
authorhendrikw <hendrikw@chromium.org>2015-06-17 14:39:04 -0700
committerCommit bot <commit-bot@chromium.org>2015-06-17 21:39:42 +0000
commit6daedb499182a5b6b0bcd54004afb7ebb3c3443b (patch)
tree42b78677d4620a97b6c842af44da649b6b569ce6 /gpu
parent062310c77adfdc909f488f9865e0f033cdce9d0a (diff)
downloadchromium_src-6daedb499182a5b6b0bcd54004afb7ebb3c3443b.zip
chromium_src-6daedb499182a5b6b0bcd54004afb7ebb3c3443b.tar.gz
chromium_src-6daedb499182a5b6b0bcd54004afb7ebb3c3443b.tar.bz2
gpu: play skp files through the command buffer
Small utility program that can take an skp, or directory of skps and GPU rasterizes them to png, through chrome's command buffer. BUG= Review URL: https://codereview.chromium.org/1149893010 Cr-Commit-Position: refs/heads/master@{#334928}
Diffstat (limited to 'gpu')
-rw-r--r--gpu/command_buffer/service/in_process_command_buffer.cc17
-rw-r--r--gpu/skia_runner/BUILD.gn29
-rw-r--r--gpu/skia_runner/DEPS6
-rw-r--r--gpu/skia_runner/in_process_graphics_system.cc150
-rw-r--r--gpu/skia_runner/in_process_graphics_system.h29
-rw-r--r--gpu/skia_runner/sk_picture_rasterizer.cc91
-rw-r--r--gpu/skia_runner/sk_picture_rasterizer.h40
-rw-r--r--gpu/skia_runner/skia_runner.cc221
-rw-r--r--gpu/skia_runner/skia_runner.gyp36
9 files changed, 618 insertions, 1 deletions
diff --git a/gpu/command_buffer/service/in_process_command_buffer.cc b/gpu/command_buffer/service/in_process_command_buffer.cc
index 692fb8e..24628f5 100644
--- a/gpu/command_buffer/service/in_process_command_buffer.cc
+++ b/gpu/command_buffer/service/in_process_command_buffer.cc
@@ -221,6 +221,21 @@ gfx::GpuMemoryBufferHandle ShareGpuMemoryBufferToGpuThread(
}
}
+scoped_refptr<InProcessCommandBuffer::Service> GetInitialService(
+ const scoped_refptr<InProcessCommandBuffer::Service>& service) {
+ if (service)
+ return service;
+
+ // Call base::ThreadTaskRunnerHandle::IsSet() to ensure that it is
+ // instantiated before we create the GPU thread, otherwise shutdown order will
+ // delete the ThreadTaskRunnerHandle before the GPU thread's message loop,
+ // and when the message loop is shutdown, it will recreate
+ // ThreadTaskRunnerHandle, which will re-add a new task to the, AtExitManager,
+ // which causes a deadlock because it's already locked.
+ base::ThreadTaskRunnerHandle::IsSet();
+ return g_default_service.Get().gpu_thread;
+}
+
} // anonyous namespace
InProcessCommandBuffer::Service::Service() {}
@@ -271,7 +286,7 @@ InProcessCommandBuffer::InProcessCommandBuffer(
last_put_offset_(-1),
gpu_memory_buffer_manager_(nullptr),
flush_event_(false, false),
- service_(service.get() ? service : g_default_service.Get().gpu_thread),
+ service_(GetInitialService(service)),
gpu_thread_weak_ptr_factory_(this) {
DCHECK(service_.get());
next_image_id_.GetNext();
diff --git a/gpu/skia_runner/BUILD.gn b/gpu/skia_runner/BUILD.gn
new file mode 100644
index 0000000..b275091
--- /dev/null
+++ b/gpu/skia_runner/BUILD.gn
@@ -0,0 +1,29 @@
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("//build/config/ui.gni")
+
+# GYP version: //gpu/skia_runner/skia_runner.gyp:skia_runner
+executable("skia_runner") {
+ sources = [
+ "in_process_graphics_system.cc",
+ "sk_picture_rasterizer.cc",
+ "skia_runner.cc",
+ ]
+
+ deps = [
+ "//base",
+ "//gpu/command_buffer/common",
+ "//gpu/command_buffer/client:gles2_implementation",
+ "//gpu/command_buffer/client:gl_in_process_context",
+ "//gpu/skia_bindings",
+ "//skia",
+ "//third_party/WebKit/public:blink",
+ "//ui/gfx",
+ "//ui/gl",
+ ]
+
+ configs -= [ "//build/config/compiler:chromium_code" ]
+ configs += [ "//build/config/compiler:no_chromium_code" ]
+}
diff --git a/gpu/skia_runner/DEPS b/gpu/skia_runner/DEPS
new file mode 100644
index 0000000..21e329d
--- /dev/null
+++ b/gpu/skia_runner/DEPS
@@ -0,0 +1,6 @@
+include_rules = [
+ "+third_party/khronos",
+ "+third_party/skia",
+ "+third_party/WebKit/public/platform",
+ "+skia/ext",
+]
diff --git a/gpu/skia_runner/in_process_graphics_system.cc b/gpu/skia_runner/in_process_graphics_system.cc
new file mode 100644
index 0000000..e5294b1
--- /dev/null
+++ b/gpu/skia_runner/in_process_graphics_system.cc
@@ -0,0 +1,150 @@
+// Copyright (c) 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "gpu/skia_runner/in_process_graphics_system.h"
+
+#include <iostream>
+
+#include "base/lazy_instance.h"
+#include "base/memory/discardable_memory.h"
+#include "base/memory/discardable_memory_allocator.h"
+#include "base/thread_task_runner_handle.h"
+#include "gpu/command_buffer/client/gles2_implementation.h"
+#include "gpu/command_buffer/client/gles2_lib.h"
+#include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h"
+#include "third_party/khronos/GLES2/gl2.h"
+#include "third_party/skia/include/gpu/gl/GrGLInterface.h"
+
+namespace {
+
+// TODO(hendrikw): Replace TestDiscardableMemoryAllocator and move to base?
+class NonDiscardableMemory : public base::DiscardableMemory {
+ public:
+ explicit NonDiscardableMemory(size_t size) : data_(new uint8_t[size]) {}
+ bool Lock() override { return false; }
+ void Unlock() override {}
+ void* data() const override { return data_.get(); }
+
+ private:
+ scoped_ptr<uint8_t[]> data_;
+};
+
+class NonDiscardableMemoryAllocator : public base::DiscardableMemoryAllocator {
+ public:
+ // Overridden from DiscardableMemoryAllocator:
+ scoped_ptr<base::DiscardableMemory> AllocateLockedDiscardableMemory(
+ size_t size) override {
+ return make_scoped_ptr(new NonDiscardableMemory(size));
+ }
+};
+
+// Singleton used to initialize and terminate the gles2 library.
+class GLES2Initializer {
+ public:
+ GLES2Initializer() { gles2::Initialize(); }
+ ~GLES2Initializer() { gles2::Terminate(); }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(GLES2Initializer);
+};
+
+base::LazyInstance<GLES2Initializer> g_gles2_initializer =
+ LAZY_INSTANCE_INITIALIZER;
+base::LazyInstance<NonDiscardableMemoryAllocator> g_discardable;
+
+} // namespace anonymous
+
+namespace skia_runner {
+
+void BindContext3DGLContextCallback(const GrGLInterface* gl_interface) {
+ gles2::SetGLContext(reinterpret_cast<gpu::GLInProcessContext*>(
+ gl_interface->fCallbackData)->GetImplementation());
+}
+
+InProcessGraphicsSystem::InProcessGraphicsSystem() {
+ base::DiscardableMemoryAllocator::SetInstance(&g_discardable.Get());
+ g_gles2_initializer.Get();
+
+ if (!gfx::GLSurface::InitializeOneOff()) {
+ LOG(ERROR) << "Unable to initialize gfx::GLSurface.";
+ return;
+ }
+
+ // Create the in process context.
+ in_process_context_ = CreateInProcessContext();
+ if (!in_process_context_) {
+ LOG(ERROR) << "Unable to create in process context.";
+ return;
+ }
+
+ // Create and set up skia's GL bindings.
+ gles2::SetGLContext(in_process_context_->GetImplementation());
+ GrGLInterface* bindings = skia_bindings::CreateCommandBufferSkiaGLBinding();
+ if (!bindings) {
+ LOG(ERROR) << "Unable to create skia command buffer bindings.";
+ return;
+ }
+
+ bindings->fCallback = BindContext3DGLContextCallback;
+ bindings->fCallbackData =
+ reinterpret_cast<GrGLInterfaceCallbackData>(in_process_context_.get());
+
+ // Create skia's graphics context.
+ gr_context_ = skia::AdoptRef(GrContext::Create(
+ kOpenGL_GrBackend, reinterpret_cast<GrBackendContext>(bindings)));
+
+ if (!gr_context_) {
+ LOG(ERROR) << "Unable to create skia graphics context.";
+ return;
+ }
+
+ // Set skia's graphics context cache size.
+ const int kMaxGaneshResourceCacheCount = 2048;
+ const size_t kMaxGaneshResourceCacheBytes = 96 * 1024 * 1024;
+ gr_context_->setResourceCacheLimits(kMaxGaneshResourceCacheCount,
+ kMaxGaneshResourceCacheBytes);
+}
+
+InProcessGraphicsSystem::~InProcessGraphicsSystem() {
+}
+
+bool InProcessGraphicsSystem::IsSuccessfullyInitialized() const {
+ return gr_context_;
+}
+
+int InProcessGraphicsSystem::GetMaxTextureSize() const {
+ int max_texture_size = 0;
+ in_process_context_->GetImplementation()->GetIntegerv(GL_MAX_TEXTURE_SIZE,
+ &max_texture_size);
+ return max_texture_size;
+}
+
+scoped_ptr<gpu::GLInProcessContext>
+InProcessGraphicsSystem::CreateInProcessContext() const {
+ const bool is_offscreen = true;
+ const bool share_resources = true;
+ gpu::gles2::ContextCreationAttribHelper attribs;
+ attribs.alpha_size = 8;
+ attribs.blue_size = 8;
+ attribs.green_size = 8;
+ attribs.red_size = 8;
+ attribs.depth_size = 24;
+ attribs.stencil_size = 8;
+ attribs.samples = 0;
+ attribs.sample_buffers = 0;
+ attribs.fail_if_major_perf_caveat = false;
+ attribs.bind_generates_resource = false;
+ gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu;
+
+ scoped_ptr<gpu::GLInProcessContext> context =
+ make_scoped_ptr(gpu::GLInProcessContext::Create(
+ nullptr, nullptr, is_offscreen, gfx::kNullAcceleratedWidget,
+ gfx::Size(1, 1), nullptr, share_resources, attribs, gpu_preference,
+ gpu::GLInProcessContextSharedMemoryLimits(), nullptr, nullptr));
+
+ DCHECK(context);
+ return context.Pass();
+}
+
+} // namespace skia_runner
diff --git a/gpu/skia_runner/in_process_graphics_system.h b/gpu/skia_runner/in_process_graphics_system.h
new file mode 100644
index 0000000..a2366cc
--- /dev/null
+++ b/gpu/skia_runner/in_process_graphics_system.h
@@ -0,0 +1,29 @@
+// Copyright (c) 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/memory/scoped_ptr.h"
+#include "gpu/command_buffer/client/gl_in_process_context.h"
+#include "skia/ext/refptr.h"
+#include "third_party/skia/include/core/SkPicture.h"
+#include "third_party/skia/include/gpu/GrContext.h"
+
+namespace skia_runner {
+
+class InProcessGraphicsSystem {
+ public:
+ InProcessGraphicsSystem();
+ ~InProcessGraphicsSystem();
+
+ bool IsSuccessfullyInitialized() const;
+ skia::RefPtr<GrContext> GetGrContext() const { return gr_context_; }
+ int GetMaxTextureSize() const;
+
+ private:
+ scoped_ptr<gpu::GLInProcessContext> CreateInProcessContext() const;
+
+ scoped_ptr<gpu::GLInProcessContext> in_process_context_;
+ skia::RefPtr<GrContext> gr_context_;
+};
+
+} // namespace skia_runner
diff --git a/gpu/skia_runner/sk_picture_rasterizer.cc b/gpu/skia_runner/sk_picture_rasterizer.cc
new file mode 100644
index 0000000..dbd1f49
--- /dev/null
+++ b/gpu/skia_runner/sk_picture_rasterizer.cc
@@ -0,0 +1,91 @@
+// Copyright (c) 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "gpu/skia_runner/sk_picture_rasterizer.h"
+
+#include <iostream>
+
+#include "third_party/skia/include/core/SkCanvas.h"
+#include "third_party/skia/include/core/SkSurface.h"
+#include "third_party/skia/include/core/SkSurfaceProps.h"
+
+namespace skia_runner {
+
+SkPictureRasterizer::SkPictureRasterizer(skia::RefPtr<GrContext> gr_context,
+ int max_texture_size)
+ : use_lcd_text_(false),
+ use_distance_field_text_(false),
+ msaa_sample_count_(0),
+ max_texture_size_(max_texture_size),
+ gr_context_(gr_context) {
+}
+
+SkPictureRasterizer::~SkPictureRasterizer() {
+}
+
+skia::RefPtr<SkImage> SkPictureRasterizer::RasterizeTile(
+ const SkPicture* picture,
+ const SkRect& rect) const {
+ DCHECK(gr_context_);
+
+ SkImageInfo info = SkImageInfo::MakeN32Premul(rect.width(), rect.height());
+ uint32_t flags = 0;
+ if (use_distance_field_text_)
+ flags = SkSurfaceProps::kUseDistanceFieldFonts_Flag;
+
+ SkSurfaceProps surface_props =
+ use_lcd_text_
+ ? SkSurfaceProps(flags, SkSurfaceProps::kLegacyFontHost_InitType)
+ : SkSurfaceProps(flags, kUnknown_SkPixelGeometry);
+
+ skia::RefPtr<SkSurface> sk_surface(skia::AdoptRef(
+ SkSurface::NewRenderTarget(gr_context_.get(), SkSurface::kYes_Budgeted,
+ info, msaa_sample_count_, &surface_props)));
+ if (sk_surface) {
+ SkCanvas* canvas = sk_surface->getCanvas();
+ canvas->translate(-rect.left(), -rect.top());
+ canvas->drawPicture(picture);
+
+ return skia::AdoptRef(sk_surface->newImageSnapshot());
+ }
+ return nullptr;
+}
+
+skia::RefPtr<SkImage> SkPictureRasterizer::Rasterize(
+ const SkPicture* picture) const {
+ if (!gr_context_)
+ return nullptr;
+
+ SkRect picture_rect = picture->cullRect();
+ if (picture_rect.width() <= max_texture_size_ &&
+ picture_rect.height() <= max_texture_size_)
+ return RasterizeTile(picture, picture_rect);
+
+ SkImageInfo info =
+ SkImageInfo::MakeN32Premul(picture_rect.width(), picture_rect.height());
+
+ skia::RefPtr<SkSurface> sk_surface(
+ skia::AdoptRef(SkSurface::NewRaster(info)));
+ SkCanvas* canvas = sk_surface->getCanvas();
+
+ int num_tiles_x = picture_rect.width() / max_texture_size_ + 1;
+ int num_tiles_y = picture_rect.height() / max_texture_size_ + 1;
+ for (int y = 0; y < num_tiles_y; ++y) {
+ SkRect tile_rect;
+ tile_rect.fTop = picture_rect.top() + y * max_texture_size_;
+ tile_rect.fBottom =
+ std::min(tile_rect.fTop + max_texture_size_, picture_rect.bottom());
+ for (int x = 0; x < num_tiles_x; ++x) {
+ tile_rect.fLeft = picture_rect.left() + x * max_texture_size_;
+ tile_rect.fRight =
+ std::min(tile_rect.fLeft + max_texture_size_, picture_rect.right());
+ skia::RefPtr<SkImage> tile(RasterizeTile(picture, tile_rect));
+ // canvas.drawBitmap(tile, tile_rect.left(), tile_rect.top());
+ canvas->drawImage(tile.get(), tile_rect.left(), tile_rect.top());
+ }
+ }
+ return skia::AdoptRef(sk_surface->newImageSnapshot());
+}
+
+} // namepsace skia_runner
diff --git a/gpu/skia_runner/sk_picture_rasterizer.h b/gpu/skia_runner/sk_picture_rasterizer.h
new file mode 100644
index 0000000..380bfa0
--- /dev/null
+++ b/gpu/skia_runner/sk_picture_rasterizer.h
@@ -0,0 +1,40 @@
+// Copyright (c) 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/memory/scoped_ptr.h"
+#include "gpu/command_buffer/client/gl_in_process_context.h"
+#include "skia/ext/refptr.h"
+#include "third_party/skia/include/core/SkPicture.h"
+#include "third_party/skia/include/gpu/GrContext.h"
+
+namespace skia_runner {
+
+class SkPictureRasterizer {
+ public:
+ SkPictureRasterizer(skia::RefPtr<GrContext> gr_context, int max_texture_size);
+ ~SkPictureRasterizer();
+
+ skia::RefPtr<SkImage> Rasterize(const SkPicture* picture) const;
+
+ void set_msaa_sample_count(int msaa_sample_count) {
+ msaa_sample_count_ = msaa_sample_count;
+ }
+ void set_use_lcd_text(bool use_lcd_text) { use_lcd_text_ = use_lcd_text; }
+ void set_use_distance_field_text(bool use_distance_field_text) {
+ use_distance_field_text_ = use_distance_field_text;
+ }
+
+ private:
+ skia::RefPtr<SkImage> RasterizeTile(const SkPicture* picture,
+ const SkRect& rect) const;
+
+ bool use_lcd_text_;
+ bool use_distance_field_text_;
+ int msaa_sample_count_;
+
+ int max_texture_size_;
+ skia::RefPtr<GrContext> gr_context_;
+};
+
+} // namespace skia_runner
diff --git a/gpu/skia_runner/skia_runner.cc b/gpu/skia_runner/skia_runner.cc
new file mode 100644
index 0000000..a5efc7d
--- /dev/null
+++ b/gpu/skia_runner/skia_runner.cc
@@ -0,0 +1,221 @@
+// Copyright (c) 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <iostream>
+
+#include "base/at_exit.h"
+#include "base/command_line.h"
+#include "base/files/file_enumerator.h"
+#include "base/files/file_util.h"
+#include "base/strings/string_number_conversions.h"
+#include "gpu/skia_runner/in_process_graphics_system.h"
+#include "gpu/skia_runner/sk_picture_rasterizer.h"
+#include "third_party/WebKit/public/platform/WebData.h"
+#include "third_party/WebKit/public/platform/WebImage.h"
+#include "third_party/WebKit/public/platform/WebSize.h"
+#include "third_party/skia/include/core/SkOSFile.h"
+#include "third_party/skia/include/core/SkPicture.h"
+#include "third_party/skia/include/core/SkStream.h"
+#include "ui/gfx/codec/png_codec.h"
+
+namespace {
+
+bool WriteSkImagePNG(const SkImage* image, const base::FilePath& path) {
+ DCHECK(!path.empty());
+
+ if (!image) {
+ std::cout << "Unable to write empty bitmap for " << path.value() << ".\n";
+ return false;
+ }
+
+ std::string file_path = path.MaybeAsASCII();
+ SkFILEWStream stream(file_path.c_str());
+ if (!stream.isValid()) {
+ std::cout << "Unable to write to " << file_path.c_str() << ".\n";
+ return false;
+ }
+
+ SkImageInfo info = SkImageInfo::Make(image->width(), image->height(),
+ SkColorType::kBGRA_8888_SkColorType,
+ SkAlphaType::kPremul_SkAlphaType);
+ SkImageInfo::MakeN32Premul(image->width(), image->height());
+
+ const size_t rowBytes = image->width() * sizeof(SkPMColor);
+ std::vector<SkPMColor> pixels(image->width() * image->height());
+
+ if (image->readPixels(info, pixels.data(), rowBytes, 0, 0)) {
+ std::vector<unsigned char> png_data;
+
+ if (gfx::PNGCodec::Encode(
+ reinterpret_cast<const unsigned char*>(pixels.data()),
+ gfx::PNGCodec::FORMAT_BGRA,
+ gfx::Size(image->width(), image->height()),
+ static_cast<int>(rowBytes), false,
+ std::vector<gfx::PNGCodec::Comment>(), &png_data)) {
+ if (stream.write(png_data.data(), png_data.size())) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
+bool onDecode(const void* buffer, size_t size, SkBitmap* bm) {
+ blink::WebData web_data(static_cast<const char*>(buffer), size);
+ blink::WebImage image = blink::WebImage::fromData(web_data, blink::WebSize());
+ if (!image.isNull()) {
+ *bm = image.getSkBitmap();
+ return true;
+ }
+ std::cout << "Error decoding image.\n";
+ return false;
+}
+
+skia::RefPtr<SkPicture> ReadPicture(const base::FilePath& path) {
+ skia::RefPtr<SkPicture> picture;
+ std::string file_path = path.MaybeAsASCII();
+ SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(file_path.c_str()));
+ if (!stream.get()) {
+ std::cout << "Unable to read " << file_path.c_str() << ".\n";
+ return picture;
+ }
+
+ picture = skia::AdoptRef(SkPicture::CreateFromStream(stream.get(), onDecode));
+ if (!picture) {
+ std::cout << "Unable to load " << file_path.c_str()
+ << " as an SkPicture.\n";
+ }
+ return picture;
+}
+
+base::FilePath MakeDestinationFilename(
+ base::FilePath source_file,
+ base::FilePath destination_folder,
+ base::FilePath::StringType new_extension) {
+ base::FilePath filename = source_file.BaseName().RemoveExtension();
+ filename = filename.AddExtension(new_extension);
+ return destination_folder.AsEndingWithSeparator().Append(filename);
+}
+
+std::vector<std::pair<base::FilePath, base::FilePath>> GetSkpsToRasterize(
+ base::FilePath input_path,
+ base::FilePath output_path) {
+ std::vector<std::pair<base::FilePath, base::FilePath>> files;
+
+ if (base::DirectoryExists(input_path)) {
+ if (!base::DirectoryExists(output_path)) {
+ return files;
+ }
+ base::FilePath::StringType extension = FILE_PATH_LITERAL(".skp");
+ base::FileEnumerator file_iter(input_path, false,
+ base::FileEnumerator::FILES);
+ while (!file_iter.Next().empty()) {
+ if (file_iter.GetInfo().GetName().MatchesExtension(extension)) {
+ base::FilePath skp_file = file_iter.GetInfo().GetName();
+ skp_file = input_path.AsEndingWithSeparator().Append(skp_file);
+ base::FilePath png_file = MakeDestinationFilename(
+ skp_file, output_path, FILE_PATH_LITERAL("png"));
+ files.push_back(std::make_pair(skp_file, png_file));
+ }
+ }
+ } else {
+ // Single file passed. If the output file is a folder, make a name.
+ if (base::DirectoryExists(output_path)) {
+ output_path = MakeDestinationFilename(input_path, output_path,
+ FILE_PATH_LITERAL("png"));
+ }
+ files.push_back(std::make_pair(input_path, output_path));
+ }
+ return files;
+}
+
+static const char kHelpMessage[] =
+ "This program renders a skia SKP to a PNG using GPU rasterization via the\n"
+ "command buffer.\n\n"
+ "following command line flags to control its behavior:\n"
+ "\n"
+ " --in-skp=skp[:DIRECTORY_PATH|FILE_PATH]\n"
+ " Input SKP file. If a directory is provided, all SKP files will be\n"
+ " converted.\n"
+ " --out-png=png[:DIRECTORY_PATH|:FILE_PATH]\n"
+ " Output PNG file. If a directory is provided, the SKP filename is "
+ "used.\n\n"
+ " --use-lcd-text\n"
+ " Turn on lcd text rendering.\n"
+ " --use-distance-field-text\n"
+ " Turn on distance field text rendering.\n"
+ " --msaa-sample-count=(0|2|4|8|16)\n"
+ " Turn on multi-sample anti-aliasing.\n"
+ " --use-gl=(desktop|osmesa|egl|swiftshader)\n"
+ " Specify Gl driver. --swiftshader-path required for swiftshader.\n";
+
+} // namespace anonymous
+
+int main(int argc, char** argv) {
+ base::AtExitManager exit_manager;
+ base::CommandLine::Init(argc, argv);
+#if defined(OS_MACOSX)
+ base::mac::ScopedNSAutoreleasePool autorelease_pool;
+#endif
+ base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
+ base::FilePath input_path(command_line->GetSwitchValuePath("in-skp"));
+ base::FilePath output_path(command_line->GetSwitchValuePath("out-png"));
+
+ if (input_path.empty() || output_path.empty()) {
+ std::cout << kHelpMessage;
+ return 0;
+ }
+
+ std::vector<std::pair<base::FilePath, base::FilePath>> files =
+ GetSkpsToRasterize(input_path, output_path);
+
+ if (files.empty()) {
+ if (!base::DirectoryExists(output_path))
+ std::cout << "You must specify an existing directory using '--out-png'\n";
+ else
+ std::cout << "No skp files found at " << input_path.value() << "\n";
+ return 0;
+ }
+
+ skia_runner::InProcessGraphicsSystem graphics_system;
+ if (!graphics_system.IsSuccessfullyInitialized()) {
+ LOG(ERROR) << "Unable to initialize rasterizer.";
+ return 0;
+ }
+
+ skia_runner::SkPictureRasterizer picture_rasterizer(
+ graphics_system.GetGrContext(), graphics_system.GetMaxTextureSize());
+
+ // Set up command-line render options.
+ picture_rasterizer.set_use_lcd_text(command_line->HasSwitch("use-lcd-text"));
+ picture_rasterizer.set_use_distance_field_text(
+ command_line->HasSwitch("use-distance-field-text"));
+
+ if (command_line->HasSwitch("msaa-sample-count")) {
+ std::string value = command_line->GetSwitchValueASCII("msaa-sample-count");
+ int msaa = 0;
+ if (base::StringToInt(value, &msaa))
+ picture_rasterizer.set_msaa_sample_count(msaa);
+
+ if (msaa != 0 && msaa != 2 && msaa != 4 && msaa != 8 && msaa != 16) {
+ std::cout << "Error: msaa sample count must be 0, 2, 4, 8 or 16.\n";
+ return 0;
+ }
+ }
+
+ for (auto file_pair : files) {
+ skia::RefPtr<SkPicture> picture = ReadPicture(file_pair.first);
+ if (!picture) {
+ std::cout << "Error reading: " << file_pair.first.value() << "\n";
+ continue;
+ }
+
+ skia::RefPtr<SkImage> image(picture_rasterizer.Rasterize(picture.get()));
+ if (!WriteSkImagePNG(image.get(), file_pair.second))
+ std::cout << "Error writing: " << file_pair.second.value() << "\n";
+ else
+ std::cout << file_pair.second.value() << " successfully created.\n";
+ }
+}
diff --git a/gpu/skia_runner/skia_runner.gyp b/gpu/skia_runner/skia_runner.gyp
new file mode 100644
index 0000000..1a07caa
--- /dev/null
+++ b/gpu/skia_runner/skia_runner.gyp
@@ -0,0 +1,36 @@
+# Copyright (c) 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+{
+ 'variables': {
+ 'chromium_code': 1,
+ },
+ 'targets': [
+ {
+ # GN version: //gpu:skia_runner
+ 'target_name': 'skia_runner',
+ 'type': 'executable',
+ 'dependencies': [
+ '../../base/base.gyp:base',
+ '../../gpu/command_buffer/command_buffer.gyp:gles2_utils',
+ '../../gpu/gpu.gyp:command_buffer_service',
+ '../../gpu/gpu.gyp:gles2_implementation',
+ '../../gpu/gpu.gyp:gl_in_process_context',
+ '../../gpu/skia_bindings/skia_bindings.gyp:gpu_skia_bindings',
+ '../../skia/skia.gyp:skia',
+ '../../third_party/WebKit/public/blink.gyp:blink',
+ '../../ui/gfx/gfx.gyp:gfx',
+ '../../ui/gl/gl.gyp:gl',
+ ],
+ 'sources': [
+ # Note: sources list duplicated in GN build.
+ 'in_process_graphics_system.cc',
+ 'in_process_graphics_system.h',
+ 'sk_picture_rasterizer.cc',
+ 'sk_picture_rasterizer.h',
+ 'skia_runner.cc',
+ ],
+ },
+ ],
+}