| 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/ptr_util.h" | |
| 13 #include "base/memory/ref_counted.h" | |
| 14 #include "base/sha1.h" | |
| 15 #include "base/strings/string_number_conversions.h" | |
| 16 #include "blimp/client/feature/compositor/blimp_client_picture_cache.h" | |
| 17 #include "blimp/client/feature/compositor/blimp_image_decoder.h" | |
| 18 #include "blimp/common/blob_cache/blob_cache.h" | |
| 19 #include "blimp/common/blob_cache/id_util.h" | |
| 20 #include "blimp/common/proto/blob_cache.pb.h" | |
| 21 #include "blimp/net/blob_channel/blob_channel_receiver.h" | |
| 22 | |
| 23 namespace blimp { | |
| 24 namespace client { | |
| 25 | |
| 26 BlobImageSerializationProcessor* | |
| 27 BlobImageSerializationProcessor::current_instance_ = nullptr; | |
| 28 | |
| 29 BlobImageSerializationProcessor* BlobImageSerializationProcessor::current() { | |
| 30 DCHECK(current_instance_); | |
| 31 return current_instance_; | |
| 32 } | |
| 33 | |
| 34 BlobImageSerializationProcessor::BlobImageSerializationProcessor() { | |
| 35 DCHECK(!current_instance_); | |
| 36 current_instance_ = this; | |
| 37 } | |
| 38 | |
| 39 BlobImageSerializationProcessor::~BlobImageSerializationProcessor() { | |
| 40 current_instance_ = nullptr; | |
| 41 } | |
| 42 | |
| 43 // static | |
| 44 bool BlobImageSerializationProcessor::InstallPixelRefProc(const void* input, | |
| 45 size_t input_size, | |
| 46 SkBitmap* bitmap) { | |
| 47 return current()->GetAndDecodeBlob(input, input_size, bitmap); | |
| 48 } | |
| 49 | |
| 50 bool BlobImageSerializationProcessor::GetAndDecodeBlob(const void* input, | |
| 51 size_t input_size, | |
| 52 SkBitmap* bitmap) const { | |
| 53 DCHECK(input); | |
| 54 DCHECK(bitmap); | |
| 55 | |
| 56 BlobCacheImageMetadata parsed_metadata; | |
| 57 if (!parsed_metadata.ParseFromArray(input, input_size)) { | |
| 58 LOG(ERROR) << "Couldn't parse blob metadata structure."; | |
| 59 error_delegate_->OnImageDecodeError(); | |
| 60 return false; | |
| 61 } | |
| 62 if (!IsValidBlobId(parsed_metadata.id())) { | |
| 63 LOG(ERROR) << "Image payload is not a valid blob ID."; | |
| 64 error_delegate_->OnImageDecodeError(); | |
| 65 return false; | |
| 66 } | |
| 67 | |
| 68 // Get the image blob synchronously. | |
| 69 // TODO(kmarshall): Add support for asynchronous Get() completion after Skia | |
| 70 // supports image replacement. | |
| 71 BlobDataPtr blob = blob_receiver_->Get(parsed_metadata.id()); | |
| 72 if (!blob) { | |
| 73 LOG(ERROR) << "No blob found with ID: " | |
| 74 << BlobIdToString(parsed_metadata.id()); | |
| 75 error_delegate_->OnImageDecodeError(); | |
| 76 return false; | |
| 77 } | |
| 78 | |
| 79 DVLOG(1) << "GetAndDecodeBlob(" << BlobIdToString(parsed_metadata.id()) | |
| 80 << ")"; | |
| 81 | |
| 82 return DecodeBlimpImage(reinterpret_cast<const void*>(&blob->data[0]), | |
| 83 blob->data.size(), bitmap); | |
| 84 } | |
| 85 | |
| 86 std::unique_ptr<cc::EnginePictureCache> | |
| 87 BlobImageSerializationProcessor::CreateEnginePictureCache() { | |
| 88 NOTREACHED(); | |
| 89 return nullptr; | |
| 90 } | |
| 91 | |
| 92 std::unique_ptr<cc::ClientPictureCache> | |
| 93 BlobImageSerializationProcessor::CreateClientPictureCache() { | |
| 94 return base::WrapUnique(new BlimpClientPictureCache( | |
| 95 &BlobImageSerializationProcessor::InstallPixelRefProc)); | |
| 96 } | |
| 97 | |
| 98 } // namespace client | |
| 99 } // namespace blimp | |
| OLD | NEW |