Avi Drissman | 3e1a26c | 2022-09-15 20:26:03 | [diff] [blame] | 1 | // Copyright 2021 The Chromium Authors |
Wei Lee | 6fc33ef4 | 2021-05-25 08:36:26 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef UI_GFX_IMAGE_BUFFER_W_STREAM_H_ |
| 6 | #define UI_GFX_IMAGE_BUFFER_W_STREAM_H_ |
| 7 | |
| 8 | #include <stdint.h> |
Kalvin Lee | 7d17d557 | 2024-11-10 13:52:45 | [diff] [blame] | 9 | |
Wei Lee | 6fc33ef4 | 2021-05-25 08:36:26 | [diff] [blame] | 10 | #include <vector> |
| 11 | |
Kalvin Lee | 7d17d557 | 2024-11-10 13:52:45 | [diff] [blame] | 12 | #include "base/component_export.h" |
Wei Lee | 6fc33ef4 | 2021-05-25 08:36:26 | [diff] [blame] | 13 | #include "third_party/skia/include/core/SkStream.h" |
Wei Lee | 6fc33ef4 | 2021-05-25 08:36:26 | [diff] [blame] | 14 | |
| 15 | namespace gfx { |
| 16 | |
| 17 | // Writes bytes to a std::vector that can be fetched. This is used to record the |
| 18 | // output of skia image encoding. |
Kalvin Lee | 7d17d557 | 2024-11-10 13:52:45 | [diff] [blame] | 19 | class COMPONENT_EXPORT(GFX) BufferWStream : public SkWStream { |
Wei Lee | 6fc33ef4 | 2021-05-25 08:36:26 | [diff] [blame] | 20 | public: |
| 21 | BufferWStream(); |
| 22 | BufferWStream(const BufferWStream&) = delete; |
| 23 | BufferWStream& operator=(const BufferWStream&) = delete; |
| 24 | ~BufferWStream() override; |
| 25 | |
| 26 | // Returns the output buffer by moving. |
| 27 | std::vector<uint8_t> TakeBuffer(); |
| 28 | |
| 29 | // SkWStream: |
| 30 | bool write(const void* buffer, size_t size) override; |
| 31 | size_t bytesWritten() const override; |
| 32 | |
| 33 | private: |
| 34 | std::vector<uint8_t> result_; |
| 35 | }; |
| 36 | |
| 37 | } // namespace gfx |
| 38 | |
| 39 | #endif // UI_GFX_IMAGE_BUFFER_W_STREAM_H_ |