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

Unified Diff: blimp/client/feature/compositor/blob_image_serialization_processor.cc

Issue 1985863002: Incorporate BlobChannel into Blimp image encode/decode pipeline. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blobchannel-helium
Patch Set: fix gn dependency warning & rebase Created 4 years, 6 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
Index: blimp/client/feature/compositor/blob_image_serialization_processor.cc
diff --git a/blimp/client/feature/compositor/blob_image_serialization_processor.cc b/blimp/client/feature/compositor/blob_image_serialization_processor.cc
new file mode 100644
index 0000000000000000000000000000000000000000..65e1d0d7ab7e482dfd8eb0484c743c58e506f9ff
--- /dev/null
+++ b/blimp/client/feature/compositor/blob_image_serialization_processor.cc
@@ -0,0 +1,95 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "blimp/client/feature/compositor/blob_image_serialization_processor.h"
+
+#include <stddef.h>
+#include <string>
+#include <vector>
+
+#include "base/logging.h"
+#include "base/memory/ref_counted.h"
+#include "base/sha1.h"
+#include "base/strings/string_number_conversions.h"
+#include "blimp/client/feature/compositor/blimp_image_decoder.h"
+#include "blimp/common/blob_cache/blob_cache.h"
+#include "blimp/common/blob_cache/id_util.h"
+#include "blimp/common/proto/blob_cache.pb.h"
+#include "blimp/net/blob_channel/blob_channel_receiver.h"
+
+namespace blimp {
+namespace client {
+
+BlobImageSerializationProcessor*
+ BlobImageSerializationProcessor::current_instance_ = nullptr;
+
+BlobImageSerializationProcessor* BlobImageSerializationProcessor::current() {
+ DCHECK(current_instance_);
+ return current_instance_;
+}
+
+BlobImageSerializationProcessor::BlobImageSerializationProcessor() {
+ DCHECK(!current_instance_);
+ current_instance_ = this;
+}
+
+BlobImageSerializationProcessor::~BlobImageSerializationProcessor() {
+ current_instance_ = nullptr;
+}
+
+// static
+bool BlobImageSerializationProcessor::InstallPixelRefProc(const void* input,
+ size_t input_size,
+ SkBitmap* bitmap) {
+ return current()->GetAndDecodeBlob(input, input_size, bitmap);
+}
+
+bool BlobImageSerializationProcessor::GetAndDecodeBlob(const void* input,
+ size_t input_size,
+ SkBitmap* bitmap) const {
+ DCHECK(input);
+ DCHECK(bitmap);
+
+ BlobCacheImageMetadata parsed_metadata;
+ if (!parsed_metadata.ParseFromArray(input, input_size)) {
+ LOG(ERROR) << "Couldn't parse blob metadata structure.";
+ error_delegate_->OnImageDecodeError();
+ return false;
+ }
+ if (!IsValidBlobId(parsed_metadata.id())) {
+ LOG(ERROR) << "Image payload is not a valid blob ID.";
+ error_delegate_->OnImageDecodeError();
+ return false;
+ }
+
+ // Get the image blob synchronously.
+ // TODO(kmarshall): Add support for asynchronous Get() completion after Skia
+ // supports image replacement.
+ BlobDataPtr blob = blob_receiver_->Get(parsed_metadata.id());
+ if (!blob) {
+ LOG(ERROR) << "No blob found with ID: "
+ << BlobIdToString(parsed_metadata.id());
+ error_delegate_->OnImageDecodeError();
+ return false;
+ }
+
+ DVLOG(1) << "GetAndDecodeBlob(" << BlobIdToString(parsed_metadata.id())
+ << ")";
+
+ return BlimpImageDecoder(reinterpret_cast<const void*>(&blob->data[0]),
+ blob->data.size(), bitmap);
+}
+
+SkPixelSerializer* BlobImageSerializationProcessor::GetPixelSerializer() {
+ NOTREACHED();
+ return nullptr;
+}
+
+SkPicture::InstallPixelRefProc
+BlobImageSerializationProcessor::GetPixelDeserializer() {
+ return &BlobImageSerializationProcessor::InstallPixelRefProc;
+}
+
+} // namespace client
+} // namespace blimp

Powered by Google App Engine
This is Rietveld 408576698