OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "blimp/client/feature/compositor/blob_image_serialization_processor.h" |
| 6 |
| 7 #include <stddef.h> |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/logging.h" |
| 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/sha1.h" |
| 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "blimp/client/feature/compositor/blimp_image_decoder.h" |
| 16 #include "blimp/common/blob_cache/blob_cache.h" |
| 17 #include "blimp/common/blob_cache/id_util.h" |
| 18 #include "blimp/common/proto/blob_cache.pb.h" |
| 19 #include "blimp/net/blob_channel/blob_channel_receiver.h" |
| 20 |
| 21 namespace blimp { |
| 22 namespace client { |
| 23 |
| 24 BlobImageSerializationProcessor* |
| 25 BlobImageSerializationProcessor::current_instance_ = nullptr; |
| 26 |
| 27 BlobImageSerializationProcessor* BlobImageSerializationProcessor::current() { |
| 28 DCHECK(current_instance_); |
| 29 return current_instance_; |
| 30 } |
| 31 |
| 32 BlobImageSerializationProcessor::BlobImageSerializationProcessor() { |
| 33 DCHECK(!current_instance_); |
| 34 current_instance_ = this; |
| 35 } |
| 36 |
| 37 BlobImageSerializationProcessor::~BlobImageSerializationProcessor() { |
| 38 current_instance_ = nullptr; |
| 39 } |
| 40 |
| 41 // static |
| 42 bool BlobImageSerializationProcessor::InstallPixelRefProc(const void* input, |
| 43 size_t input_size, |
| 44 SkBitmap* bitmap) { |
| 45 return current()->GetAndDecodeBlob(input, input_size, bitmap); |
| 46 } |
| 47 |
| 48 bool BlobImageSerializationProcessor::GetAndDecodeBlob(const void* input, |
| 49 size_t input_size, |
| 50 SkBitmap* bitmap) const { |
| 51 DCHECK(input); |
| 52 DCHECK(bitmap); |
| 53 |
| 54 BlobCacheImageMetadata parsed_metadata; |
| 55 if (!parsed_metadata.ParseFromArray(input, input_size)) { |
| 56 LOG(ERROR) << "Couldn't parse blob metadata structure."; |
| 57 error_delegate_->OnImageDecodeError(); |
| 58 return false; |
| 59 } |
| 60 if (!IsValidBlobId(parsed_metadata.id())) { |
| 61 LOG(ERROR) << "Image payload is not a valid blob ID."; |
| 62 error_delegate_->OnImageDecodeError(); |
| 63 return false; |
| 64 } |
| 65 |
| 66 // Get the image blob synchronously. |
| 67 // TODO(kmarshall): Add support for asynchronous Get() completion after Skia |
| 68 // supports image replacement. |
| 69 BlobDataPtr blob = blob_receiver_->Get(parsed_metadata.id()); |
| 70 if (!blob) { |
| 71 LOG(ERROR) << "No blob found with ID: " |
| 72 << BlobIdToString(parsed_metadata.id()); |
| 73 error_delegate_->OnImageDecodeError(); |
| 74 return false; |
| 75 } |
| 76 |
| 77 DVLOG(1) << "GetAndDecodeBlob(" << BlobIdToString(parsed_metadata.id()) |
| 78 << ")"; |
| 79 |
| 80 return BlimpImageDecoder(reinterpret_cast<const void*>(&blob->data[0]), |
| 81 blob->data.size(), bitmap); |
| 82 } |
| 83 |
| 84 SkPixelSerializer* BlobImageSerializationProcessor::GetPixelSerializer() { |
| 85 NOTREACHED(); |
| 86 return nullptr; |
| 87 } |
| 88 |
| 89 SkPicture::InstallPixelRefProc |
| 90 BlobImageSerializationProcessor::GetPixelDeserializer() { |
| 91 return &BlobImageSerializationProcessor::InstallPixelRefProc; |
| 92 } |
| 93 |
| 94 } // namespace client |
| 95 } // namespace blimp |
OLD | NEW |