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