Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

Unified Diff: cc/resources/picture.cc

Issue 802533005: use new PixelSerializer API, remove legacy flag (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix cast Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | content/renderer/gpu/gpu_benchmarking_extension.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/resources/picture.cc
diff --git a/cc/resources/picture.cc b/cc/resources/picture.cc
index 64f29e4cfacb52c2fbd99a3d239fbc278832118c..f956389aa14c7efe993152f5e4c1dc1459d8aa4d 100644
--- a/cc/resources/picture.cc
+++ b/cc/resources/picture.cc
@@ -23,6 +23,7 @@
#include "third_party/skia/include/core/SkData.h"
#include "third_party/skia/include/core/SkPaint.h"
#include "third_party/skia/include/core/SkPictureRecorder.h"
+#include "third_party/skia/include/core/SkPixelSerializer.h"
#include "third_party/skia/include/core/SkStream.h"
#include "third_party/skia/include/utils/SkNullCanvas.h"
#include "third_party/skia/include/utils/SkPictureUtils.h"
@@ -35,36 +36,39 @@ namespace cc {
namespace {
-SkData* EncodeBitmap(size_t* offset, const SkBitmap& bm) {
- const int kJpegQuality = 80;
- std::vector<unsigned char> data;
-
- // If bitmap is opaque, encode as JPEG.
- // Otherwise encode as PNG.
- bool encoding_succeeded = false;
- if (bm.isOpaque()) {
- SkAutoLockPixels lock_bitmap(bm);
- if (bm.empty())
- return NULL;
-
- encoding_succeeded = gfx::JPEGCodec::Encode(
- reinterpret_cast<unsigned char*>(bm.getAddr32(0, 0)),
- gfx::JPEGCodec::FORMAT_SkBitmap,
- bm.width(),
- bm.height(),
- bm.rowBytes(),
- kJpegQuality,
- &data);
- } else {
- encoding_succeeded = gfx::PNGCodec::EncodeBGRASkBitmap(bm, false, &data);
- }
+class BitmapSerializer : public SkPixelSerializer {
+ protected:
+ bool onUseEncodedData(const void* data, size_t len) override { return true; }
+
+ SkData* onEncodePixels(const SkImageInfo& info,
+ const void* pixels,
+ size_t row_bytes) override {
+ const int kJpegQuality = 80;
+ std::vector<unsigned char> data;
+
+ // If bitmap is opaque, encode as JPEG.
+ // Otherwise encode as PNG.
+ bool encoding_succeeded = false;
+ if (info.isOpaque()) {
+ encoding_succeeded =
+ gfx::JPEGCodec::Encode(reinterpret_cast<const unsigned char*>(pixels),
+ gfx::JPEGCodec::FORMAT_SkBitmap, info.width(),
+ info.height(), row_bytes, kJpegQuality, &data);
+ } else {
+ SkBitmap bm;
+ // The cast is ok, since we only read the bm.
+ if (!bm.installPixels(info, const_cast<void*>(pixels), row_bytes)) {
+ return nullptr;
+ }
+ encoding_succeeded = gfx::PNGCodec::EncodeBGRASkBitmap(bm, false, &data);
+ }
- if (encoding_succeeded) {
- *offset = 0;
- return SkData::NewWithCopy(&data.front(), data.size());
+ if (encoding_succeeded) {
+ return SkData::NewWithCopy(&data.front(), data.size());
+ }
+ return nullptr;
}
- return NULL;
-}
+};
bool DecodeBitmap(const void* buffer, size_t size, SkBitmap* bm) {
const unsigned char* data = static_cast<const unsigned char *>(buffer);
@@ -367,7 +371,8 @@ void Picture::Replay(SkCanvas* canvas) {
scoped_ptr<base::Value> Picture::AsValue() const {
SkDynamicMemoryWStream stream;
- picture_->serialize(&stream, &EncodeBitmap);
+ BitmapSerializer serializer;
+ picture_->serialize(&stream, &serializer);
// Encode the picture as base64.
scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue());
« no previous file with comments | « no previous file | content/renderer/gpu/gpu_benchmarking_extension.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698