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

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: 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 | « cc/resources/picture.cc ('k') | skia/config/SkUserConfig.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..a83c02a0a1676e250ab681e5d088668a5660a3a7 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,24 @@ 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;
- }
- std::vector<unsigned char> vector;
- if (gfx::PNGCodec::EncodeBGRASkBitmap(bm, false, &vector)) {
- return SkData::NewWithCopy(&vector.front(), vector.size());
+class PNGSerializer : 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 {
+ SkBitmap bm;
+ // The const_cast is fine, since we only read from the bitmap.
+ if (bm.installPixels(info, const_cast<void*>(pixels), row_bytes)) {
+ std::vector<unsigned char> vector;
+ if (gfx::PNGCodec::EncodeBGRASkBitmap(bm, false, &vector)) {
+ return SkData::NewWithCopy(&vector.front(), vector.size());
+ }
+ }
+ return nullptr;
}
- return NULL;
-}
+};
class SkPictureSerializer {
public:
@@ -97,7 +101,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:
« no previous file with comments | « cc/resources/picture.cc ('k') | skia/config/SkUserConfig.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698