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

Unified Diff: ui/snapshot/snapshot_async.cc

Issue 2650903003: Revert of [devtools] Support different encodings for Page.CaptureScreenshot. (Closed)
Patch Set: Created 3 years, 11 months 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 | « ui/snapshot/snapshot_async.h ('k') | ui/snapshot/snapshot_aura.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/snapshot/snapshot_async.cc
diff --git a/ui/snapshot/snapshot_async.cc b/ui/snapshot/snapshot_async.cc
index 173f70a56acf24d884f37ef26e05b303efb06936..a4f0eb07bc44b9abab830015667ef94dd1f36eab 100644
--- a/ui/snapshot/snapshot_async.cc
+++ b/ui/snapshot/snapshot_async.cc
@@ -10,6 +10,8 @@
#include "base/task_runner_util.h"
#include "skia/ext/image_operations.h"
#include "third_party/skia/include/core/SkBitmap.h"
+#include "third_party/skia/include/core/SkPixelRef.h"
+#include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/skbitmap_operations.h"
@@ -30,6 +32,29 @@
target_size.width(),
target_size.height(),
static_cast<SkBitmap::Allocator*>(NULL));
+}
+
+scoped_refptr<base::RefCountedBytes> EncodeBitmap(const SkBitmap& bitmap) {
+ scoped_refptr<base::RefCountedBytes> png_data(new base::RefCountedBytes);
+ SkAutoLockPixels lock(bitmap);
+ unsigned char* pixels = reinterpret_cast<unsigned char*>(bitmap.getPixels());
+#if SK_A32_SHIFT == 24 && SK_R32_SHIFT == 16 && SK_G32_SHIFT == 8
+ gfx::PNGCodec::ColorFormat kColorFormat = gfx::PNGCodec::FORMAT_BGRA;
+#elif SK_A32_SHIFT == 24 && SK_B32_SHIFT == 16 && SK_G32_SHIFT == 8
+ gfx::PNGCodec::ColorFormat kColorFormat = gfx::PNGCodec::FORMAT_RGBA;
+#else
+#error Unknown color format
+#endif
+ if (!gfx::PNGCodec::Encode(pixels,
+ kColorFormat,
+ gfx::Size(bitmap.width(), bitmap.height()),
+ base::checked_cast<int>(bitmap.rowBytes()),
+ true,
+ std::vector<gfx::PNGCodec::Comment>(),
+ &png_data->data())) {
+ return scoped_refptr<base::RefCountedBytes>();
+ }
+ return png_data;
}
} // namespace
@@ -55,15 +80,24 @@
base::Bind(&OnFrameScalingFinished, callback));
}
-void SnapshotAsync::RunCallbackWithCopyOutputResult(
- const GrabWindowSnapshotAsyncCallback& callback,
+void SnapshotAsync::EncodeCopyOutputResult(
+ const GrabWindowSnapshotAsyncPNGCallback& callback,
+ scoped_refptr<base::TaskRunner> background_task_runner,
std::unique_ptr<cc::CopyOutputResult> result) {
if (result->IsEmpty()) {
- callback.Run(gfx::Image());
+ callback.Run(scoped_refptr<base::RefCountedBytes>());
return;
}
- callback.Run(gfx::Image::CreateFrom1xBitmap(*result->TakeBitmap()));
+ // TODO(sergeyu): Potentially images can be scaled on GPU before reading it
+ // from GPU. Image scaling is implemented in content::GlHelper, but it's can't
+ // be used here because it's not in content/public. Move the scaling code
+ // somewhere so that it can be reused here.
+ base::PostTaskAndReplyWithResult(
+ background_task_runner.get(),
+ FROM_HERE,
+ base::Bind(EncodeBitmap, *result->TakeBitmap()),
+ callback);
}
} // namespace ui
« no previous file with comments | « ui/snapshot/snapshot_async.h ('k') | ui/snapshot/snapshot_aura.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698