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

Unified Diff: content/renderer/gpu/gpu_benchmarking_extension.cc

Issue 802533005: use new PixelSerializer API, remove legacy flag (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
Index: content/renderer/gpu/gpu_benchmarking_extension.cc
diff --git a/content/renderer/gpu/gpu_benchmarking_extension.cc b/content/renderer/gpu/gpu_benchmarking_extension.cc
index f57a9a781e4249a938f854e04aa17efa6785074a..20468048adff8753793f9605d874d07cb8c2b9e6 100644
--- a/content/renderer/gpu/gpu_benchmarking_extension.cc
+++ b/content/renderer/gpu/gpu_benchmarking_extension.cc
@@ -34,6 +34,7 @@
#include "third_party/skia/include/core/SkGraphics.h"
#include "third_party/skia/include/core/SkPicture.h"
#include "third_party/skia/include/core/SkPixelRef.h"
+#include "third_party/skia/include/core/SkPixelSerializer.h"
#include "third_party/skia/include/core/SkStream.h"
#include "ui/gfx/codec/png_codec.h"
#include "v8/include/v8.h"
@@ -49,21 +50,27 @@ namespace content {
namespace {
-// offset parameter is deprecated/ignored, and will be remove from the
-// signature in a future skia release. <reed@google.com>
-SkData* EncodeBitmapToData(size_t* offset, const SkBitmap& bm) {
- SkPixelRef* pr = bm.pixelRef();
- if (pr != NULL) {
- SkData* data = pr->refEncodedData();
- if (data != NULL)
- return data;
+class PNGSerializer : public SkPixelSerializer {
+ protected:
+ bool onUseEncodedData(const void* data, size_t len) override {
+ // If its already encoded, we are fine with that.
+ return true;
}
- std::vector<unsigned char> vector;
- if (gfx::PNGCodec::EncodeBGRASkBitmap(bm, false, &vector)) {
- return SkData::NewWithCopy(&vector.front(), vector.size());
+
+ SkData* onEncodePixels(const SkImageInfo& info,
+ void* pixels,
+ size_t rowBytes) override {
piman 2014/12/19 20:21:42 nit: row_bytes
reed1 2014/12/19 21:30:02 Done.
+ SkBitmap bm;
+ // The const_cast is fine, since we only read from the bitmap.
+ if (bm.installPixels(info, const_cast<void*>(pixels), rowBytes)) {
piman 2014/12/19 20:21:42 nit: no need for const_cast, pixels is already non
reed1 2014/12/19 21:30:02 A pending change in skia will require this cast (t
+ std::vector<unsigned char> vector;
+ if (gfx::PNGCodec::EncodeBGRASkBitmap(bm, false, &vector)) {
+ return SkData::NewWithCopy(&vector.front(), vector.size());
+ }
+ }
+ return NULL;
}
- return NULL;
-}
+};
class SkPictureSerializer {
public:
@@ -97,7 +104,9 @@ class SkPictureSerializer {
DCHECK(!filepath.empty());
SkFILEWStream file(filepath.c_str());
DCHECK(file.isValid());
- picture->serialize(&file, &EncodeBitmapToData);
+
+ PNGSerializer serializer;
+ picture->serialize(&file, &serializer);
}
private:

Powered by Google App Engine
This is Rietveld 408576698