| 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 #ifndef BLIMP_CLIENT_FEATURE_COMPOSITOR_BLOB_IMAGE_SERIALIZATION_PROCESSOR_H_ | 5 #ifndef BLIMP_CLIENT_FEATURE_COMPOSITOR_BLOB_IMAGE_SERIALIZATION_PROCESSOR_H_ |
| 6 #define BLIMP_CLIENT_FEATURE_COMPOSITOR_BLOB_IMAGE_SERIALIZATION_PROCESSOR_H_ | 6 #define BLIMP_CLIENT_FEATURE_COMPOSITOR_BLOB_IMAGE_SERIALIZATION_PROCESSOR_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
| 12 #include "cc/proto/image_serialization_processor.h" | 12 #include "cc/proto/image_serialization_processor.h" |
| 13 #include "third_party/skia/include/core/SkPicture.h" | 13 #include "third_party/skia/include/core/SkPicture.h" |
| 14 | 14 |
| 15 class SkPixelSerializer; | 15 class SkPixelSerializer; |
| 16 | 16 |
| 17 namespace blimp { | 17 namespace blimp { |
| 18 | 18 |
| 19 class BlobChannelReceiver; | 19 class BlobChannelReceiver; |
| 20 | 20 |
| 21 namespace client { | 21 namespace client { |
| 22 | 22 |
| 23 // Adds BlobChannel image retrieval support to the Skia image decoding process. | 23 // Adds BlobChannel image retrieval support to the Skia image decoding process, |
| 24 // in addition to providing a cache for Skia images. |
| 24 class BlobImageSerializationProcessor : public cc::ImageSerializationProcessor { | 25 class BlobImageSerializationProcessor : public cc::ImageSerializationProcessor { |
| 25 public: | 26 public: |
| 26 class ErrorDelegate { | 27 class ErrorDelegate { |
| 27 public: | 28 public: |
| 28 virtual void OnImageDecodeError() = 0; | 29 virtual void OnImageDecodeError() = 0; |
| 29 }; | 30 }; |
| 30 | 31 |
| 31 // Returns the BlobImageSerializationProcessor* instance that is active | 32 // Returns the BlobImageSerializationProcessor* instance that is active |
| 32 // for the current process. | 33 // for the current process. |
| 33 static BlobImageSerializationProcessor* current(); | 34 static BlobImageSerializationProcessor* current(); |
| 34 | 35 |
| 35 BlobImageSerializationProcessor(); | 36 BlobImageSerializationProcessor(); |
| 36 virtual ~BlobImageSerializationProcessor(); | 37 ~BlobImageSerializationProcessor() override; |
| 37 | 38 |
| 38 // Sets the |blob_receiver| to use for reading images. | 39 // Sets the |blob_receiver| to use for reading images. |
| 39 // |blob_receiver| must outlive |this|. | 40 // |blob_receiver| must outlive |this|. |
| 40 void set_blob_receiver(BlobChannelReceiver* blob_receiver) { | 41 void set_blob_receiver(BlobChannelReceiver* blob_receiver) { |
| 41 blob_receiver_ = blob_receiver; | 42 blob_receiver_ = blob_receiver; |
| 42 } | 43 } |
| 43 | 44 |
| 44 // |error_delegate| must outlive this. | 45 // |error_delegate| must outlive this. |
| 45 void set_error_delegate(ErrorDelegate* error_delegate) { | 46 void set_error_delegate(ErrorDelegate* error_delegate) { |
| 46 error_delegate_ = error_delegate; | 47 error_delegate_ = error_delegate; |
| 47 } | 48 } |
| 48 | 49 |
| 49 // Retrieves a bitmap with ID |input| from |blob_receiver_| and decodes it | 50 // Retrieves a bitmap with ID |input| from |blob_receiver_| and decodes it |
| 50 // to |bitmap|. | 51 // to |bitmap|. |
| 51 bool GetAndDecodeBlob(const void* input, | 52 bool GetAndDecodeBlob(const void* input, |
| 52 size_t input_size, | 53 size_t input_size, |
| 53 SkBitmap* bitmap) const; | 54 SkBitmap* bitmap) const; |
| 54 | 55 |
| 55 private: | 56 private: |
| 56 friend struct base::DefaultSingletonTraits<BlobImageSerializationProcessor>; | 57 friend struct base::DefaultSingletonTraits<BlobImageSerializationProcessor>; |
| 57 | 58 |
| 58 // Adapts a bare function pointer call to a singleton call to | 59 // Adapts a bare function pointer call to a singleton call to |
| 59 // GetAndDecodeBlob() call on the current() processor. | 60 // GetAndDecodeBlob() call on the current() processor. |
| 60 static bool InstallPixelRefProc(const void* input, | 61 static bool InstallPixelRefProc(const void* input, |
| 61 size_t input_size, | 62 size_t input_size, |
| 62 SkBitmap* bitmap); | 63 SkBitmap* bitmap); |
| 63 | 64 |
| 64 // cc:ImageSerializationProcessor implementation. | 65 // cc:ImageSerializationProcessor implementation. |
| 65 SkPixelSerializer* GetPixelSerializer() override; | 66 std::unique_ptr<cc::EnginePictureCache> CreateEnginePictureCache() override; |
| 66 SkPicture::InstallPixelRefProc GetPixelDeserializer() override; | 67 std::unique_ptr<cc::ClientPictureCache> CreateClientPictureCache() override; |
| 67 | 68 |
| 68 // Interface for accessing stored images received over the Blob Channel. | 69 // Interface for accessing stored images received over the Blob Channel. |
| 69 BlobChannelReceiver* blob_receiver_ = nullptr; | 70 BlobChannelReceiver* blob_receiver_ = nullptr; |
| 70 | 71 |
| 71 ErrorDelegate* error_delegate_ = nullptr; | 72 ErrorDelegate* error_delegate_ = nullptr; |
| 72 | 73 |
| 73 // Pointer is bound on object construction, and set to nullptr on object | 74 // Pointer is bound on object construction, and set to nullptr on object |
| 74 // deletion. Only one BlobImageSerializationProcessor may be live at a time. | 75 // deletion. Only one BlobImageSerializationProcessor may be live at a time. |
| 75 static BlobImageSerializationProcessor* current_instance_; | 76 static BlobImageSerializationProcessor* current_instance_; |
| 76 | 77 |
| 77 DISALLOW_COPY_AND_ASSIGN(BlobImageSerializationProcessor); | 78 DISALLOW_COPY_AND_ASSIGN(BlobImageSerializationProcessor); |
| 78 }; | 79 }; |
| 79 | 80 |
| 80 } // namespace client | 81 } // namespace client |
| 81 } // namespace blimp | 82 } // namespace blimp |
| 82 | 83 |
| 83 #endif // BLIMP_CLIENT_FEATURE_COMPOSITOR_BLOB_IMAGE_SERIALIZATION_PROCESSOR_H_ | 84 #endif // BLIMP_CLIENT_FEATURE_COMPOSITOR_BLOB_IMAGE_SERIALIZATION_PROCESSOR_H_ |
| OLD | NEW |