blob: d4f4a6ae3f1fff1c216914c9c429d8685078a700 [file] [log] [blame]
Avi Drissman3e1a26c2022-09-15 20:26:031// Copyright 2021 The Chromium Authors
Wei Lee6fc33ef42021-05-25 08:36:262// 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 Lee7d17d5572024-11-10 13:52:459
Wei Lee6fc33ef42021-05-25 08:36:2610#include <vector>
11
Kalvin Lee7d17d5572024-11-10 13:52:4512#include "base/component_export.h"
Wei Lee6fc33ef42021-05-25 08:36:2613#include "third_party/skia/include/core/SkStream.h"
Wei Lee6fc33ef42021-05-25 08:36:2614
15namespace 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 Lee7d17d5572024-11-10 13:52:4519class COMPONENT_EXPORT(GFX) BufferWStream : public SkWStream {
Wei Lee6fc33ef42021-05-25 08:36:2620 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_