summaryrefslogtreecommitdiffstats
path: root/blimp/client
diff options
context:
space:
mode:
authornyquist <nyquist@chromium.org>2016-02-17 15:42:18 -0800
committerCommit bot <commit-bot@chromium.org>2016-02-17 23:44:43 +0000
commit6c3ec5f996e1d405bec3bf7dd46eaba4ae5f2a80 (patch)
tree8b51160c82328b2b25cfd6fe88434dd26930bda1 /blimp/client
parentd4206333fde9b065df62e60ada7459593dca2b08 (diff)
downloadchromium_src-6c3ec5f996e1d405bec3bf7dd46eaba4ae5f2a80.zip
chromium_src-6c3ec5f996e1d405bec3bf7dd46eaba4ae5f2a80.tar.gz
chromium_src-6c3ec5f996e1d405bec3bf7dd46eaba4ae5f2a80.tar.bz2
Add support for encoding/decoding WebP images.
This CL adds support for always encoding all images within SkPicture to WebP. On the decoding side it also assumes that the input will be WebP. The pixels from Skia are premultiplied, but the import functions available from WebP only supports un-premultiplied data, so the code unpremultiples the values during the encoding step. Also, the quality and method configuration is hard coded since any change in it would change the hash of the data. Also, the alpha-channel is always used, since the WebP encoder will optimize the alpha-channel if all values are 255. BUG=577262 Review URL: https://codereview.chromium.org/1680333004 Cr-Commit-Position: refs/heads/master@{#376034}
Diffstat (limited to 'blimp/client')
-rw-r--r--blimp/client/BUILD.gn3
-rw-r--r--blimp/client/DEPS1
-rw-r--r--blimp/client/app/blimp_startup.cc9
-rw-r--r--blimp/client/feature/compositor/decoding_image_generator.cc58
-rw-r--r--blimp/client/feature/compositor/decoding_image_generator.h47
5 files changed, 118 insertions, 0 deletions
diff --git a/blimp/client/BUILD.gn b/blimp/client/BUILD.gn
index e817cd3..d629ef8 100644
--- a/blimp/client/BUILD.gn
+++ b/blimp/client/BUILD.gn
@@ -38,6 +38,7 @@ source_set("blimp_client") {
"//cc",
"//gpu/skia_bindings",
"//net",
+ "//third_party/libwebp",
"//ui/gfx/geometry",
"//url:url",
]
@@ -76,6 +77,8 @@ source_set("feature") {
"feature/compositor/blimp_layer_tree_settings.h",
"feature/compositor/blimp_output_surface.cc",
"feature/compositor/blimp_output_surface.h",
+ "feature/compositor/decoding_image_generator.cc",
+ "feature/compositor/decoding_image_generator.h",
"feature/navigation_feature.cc",
"feature/navigation_feature.h",
"feature/render_widget_feature.cc",
diff --git a/blimp/client/DEPS b/blimp/client/DEPS
index e334a8c..06e3f96 100644
--- a/blimp/client/DEPS
+++ b/blimp/client/DEPS
@@ -8,6 +8,7 @@ include_rules = [
"+jni",
"+net/base",
"+skia",
+ "+third_party/libwebp",
"+third_party/skia",
"+third_party/WebKit/public/web/WebInputEvent.h",
"+ui/events",
diff --git a/blimp/client/app/blimp_startup.cc b/blimp/client/app/blimp_startup.cc
index 0d1f187..e19ee3f 100644
--- a/blimp/client/app/blimp_startup.cc
+++ b/blimp/client/app/blimp_startup.cc
@@ -10,17 +10,25 @@
#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
#include "blimp/client/app/blimp_discardable_memory_allocator.h"
+#include "blimp/client/feature/compositor/decoding_image_generator.h"
#include "third_party/skia/include/core/SkGraphics.h"
#include "ui/gl/gl_surface.h"
+class SkImageGenerator;
+
namespace {
base::LazyInstance<scoped_ptr<base::MessageLoopForUI>> g_main_message_loop =
LAZY_INSTANCE_INITIALIZER;
base::LazyInstance<blimp::client::BlimpDiscardableMemoryAllocator>
g_discardable_memory_allocator = LAZY_INSTANCE_INITIALIZER;
+
+SkImageGenerator* CreateImageGenerator(SkData* data) {
+ return blimp::client::DecodingImageGenerator::create(data);
}
+} // namespace
+
namespace blimp {
namespace client {
@@ -54,6 +62,7 @@ bool InitializeMainMessageLoop() {
if (!gfx::GLSurface::InitializeOneOff())
return false;
SkGraphics::Init();
+ SkGraphics::SetImageGeneratorFromEncodedFactory(CreateImageGenerator);
g_main_message_loop.Get().reset(new base::MessageLoopForUI);
return true;
}
diff --git a/blimp/client/feature/compositor/decoding_image_generator.cc b/blimp/client/feature/compositor/decoding_image_generator.cc
new file mode 100644
index 0000000..b2239c5
--- /dev/null
+++ b/blimp/client/feature/compositor/decoding_image_generator.cc
@@ -0,0 +1,58 @@
+// Copyright 2016 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 "blimp/client/feature/compositor/decoding_image_generator.h"
+
+#include "blimp/common/compositor/webp_decoder.h"
+#include "third_party/libwebp/webp/decode.h"
+#include "third_party/libwebp/webp/demux.h"
+#include "third_party/skia/include/core/SkData.h"
+
+namespace blimp {
+namespace client {
+
+SkImageGenerator* DecodingImageGenerator::create(SkData* data) {
+ WebPData inputData = {reinterpret_cast<const uint8_t*>(data->data()),
+ data->size()};
+ WebPDemuxState demuxState(WEBP_DEMUX_PARSING_HEADER);
+ WebPDemuxer* demux = WebPDemuxPartial(&inputData, &demuxState);
+
+ uint32_t width = WebPDemuxGetI(demux, WEBP_FF_CANVAS_WIDTH);
+ uint32_t height = WebPDemuxGetI(demux, WEBP_FF_CANVAS_HEIGHT);
+
+ const SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
+ return new DecodingImageGenerator(info, data->data(), data->size());
+}
+
+DecodingImageGenerator::DecodingImageGenerator(const SkImageInfo info,
+ const void* data,
+ size_t size)
+ : SkImageGenerator(info) {
+ WebPDecoder(data, size, &decoded_bitmap_);
+}
+
+DecodingImageGenerator::~DecodingImageGenerator() {}
+
+bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info,
+ void* pixels,
+ size_t rowBytes,
+ SkPMColor table[],
+ int* tableCount) {
+ SkAutoLockPixels bitmapLock(decoded_bitmap_);
+ if (decoded_bitmap_.getPixels() != pixels) {
+ return decoded_bitmap_.copyPixelsTo(pixels, rowBytes * info.height(),
+ rowBytes);
+ }
+ return true;
+}
+
+bool DecodingImageGenerator::onGetYUV8Planes(SkISize sizes[3],
+ void* planes[3],
+ size_t rowBytes[3],
+ SkYUVColorSpace*) {
+ return false;
+}
+
+} // namespace client
+} // namespace blimp
diff --git a/blimp/client/feature/compositor/decoding_image_generator.h b/blimp/client/feature/compositor/decoding_image_generator.h
new file mode 100644
index 0000000..1062cb8
--- /dev/null
+++ b/blimp/client/feature/compositor/decoding_image_generator.h
@@ -0,0 +1,47 @@
+// Copyright 2016 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.
+
+#ifndef BLIMP_CLIENT_FEATURE_COMPOSITOR_DECODING_IMAGE_GENERATOR_H_
+#define BLIMP_CLIENT_FEATURE_COMPOSITOR_DECODING_IMAGE_GENERATOR_H_
+
+#include "base/macros.h"
+#include "third_party/skia/include/core/SkImageGenerator.h"
+#include "third_party/skia/include/core/SkImageInfo.h"
+
+class SkData;
+
+namespace blimp {
+namespace client {
+
+class DecodingImageGenerator : public SkImageGenerator {
+ public:
+ static SkImageGenerator* create(SkData* data);
+ explicit DecodingImageGenerator(const SkImageInfo info,
+ const void* data,
+ size_t size);
+ ~DecodingImageGenerator() override;
+
+ protected:
+ // SkImageGenerator implementation.
+ bool onGetPixels(const SkImageInfo&,
+ void* pixels,
+ size_t rowBytes,
+ SkPMColor table[],
+ int* tableCount) override;
+
+ bool onGetYUV8Planes(SkISize sizes[3],
+ void* planes[3],
+ size_t rowBytes[3],
+ SkYUVColorSpace*) override;
+
+ private:
+ SkBitmap decoded_bitmap_;
+
+ DISALLOW_COPY_AND_ASSIGN(DecodingImageGenerator);
+};
+
+} // namespace client
+} // namespace blimp
+
+#endif // BLIMP_CLIENT_FEATURE_COMPOSITOR_DECODING_IMAGE_GENERATOR_H_