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

Unified Diff: chrome/browser/image_decoder.h

Issue 865543002: WIP: Browser image decoding using Mojo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup and add DecodeImageBase64. Created 5 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 | « chrome/browser/extensions/webstore_install_helper.cc ('k') | chrome/browser/image_decoder.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/image_decoder.h
diff --git a/chrome/browser/image_decoder.h b/chrome/browser/image_decoder.h
index 2206dd9f454ebcbfc3a29674cf41e1d42eb594ee..aa85d3d336d59958073cfc36e4ad140105e670e8 100644
--- a/chrome/browser/image_decoder.h
+++ b/chrome/browser/image_decoder.h
@@ -11,12 +11,11 @@
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/threading/sequenced_worker_pool.h"
-#include "content/public/browser/utility_process_host_client.h"
-
-class SkBitmap;
+#include "content/common/image_decoder.mojom.h"
+#include "third_party/skia/include/core/SkBitmap.h"
// Decodes an image in a sandboxed process.
-class ImageDecoder : public content::UtilityProcessHostClient {
+class ImageDecoder : public base::RefCountedThreadSafe<ImageDecoder> {
public:
class Delegate {
public:
@@ -59,26 +58,48 @@ class ImageDecoder : public content::UtilityProcessHostClient {
void set_shrink_to_fit(bool shrink_to_fit) { shrink_to_fit_ = shrink_to_fit; }
private:
+ friend class base::RefCountedThreadSafe<ImageDecoder>;
// It's a reference counted object, so destructor is private.
- ~ImageDecoder() override;
-
- // Overidden from UtilityProcessHostClient:
- bool OnMessageReceived(const IPC::Message& message) override;
-
- // IPC message handlers.
- void OnDecodeImageSucceeded(const SkBitmap& decoded_image);
- void OnDecodeImageFailed();
+ ~ImageDecoder();
// Launches sandboxed process that will decode the image.
void DecodeImageInSandbox(const std::vector<unsigned char>& image_data);
+ // Mojo RPC callback.
+ void OnDecodeImageDone(bool success, content::ImageDataPtr image);
+
Delegate* delegate_;
std::vector<unsigned char> image_data_;
const ImageCodec image_codec_;
scoped_refptr<base::SequencedTaskRunner> task_runner_;
bool shrink_to_fit_; // if needed for IPC msg size limit
+ content::ImageDecoderPtr decoder_;
DISALLOW_COPY_AND_ASSIGN(ImageDecoder);
};
+// TODO(amistry): Move somewhere else.
+namespace mojo {
+template <>
+struct TypeConverter<SkBitmap, content::ImageDataPtr> {
+ static SkBitmap Convert(const content::ImageDataPtr& image) {
+ SkBitmap bitmap;
+ if (!bitmap.tryAllocPixels(SkImageInfo::Make(
+ image->width, image->height,
+ static_cast<SkColorType>(image->color_type),
+ static_cast<SkAlphaType>(image->alpha_type)))) {
+ LOG(ERROR) << "Unable to create SkBitmap";
+ return bitmap;
+ }
+ if (bitmap.getSize() != image->pixels.size()) {
+ LOG(ERROR) << "Incorrect bitmap size, expected: " << image->pixels.size()
+ << ", actual: " << bitmap.getSize();
+ return bitmap;
+ }
+ memcpy(bitmap.getPixels(), &image->pixels[0], bitmap.getSize());
+ return bitmap;
+ }
+};
+} // namespace mojo
+
#endif // CHROME_BROWSER_IMAGE_DECODER_H_
« no previous file with comments | « chrome/browser/extensions/webstore_install_helper.cc ('k') | chrome/browser/image_decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698