skia2/client_utils/android/FrontBufferedStream.h
Leon Scroggins III 63cfb3638c Reland "Move SkFrontBufferedStream into Android-only dir"
This reverts commit b25f30348b.

Bug: skia:10154

Original message:
> Add client_utils for code that is specifically for a single client.
> Move SkFrontBufferedStream into its android/ subdir. Rename the class
> to android::skia::FrontBufferedStream. Temporarily leave in
> SkFrontBufferedStream until Android updates to the new API.
>
> Add a new optional target for client_utils/android. It is built in dev
> builds for testing, and when building for the Android framework.

Deliberately do not include client_utils in Google3, since the whole
point is to only include where necessary.

Change-Id: I48938c56aabb98e1ed820240d43ffcd0fdce7956
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/285104
Commit-Queue: Leon Scroggins <scroggo@google.com>
Reviewed-by: Derek Sollenberger <djsollen@google.com>
Reviewed-by: Mike Reed <reed@google.com>
2020-04-24 17:36:30 +00:00

44 lines
1.6 KiB
C++

/*
* Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef FrontBufferedStream_DEFINED
#define FrontBufferedStream_DEFINED
#include "include/core/SkStream.h"
namespace android {
namespace skia {
/**
* Specialized stream that buffers the first X bytes of a stream,
* where X is passed in by the user. Note that unlike some buffered
* stream APIs, once more bytes than can fit in the buffer are read,
* no more buffering is done. This stream is designed for a use case
* where the caller knows that rewind will only be called from within
* X bytes (inclusive), and the wrapped stream is not necessarily
* able to rewind at all.
*/
class SK_API FrontBufferedStream {
public:
/**
* Creates a new stream that wraps and buffers an SkStream.
* @param stream SkStream to buffer. If stream is NULL, NULL is
* returned. When this call succeeds (i.e. returns non NULL),
* FrontBufferedStream is expected to be the only owner of
* stream, so it should no be longer used directly.
* FrontBufferedStream will delete stream upon deletion.
* @param minBufferSize Minimum size of buffer required.
* @return An SkStream that can buffer at least minBufferSize, or
* NULL on failure. The caller is required to delete when finished with
* this object.
*/
static std::unique_ptr<SkStreamRewindable> Make(std::unique_ptr<SkStream> stream,
size_t minBufferSize);
};
} // namespace skia
} // namespace android
#endif // FrontBufferedStream_DEFINED