129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/*
229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * Copyright (C) 2016 The Android Open Source Project
329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar *
429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * Licensed under the Apache License, Version 2.0 (the "License");
529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * you may not use this file except in compliance with the License.
629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * You may obtain a copy of the License at
729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar *
829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar *      http://www.apache.org/licenses/LICENSE-2.0
929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar *
1029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * Unless required by applicable law or agreed to in writing, software
1129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * distributed under the License is distributed on an "AS IS" BASIS,
1229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * See the License for the specific language governing permissions and
1429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * limitations under the License.
1529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar */
1629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
1729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar#ifndef C2BUFFER_H_
1829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar#define C2BUFFER_H_
1929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
2029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar#include <C2.h>
2129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar#include <C2Param.h> // for C2Info
2229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
2329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar#include <list>
2429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar#include <memory>
2529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
2629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnartypedef int C2Fence;
2729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
2829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar#ifdef __ANDROID__
2929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
3029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar// #include <system/window.h>
3129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar#include <cutils/native_handle.h>
3229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar#include <hardware/gralloc.h> // TODO: remove
3329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
3429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnartypedef native_handle_t C2Handle;
3529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
3629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar#else
3729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
3829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnartypedef void* C2Handle;
3929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
4029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar#endif
4129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
4229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarnamespace android {
4329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
4429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/// \defgroup buffer Buffers
4529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/// @{
4629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
4729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/// \defgroup buffer_sync Synchronization
4829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/// @{
4929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
5029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/**
5129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * Synchronization is accomplished using event and fence objects.
5229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar *
5329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * These are cross-process extensions of promise/future infrastructure.
5429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * Events are analogous to std::promise<void>, whereas fences are to std::shared_future<void>.
5529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar *
5629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * Fences and events are shareable/copyable.
5729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar *
5829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * Fences are used in two scenarios, and all copied instances refer to the same event.
5929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * \todo do events need to be copyable or should they be unique?
6029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar *
6129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * acquire sync fence object: signaled when it is safe for the component or client to access
6229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * (the contents of) an object.
6329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar *
6429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * release sync fence object: \todo
6529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar *
6629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * Fences can be backed by hardware. Hardware fences are guaranteed to signal NO MATTER WHAT within
6729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * a short (platform specific) amount of time; this guarantee is usually less than 15 msecs.
6829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar */
6929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
7029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/**
7129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * Fence object used by components and the framework.
7229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar *
7329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * Implements the waiting for an event, analogous to a 'future'.
7429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar *
7529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * To be implemented by vendors if using HW fences.
7629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar */
7729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarclass C2Fence {
7829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarpublic:
7929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
8029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Waits for a fence to be signaled with a timeout.
8129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
8229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \todo a mechanism to cancel a wait - for now the only way to do this is to abandon the
8329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * event, but fences are shared so canceling a wait will cancel all waits.
8429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
8529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \param timeoutNs           the maximum time to wait in nsecs
8629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
8729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \retval C2_OK            the fence has been signaled
8829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \retval C2_TIMED_OUT     the fence has not been signaled within the timeout
8929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \retval C2_BAD_STATE     the fence has been abandoned without being signaled (it will never
9029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *                          be signaled)
9129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \retval C2_NO_PERMISSION no permission to wait for the fence (unexpected - system)
9229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \retval C2_CORRUPTED     some unknown error prevented waiting for the fence (unexpected)
9329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
9429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    C2Error wait(nsecs_t timeoutNs);
9529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
9629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
9729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Used to check if this fence is valid (if there is a chance for it to be signaled.)
9829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * A fence becomes invalid if the controling event is destroyed without it signaling the fence.
9929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
10029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \return whether this fence is valid
10129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
10229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    bool valid() const;
10329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
10429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
10529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Used to check if this fence has been signaled (is ready).
10629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
10729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \return whether this fence has been signaled
10829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
10929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    bool ready() const;
11029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
11129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
11229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Returns a file descriptor that can be used to wait for this fence in a select system call.
11329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \note The returned file descriptor, if valid, must be closed by the caller.
11429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
11529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * This can be used in e.g. poll() system calls. This file becomes readable (POLLIN) when the
11629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * fence is signaled, and bad (POLLERR) if the fence is abandoned.
11729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
11829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \return a file descriptor representing this fence (with ownership), or -1 if the fence
11929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * has already been signaled (\todo or abandoned).
12029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
12129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \todo this must be compatible with fences used by gralloc
12229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
12329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    int fd() const;
12429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
12529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
12629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Returns whether this fence is a hardware-backed fence.
12729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \return whether this is a hardware fence
12829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
12929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    bool isHW() const;
13029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
13129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarprivate:
13229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    class Impl;
13329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    std::shared_ptr<Impl> mImpl;
13429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar};
13529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
13629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/**
13729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * Event object used by components and the framework.
13829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar *
13929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * Implements the signaling of an event, analogous to a 'promise'.
14029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar *
14129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * Hardware backed events do not go through this object, and must be exposed directly as fences
14229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * by vendors.
14329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar */
14429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarclass C2Event {
14529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarpublic:
14629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
14729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Returns a fence for this event.
14829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
14929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    C2Fence fence() const;
15029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
15129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
15229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Signals (all) associated fence(s).
15329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * This has no effect no effect if the event was already signaled or abandoned.
15429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
15529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \retval C2_OK            the fence(s) were successfully signaled
15629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \retval C2_BAD_STATE     the fence(s) have already been abandoned or merged (caller error)
15729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \retval C2_ALREADY_EXISTS the fence(s) have already been signaled (caller error)
15829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \retval C2_NO_PERMISSION no permission to signal the fence (unexpected - system)
15929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \retval C2_CORRUPTED     some unknown error prevented signaling the fence(s) (unexpected)
16029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
16129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    C2Error fire();
16229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
16329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
16429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Trigger this event from the merging of the supplied fences. This means that it will be
16529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * abandoned if any of these fences have been abandoned, and it will be fired if all of these
16629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * fences have been signaled.
16729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
16829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \retval C2_OK            the merging was successfully done
16929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \retval C2_NO_MEMORY     not enough memory to perform the merging
17029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \retval C2_ALREADY_EXISTS    the fence have already been merged (caller error)
17129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \retval C2_BAD_STATE     the fence have already been signaled or abandoned (caller error)
17229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \retval C2_NO_PERMISSION no permission to merge the fence (unexpected - system)
17329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \retval C2_CORRUPTED     some unknown error prevented merging the fence(s) (unexpected)
17429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
17529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    C2Error merge(std::vector<C2Fence> fences);
17629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
17729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
17829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Abandons the event and any associated fence(s).
17929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \note Call this to explicitly abandon an event before it is destructed to avoid a warning.
18029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
18129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * This has no effect no effect if the event was already signaled or abandoned.
18229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
18329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \retval C2_OK            the fence(s) were successfully signaled
18429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \retval C2_BAD_STATE     the fence(s) have already been signaled or merged (caller error)
18529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \retval C2_ALREADY_EXISTS    the fence(s) have already been abandoned (caller error)
18629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \retval C2_NO_PERMISSION no permission to abandon the fence (unexpected - system)
18729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \retval C2_CORRUPTED     some unknown error prevented signaling the fence(s) (unexpected)
18829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
18929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    C2Error abandon();
19029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
19129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarprivate:
19229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    class Impl;
19329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    std::shared_ptr<Impl> mImpl;
19429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar};
19529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
19629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/// \addtogroup buf_internal Internal
19729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/// @{
19829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
19929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/**
20029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * Interface for objects that encapsulate an updatable error value.
20129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar */
20229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarstruct _C2InnateError {
20329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline C2Error error() const { return mError; }
20429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
20529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarprotected:
20629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    _C2InnateError(C2Error error) : mError(error) { }
20729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
20829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    C2Error mError; // this error is updatable by the object
20929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar};
21029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
21129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/// @}
21229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
21329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/**
21429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * This is a utility template for objects protected by an acquire fence, so that errors during
21529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * acquiring the object are propagated to the object itself.
21629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar */
21729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnartemplate<typename T>
21829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarclass C2Acquirable : public C2Fence {
21929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarpublic:
22029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
22129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Acquires the object protected by an acquire fence. Any errors during the mapping will be
22229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * passed to the object.
22329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
22429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \return acquired object potentially invalidated if waiting for the fence failed.
22529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
22629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    T get();
22729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
22829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarprotected:
22929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    C2Acquirable(C2Error error, C2Fence fence, T t) : C2Fence(fence), mInitialError(error), mT(t) { }
23029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
23129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarprivate:
23229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    C2Error mInitialError;
23329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    T mT; // TODO: move instead of copy
23429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar};
23529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
23629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/// @}
23729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
23829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/// \defgroup linear Linear Data Blocks
23929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/// @{
24029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
24129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/**************************************************************************************************
24229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar  LINEAR ASPECTS, BLOCKS AND VIEWS
24329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar**************************************************************************************************/
24429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
24529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/**
24629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * Common aspect for all objects that have a linear capacity.
24729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar */
24829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarclass _C2LinearCapacityAspect {
24929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/// \name Linear capacity interface
25029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/// @{
25129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarpublic:
25229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline uint32_t capacity() const { return mCapacity; }
25329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
25429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarprotected:
25529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
25629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar#if UINTPTR_MAX == 0xffffffff
25729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    static_assert(sizeof(size_t) == sizeof(uint32_t), "size_t is too big");
25829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar#else
25929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    static_assert(sizeof(size_t) > sizeof(uint32_t), "size_t is too small");
26029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    // explicitly disable construction from size_t
26129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline explicit _C2LinearCapacityAspect(size_t capacity) = delete;
26229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar#endif
26329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
26429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline explicit _C2LinearCapacityAspect(uint32_t capacity)
26529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar      : mCapacity(capacity) { }
26629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
26729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline explicit _C2LinearCapacityAspect(const _C2LinearCapacityAspect *parent)
26829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        : mCapacity(parent == nullptr ? 0 : parent->capacity()) { }
26929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
27029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarprivate:
27129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    const uint32_t mCapacity;
27229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/// @}
27329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar};
27429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
27529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/**
27629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * Aspect for objects that have a linear range.
27729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar *
27829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * This class is copiable.
27929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar */
28029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarclass _C2LinearRangeAspect : public _C2LinearCapacityAspect {
28129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/// \name Linear range interface
28229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/// @{
28329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarpublic:
28429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline uint32_t offset() const { return mOffset; }
28529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline uint32_t size() const { return mSize; }
28629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
28729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarprotected:
28829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline explicit _C2LinearRangeAspect(const _C2LinearCapacityAspect *parent)
28929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        : _C2LinearCapacityAspect(parent),
29029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar          mOffset(0),
29129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar          mSize(capacity()) { }
29229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
29329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline _C2LinearRangeAspect(const _C2LinearCapacityAspect *parent, size_t offset, size_t size)
29429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        : _C2LinearCapacityAspect(parent),
29529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar          mOffset(c2_min(offset, capacity())),
29629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar          mSize(c2_min(size, capacity() - mOffset)) { }
29729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
29829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    // subsection of the two [offset, offset + size] ranges
29929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline _C2LinearRangeAspect(const _C2LinearRangeAspect *parent, size_t offset, size_t size)
30029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        : _C2LinearCapacityAspect(parent == nullptr ? 0 : parent->capacity()),
30129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar          mOffset(c2_min(c2_max(offset, parent == nullptr ? 0 : parent->offset()), capacity())),
30229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar          mSize(c2_min(c2_min(size, parent == nullptr ? 0 : parent->size()), capacity() - mOffset)) { }
30329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
30429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarprivate:
30529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    friend class _C2EditableLinearRange;
30629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    // invariants 0 <= mOffset <= mOffset + mSize <= capacity()
30729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    uint32_t mOffset;
30829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    uint32_t mSize;
30929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/// @}
31029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar};
31129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
31229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/**
31329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * Aspect for objects that have an editable linear range.
31429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar *
31529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * This class is copiable.
31629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar */
31729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarclass _C2EditableLinearRange : public _C2LinearRangeAspect {
31829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarprotected:
31929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline explicit _C2EditableLinearRange(const _C2LinearCapacityAspect *parent)
32029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        : _C2LinearRangeAspect(parent) { }
32129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
32229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline _C2EditableLinearRange(const _C2LinearCapacityAspect *parent, size_t offset, size_t size)
32329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        : _C2LinearRangeAspect(parent, offset, size) { }
32429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
32529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    // subsection of the two [offset, offset + size] ranges
32629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline _C2EditableLinearRange(const _C2LinearRangeAspect *parent, size_t offset, size_t size)
32729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        : _C2LinearRangeAspect(parent, offset, size) { }
32829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
32929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/// \name Editable linear range interface
33029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/// @{
33129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
33229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
33329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Sets the offset to |offset|, while trying to keep the end of the buffer unchanged (e.g.
33429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * size will grow if offset is decreased, and may shrink if offset is increased.) Returns
33529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * true if successful, which is equivalent to if 0 <= |offset| <= capacity().
33629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
33729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Note: setting offset and size will yield different result depending on the order of the
33829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * operations. Always set offset first to ensure proper size.
33929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
34029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline bool setOffset(uint32_t offset) {
34129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        if (offset > capacity()) {
34229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar            return false;
34329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        }
34429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
34529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        if (offset > mOffset + mSize) {
34629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar            mSize = 0;
34729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        } else {
34829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar            mSize = mOffset + mSize - offset;
34929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        }
35029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        mOffset = offset;
35129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        return true;
35229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    }
35329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
35429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Sets the size to |size|. Returns true if successful, which is equivalent to
35529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * if 0 <= |size| <= capacity() - offset().
35629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
35729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Note: setting offset and size will yield different result depending on the order of the
35829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * operations. Always set offset first to ensure proper size.
35929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
36029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline bool setSize(uint32_t size) {
36129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        if (size > capacity() - mOffset) {
36229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar            return false;
36329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        } else {
36429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar            mSize = size;
36529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar            return true;
36629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        }
36729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    }
36829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
36929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Sets the offset to |offset| with best effort. Same as setOffset() except that offset will
37029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * be clamped to the buffer capacity.
37129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
37229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Note: setting offset and size (even using best effort) will yield different result depending
37329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * on the order of the operations. Always set offset first to ensure proper size.
37429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
37529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline void setOffset_be(uint32_t offset) {
37629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        if (offset > capacity()) {
37729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar            offset = capacity();
37829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        }
37929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        if (offset > mOffset + mSize) {
38029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar            mSize = 0;
38129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        } else {
38229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar            mSize = mOffset + mSize - offset;
38329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        }
38429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        mOffset = offset;
38529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    }
38629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
38729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Sets the size to |size| with best effort. Same as setSize() except that the selected region
38829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * will be clamped to the buffer capacity (e.g. size is clamped to [0, capacity() - offset()]).
38929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
39029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Note: setting offset and size (even using best effort) will yield different result depending
39129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * on the order of the operations. Always set offset first to ensure proper size.
39229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
39329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline void setSize_be(uint32_t size) {
39429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        mSize = std::min(size, capacity() - mOffset);
39529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    }
39629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/// @}
39729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar};
39829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
39929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar// ================================================================================================
40029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar//  BLOCKS
40129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar// ================================================================================================
40229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
40329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/**
40429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * Blocks are sections of allocations. They can be either 1D or 2D.
40529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar */
40629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
40729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarclass C2LinearAllocation;
40829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
40929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarclass C2Block1D : public _C2LinearRangeAspect {
41029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarpublic:
41129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    const C2Handle *handle() const;
41229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
41329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarprotected:
41429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    C2Block1D(std::shared_ptr<C2LinearAllocation> alloc);
41529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    C2Block1D(std::shared_ptr<C2LinearAllocation> alloc, size_t offset, size_t size);
41629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
41729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarprivate:
41829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    class Impl;
41929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    std::shared_ptr<Impl> mImpl;
42029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar};
42129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
42229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/**
42329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * Read view provides read-only access for a linear memory segment.
42429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar *
42529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * This class is copiable.
42629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar */
42729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarclass C2ReadView : public _C2LinearCapacityAspect {
42829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarpublic:
42929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
43029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \return pointer to the start of the block or nullptr on error.
43129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
43229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    const uint8_t *data();
43329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
43429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
43529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Returns a portion of this view.
43629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
43729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \param offset  the start offset of the portion. \note This is clamped to the capacity of this
43829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *              view.
43929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \param size    the size of the portion. \note This is clamped to the remaining data from offset.
44029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
44129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \return a read view containing a portion of this view
44229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
44329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    C2ReadView subView(size_t offset, size_t size) const;
44429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
44529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
44629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \return error during the creation/mapping of this view.
44729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
44829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    C2Error error();
44929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
45029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarprivate:
45129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    class Impl;
45229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    std::shared_ptr<Impl> mImpl;
45329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar};
45429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
45529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/**
45629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * Write view provides read/write access for a linear memory segment.
45729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar *
45829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * This class is copiable. \todo movable only?
45929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar */
46029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarclass C2WriteView : public _C2EditableLinearRange {
46129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarpublic:
46229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
46329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Start of the block.
46429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
46529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \return pointer to the start of the block or nullptr on error.
46629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
46729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    uint8_t *base();
46829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
46929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
47029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \return pointer to the block at the current offset or nullptr on error.
47129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
47229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    uint8_t *data();
47329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
47429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
47529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \return error during the creation/mapping of this view.
47629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
47729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    C2Error error();
47829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
47929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarprivate:
48029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    class Impl;
48129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /// \todo should this be unique_ptr to make this movable only - to avoid inconsistent regions
48229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /// between copies.
48329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    std::shared_ptr<Impl> mImpl;
48429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar};
48529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
48629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/**
48729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * A constant (read-only) linear block (portion of an allocation) with an acquire fence.
48829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * Blocks are unmapped when created, and can be mapped into a read view on demand.
48929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar *
49029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * This class is copiable and contains a reference to the allocation that it is based on.
49129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar */
49229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarclass C2ConstLinearBlock : public C2Block1D {
49329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarpublic:
49429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
49529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Maps this block into memory and returns a read view for it.
49629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
49729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \return a read view for this block.
49829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
49929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    C2Acquirable<C2ReadView> map() const;
50029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
50129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
50229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Returns a portion of this block.
50329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
50429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \param offset  the start offset of the portion. \note This is clamped to the capacity of this
50529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *              block.
50629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \param size    the size of the portion. \note This is clamped to the remaining data from offset.
50729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
50829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \return a constant linear block containing a portion of this block
50929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
51029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    C2ConstLinearBlock subBlock(size_t offset, size_t size) const;
51129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
51229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
51329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Returns the acquire fence for this block.
51429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
51529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \return a fence that must be waited on before reading the block.
51629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
51729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    C2Fence fence() const { return mFence; }
51829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
51929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarprivate:
52029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    C2Fence mFence;
52129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar};
52229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
52329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/**
52429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * Linear block is a writeable 1D block. Once written, it can be shared in whole or in parts with
52529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * consumers/readers as read-only const linear block(s).
52629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar */
52729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarclass C2LinearBlock : public C2Block1D {
52829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarpublic:
52929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
53029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Maps this block into memory and returns a write view for it.
53129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
53229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \return a write view for this block.
53329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
53429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    C2Acquirable<C2WriteView> map();
53529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
53629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
53729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Creates a read-only const linear block for a portion of this block; optionally protected
53829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * by an acquire fence. There are two ways to use this:
53929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
54029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * 1) share ready block after writing data into the block. In this case no fence shall be
54129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *    supplied, and the block shall not be modified after calling this method.
54229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * 2) share block metadata before actually (finishing) writing the data into the block. In
54329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *    this case a fence must be supplied that will be triggered when the data is written.
54429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *    The block shall be modified only until firing the event for the fence.
54529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
54629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    C2ConstLinearBlock share(size_t offset, size_t size, C2Fence fence);
54729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar};
54829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
54929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/// @}
55029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
55129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/**************************************************************************************************
55229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar  CIRCULAR BLOCKS AND VIEWS
55329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar**************************************************************************************************/
55429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
55529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/// \defgroup circular Circular buffer support
55629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/// @{
55729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
55829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/**
55929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * Circular blocks can be used to share data between a writer and a reader (and/or other consumers)-
56029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * in a memory-efficient way by reusing a section of memory. Circular blocks are a bit more complex
56129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * than single reader/single writer schemes to facilitate block-based consuming of data.
56229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar *
56329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * They can operate in two modes:
56429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar *
56529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * 1) one writer that creates blocks to be consumed (this model can be used by components)
56629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar *
56729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * 2) one writer that writes continuously, and one reader that can creates blocks to be consumed
56829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar *    by further recipients (this model is used by the framework, and cannot be used by components.)
56929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar *
57029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * Circular blocks have four segments with running pointers:
57129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar *  - reserved: data reserved and available for the writer
57229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar *  - committed: data committed by the writer and available to the reader (if present)
57329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar *  - used: data used by consumers (if present)
57429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar *  - available: unused data available to be reserved
57529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar */
57629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarclass C2CircularBlock : public C2Block1D {
57729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    // TODO: add methods
57829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
57929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarprivate:
58029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    size_t mReserved __unused;   // end of reserved section
58129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    size_t mCommitted __unused;  // end of committed section
58229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    size_t mUsed __unused;       // end of used section
58329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    size_t mFree __unused;       // end of free section
58429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar};
58529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
58629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarclass _C2CircularBlockSegment : public _C2LinearCapacityAspect {
58729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarpublic:
58829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
58929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Returns the available size for this segment.
59029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
59129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \return currently available size for this segment
59229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
59329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    size_t available() const;
59429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
59529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
59629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Reserve some space for this segment from its current start.
59729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
59829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \param size    desired space in bytes
59929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \param fence   a pointer to an acquire fence. If non-null, the reservation is asynchronous and
60029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *              a fence will be stored here that will be signaled when the reservation is
60129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *              complete. If null, the reservation is synchronous.
60229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
60329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \retval C2_OK            the space was successfully reserved
60429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \retval C2_NO_MEMORY     the space requested cannot be reserved
60529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \retval C2_TIMED_OUT     the reservation timed out \todo when?
60629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \retval C2_CORRUPTED     some unknown error prevented reserving space. (unexpected)
60729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
60829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    C2Error reserve(size_t size, C2Fence *fence /* nullable */);
60929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
61029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
61129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Abandons a portion of this segment. This will move to the beginning of this segment.
61229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
61329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \note This methods is only allowed if this segment is producing blocks.
61429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
61529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \param size    number of bytes to abandon
61629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
61729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \retval C2_OK            the data was successfully abandoned
61829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \retval C2_TIMED_OUT     the operation timed out (unexpected)
61929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \retval C2_CORRUPTED     some unknown error prevented abandoning the data (unexpected)
62029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
62129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    C2Error abandon(size_t size);
62229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
62329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
62429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Share a portion as block(s) with consumers (these are moved to the used section).
62529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
62629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \note This methods is only allowed if this segment is producing blocks.
62729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \note Share does not move the beginning of the segment. (\todo add abandon/offset?)
62829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
62929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \param size    number of bytes to share
63029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \param fence   fence to be used for the section
63129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \param blocks  list where the blocks of the section are appended to
63229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
63329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \retval C2_OK            the portion was successfully shared
63429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \retval C2_NO_MEMORY     not enough memory to share the portion
63529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \retval C2_TIMED_OUT     the operation timed out (unexpected)
63629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \retval C2_CORRUPTED     some unknown error prevented sharing the data (unexpected)
63729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
63829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    C2Error share(size_t size, C2Fence fence, std::list<C2ConstLinearBlock> &blocks);
63929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
64029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
64129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Returns the beginning offset of this segment from the start of this circular block.
64229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
64329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * @return beginning offset
64429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
64529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    size_t begin();
64629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
64729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
64829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Returns the end offset of this segment from the start of this circular block.
64929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
65029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * @return end offset
65129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
65229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    size_t end();
65329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar};
65429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
65529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/**
65629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * A circular write-view is a dynamic mapped view for a segment of a circular block. Care must be
65729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * taken when using this view so that only the section owned by the segment is modified.
65829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar */
65929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarclass C2CircularWriteView : public _C2LinearCapacityAspect {
66029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarpublic:
66129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
66229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Start of the circular block.
66329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \note the segment does not own this pointer.
66429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
66529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \return pointer to the start of the circular block or nullptr on error.
66629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
66729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    uint8_t *base();
66829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
66929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
67029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \return error during the creation/mapping of this view.
67129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
67229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    C2Error error();
67329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar};
67429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
67529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/**
67629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * The writer of a circular buffer.
67729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar *
67829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * Can commit data to a reader (not supported for components) OR share data blocks directly with a
67929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * consumer.
68029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar *
68129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * If a component supports outputting data into circular buffers, it must allocate a circular
68229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * block and use a circular writer.
68329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar */
68429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarclass C2CircularWriter : public _C2CircularBlockSegment {
68529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarpublic:
68629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
68729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Commits a portion of this segment to the next segment. This moves the beginning of the
68829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * segment.
68929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
69029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \param size    number of bytes to commit to the next segment
69129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \param fence   fence used for the commit (the fence must signal before the data is committed)
69229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
69329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    C2Error commit(size_t size, C2Fence fence);
69429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
69529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
69629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Maps this block into memory and returns a write view for it.
69729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
69829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \return a write view for this block.
69929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
70029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    C2Acquirable<C2CircularWriteView> map();
70129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar};
70229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
70329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/// @}
70429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
70529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/// \defgroup graphic Graphic Data Blocks
70629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/// @{
70729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
70829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/**
70929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * Interface for objects that have a width and height (planar capacity).
71029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar */
71129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarclass _C2PlanarCapacityAspect {
71229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/// \name Planar capacity interface
71329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/// @{
71429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarpublic:
71529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline uint32_t width() const { return mWidth; }
71629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline uint32_t height() const { return mHeight; }
71729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
71829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarprotected:
71929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline _C2PlanarCapacityAspect(uint32_t width, uint32_t height)
72029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar      : mWidth(width), mHeight(height) { }
72129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
72229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline _C2PlanarCapacityAspect(const _C2PlanarCapacityAspect *parent)
72329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        : mWidth(parent == nullptr ? 0 : parent->width()),
72429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar          mHeight(parent == nullptr ? 0 : parent->height()) { }
72529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
72629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarprivate:
72729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    const uint32_t mWidth;
72829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    const uint32_t mHeight;
72929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/// @}
73029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar};
73129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
73229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/**
73329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * C2Rect: rectangle type with non-negative coordinates.
73429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar *
73529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * \note This struct has public fields without getters/setters. All methods are inline.
73629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar */
73729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarstruct C2Rect {
73829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar// public:
73929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    uint32_t mLeft;
74029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    uint32_t mTop;
74129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    uint32_t mWidth;
74229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    uint32_t mHeight;
74329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
74429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline C2Rect(uint32_t width, uint32_t height)
74529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        : C2Rect(width, height, 0, 0) { }
74629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
74729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline C2Rect(uint32_t width, uint32_t height, uint32_t left, uint32_t top)
74829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        : mLeft(left), mTop(top), mWidth(width), mHeight(height) { }
74929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
75029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    // utility methods
75129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
75229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline bool isEmpty() const {
75329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        return mWidth == 0 || mHeight == 0;
75429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    }
75529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
75629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline bool isValid() const {
75729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        return mLeft <= ~mWidth && mTop <= ~mHeight;
75829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    }
75929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
76029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline operator bool() const {
76129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        return isValid() && !isEmpty();
76229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    }
76329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
76429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline bool operator!() const {
76529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        return !bool(*this);
76629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    }
76729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
76829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline bool contains(const C2Rect &other) const {
76929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        if (!isValid() || !other.isValid()) {
77029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar            return false;
77129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        } else if (other.isEmpty()) {
77229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar            return true;
77329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        } else {
77429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar            return mLeft <= other.mLeft && mTop <= other.mTop
77529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar                    && mLeft + mWidth >= other.mLeft + other.mWidth
77629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar                    && mTop + mHeight >= other.mTop + other.mHeight;
77729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        }
77829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    }
77929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
78029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline bool operator==(const C2Rect &other) const {
78129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        if (!isValid()) {
78229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar            return !other.isValid();
78329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        } else if (isEmpty()) {
78429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar            return other.isEmpty();
78529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        } else {
78629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar            return mLeft == other.mLeft && mTop == other.mTop
78729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar                    && mWidth == other.mWidth && mHeight == other.mHeight;
78829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        }
78929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    }
79029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
79129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline bool operator!=(const C2Rect &other) const {
79229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        return !operator==(other);
79329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    }
79429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
79529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline bool operator>=(const C2Rect &other) const {
79629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        return contains(other);
79729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    }
79829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
79929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline bool operator>(const C2Rect &other) const {
80029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        return contains(other) && !operator==(other);
80129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    }
80229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
80329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline bool operator<=(const C2Rect &other) const {
80429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        return other.contains(*this);
80529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    }
80629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
80729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline bool operator<(const C2Rect &other) const {
80829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        return other.contains(*this) && !operator==(other);
80929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    }
81029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar};
81129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
81229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/**
81329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * C2PlaneInfo: information on the layout of flexible planes.
81429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar *
81529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * Public fields without getters/setters.
81629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar */
81729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarstruct C2PlaneInfo {
81829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar// public:
81929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    enum Channel : uint32_t {
82029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        Y,
82129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        R,
82229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        G,
82329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        B,
82429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        A,
82529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        Cr,
82629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        Cb,
82729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    } mChannel;
82829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
82929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    int32_t mColInc;               // column increment in bytes. may be negative
83029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    int32_t mRowInc;               // row increment in bytes. may be negative
83129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    uint32_t mHorizSubsampling;    // subsampling compared to width
83229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    uint32_t mVertSubsampling;     // subsampling compared to height
83329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
83429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    uint32_t mBitDepth;
83529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    uint32_t mAllocatedDepth;
83629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
83729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline ssize_t minOffset(uint32_t width, uint32_t height) {
83829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        ssize_t offs = 0;
83929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        if (width > 0 && mColInc < 0) {
84029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar            offs += mColInc * (ssize_t)(width - 1);
84129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        }
84229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        if (height > 0 && mRowInc < 0) {
84329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar            offs += mRowInc * (ssize_t)(height - 1);
84429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        }
84529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        return offs;
84629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    }
84729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
84829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline ssize_t maxOffset(uint32_t width, uint32_t height, uint32_t allocatedDepth) {
84929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        ssize_t offs = (allocatedDepth + 7) >> 3;
85029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        if (width > 0 && mColInc > 0) {
85129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar            offs += mColInc * (ssize_t)(width - 1);
85229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        }
85329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        if (height > 0 && mRowInc > 0) {
85429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar            offs += mRowInc * (ssize_t)(height - 1);
85529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        }
85629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        return offs;
85729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    }
85829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar};
85929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
86029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarstruct C2PlaneLayout {
86129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarpublic:
86229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    enum Type : uint32_t {
86329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        MEDIA_IMAGE_TYPE_UNKNOWN = 0,
86429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        MEDIA_IMAGE_TYPE_YUV = 0x100,
86529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        MEDIA_IMAGE_TYPE_YUVA,
86629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        MEDIA_IMAGE_TYPE_RGB,
86729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        MEDIA_IMAGE_TYPE_RGBA,
86829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    };
86929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
87029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    Type mType;
87129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    uint32_t mNumPlanes;               // number of planes
87229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
87329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    enum PlaneIndex : uint32_t {
87429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        Y = 0,
87529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        U = 1,
87629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        V = 2,
87729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        R = 0,
87829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        G = 1,
87929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        B = 2,
88029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        A = 3,
88129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        MAX_NUM_PLANES = 4,
88229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    };
88329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
88429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    C2PlaneInfo mPlanes[MAX_NUM_PLANES];
88529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar};
88629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
88729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/**
88829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * Aspect for objects that have a planar section (crop rectangle).
88929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar *
89029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * This class is copiable.
89129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar */
89229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarclass _C2PlanarSection : public _C2PlanarCapacityAspect {
89329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/// \name Planar section interface
89429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/// @{
89529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarpublic:
89629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    // crop can be an empty rect, does not have to line up with subsampling
89729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    // NOTE: we do not support floating-point crop
89829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline const C2Rect crop() { return mCrop; }
89929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
90029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
90129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *  Sets crop to crop intersected with [(0,0) .. (width, height)]
90229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
90329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline void setCrop_be(const C2Rect &crop);
90429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
90529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
90629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * If crop is within the dimensions of this object, it sets crop to it.
90729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
90829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \return true iff crop is within the dimensions of this object
90929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
91029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    inline bool setCrop(const C2Rect &crop);
91129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
91229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarprivate:
91329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    C2Rect mCrop;
91429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/// @}
91529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar};
91629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
91729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarclass C2Block2D : public _C2PlanarSection {
91829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarpublic:
91929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    const C2Handle *handle() const;
92029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
92129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarprivate:
92229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    class Impl;
92329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    std::shared_ptr<Impl> mImpl;
92429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar};
92529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
92629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/**
92729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * Graphic view provides read or read-write access for a graphic block.
92829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar *
92929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * This class is copiable.
93029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar *
93129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * \note Due to the subsampling of graphic buffers, a read view must still contain a crop rectangle
93229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * to ensure subsampling is followed. This results in nearly identical interface between read and
93329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * write views, so C2GraphicView can encompass both of them.
93429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar */
93529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarclass C2GraphicView : public _C2PlanarSection {
93629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarpublic:
93729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
93829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \return pointer to the start of the block or nullptr on error.
93929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
94029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    const uint8_t *data() const;
94129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
94229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
94329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \return pointer to the start of the block or nullptr on error.
94429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
94529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    uint8_t *data();
94629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
94729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
94829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Returns a section of this view.
94929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
95029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \param rect    the dimension of the section. \note This is clamped to the crop of this view.
95129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
95229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \return a read view containing the requested section of this view
95329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
95429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    const C2GraphicView subView(const C2Rect &rect) const;
95529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    C2GraphicView subView(const C2Rect &rect);
95629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
95729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
95829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \return error during the creation/mapping of this view.
95929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
96029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    C2Error error() const;
96129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
96229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarprivate:
96329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    class Impl;
96429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    std::shared_ptr<Impl> mImpl;
96529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar};
96629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
96729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/**
96829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * A constant (read-only) graphic block (portion of an allocation) with an acquire fence.
96929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * Blocks are unmapped when created, and can be mapped into a read view on demand.
97029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar *
97129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * This class is copiable and contains a reference to the allocation that it is based on.
97229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar */
97329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarclass C2ConstGraphicBlock : public C2Block2D {
97429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarpublic:
97529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
97629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Maps this block into memory and returns a read view for it.
97729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
97829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \return a read view for this block.
97929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
98029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    C2Acquirable<const C2GraphicView> map() const;
98129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
98229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
98329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Returns a section of this block.
98429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
98529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \param rect    the coordinates of the section. \note This is clamped to the crop rectangle of
98629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *              this block.
98729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
98829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \return a constant graphic block containing a portion of this block
98929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
99029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    C2ConstGraphicBlock subBlock(const C2Rect &rect) const;
99129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
99229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
99329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Returns the acquire fence for this block.
99429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
99529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \return a fence that must be waited on before reading the block.
99629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
99729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    C2Fence fence() const { return mFence; }
99829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
99929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarprivate:
100029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    C2Fence mFence;
100129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar};
100229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
100329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/**
100429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * Graphic block is a writeable 2D block. Once written, it can be shared in whole or in part with
100529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * consumers/readers as read-only const graphic block.
100629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar */
100729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarclass C2GraphicBlock : public C2Block2D {
100829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarpublic:
100929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
101029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Maps this block into memory and returns a write view for it.
101129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
101229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * \return a write view for this block.
101329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
101429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    C2Acquirable<C2GraphicView> map();
101529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
101629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
101729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * Creates a read-only const linear block for a portion of this block; optionally protected
101829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * by an acquire fence. There are two ways to use this:
101929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *
102029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * 1) share ready block after writing data into the block. In this case no fence shall be
102129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *    supplied, and the block shall not be modified after calling this method.
102229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     * 2) share block metadata before actually (finishing) writing the data into the block. In
102329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *    this case a fence must be supplied that will be triggered when the data is written.
102429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *    The block shall be modified only until firing the event for the fence.
102529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
102629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    C2ConstGraphicBlock share(const C2Rect &crop, C2Fence fence);
102729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar};
102829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
102929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/// @}
103029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
103129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/// \defgroup buffer_onj Buffer objects
103229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/// @{
103329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
103429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar// ================================================================================================
103529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar//  BUFFERS
103629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar// ================================================================================================
103729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
103829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/// \todo: Do we still need this?
103929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar///
104029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar// There are 2 kinds of buffers: linear or graphic. Linear buffers can contain a single block, or
104129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar// a list of blocks (LINEAR_CHUNKS). Support for list of blocks is optional, and can allow consuming
104229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar// data from circular buffers or scattered data sources without extra memcpy. Currently, list of
104329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar// graphic blocks is not supported.
104429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
104529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarclass C2LinearBuffer;   // read-write buffer
104629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarclass C2GraphicBuffer;  // read-write buffer
104729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarclass C2LinearChunksBuffer;
104829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar
104929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar/**
105029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * C2BufferData: the main, non-meta data of a buffer. A buffer can contain either linear blocks
105129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * or graphic blocks, and can contain either a single block or multiple blocks. This is determined
105229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar * by its type.
105329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar */
105429a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarclass C2BufferData {
105529a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnarpublic:
105629a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    /**
105729a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     *  The type of buffer data.
105829a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar     */
105929a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar    enum Type : uint32_t {
106029a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        LINEAR,             ///< the buffer contains a single linear block
106129a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        LINEAR_CHUNKS,      ///< the buffer contains one or more linear blocks
106229a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        GRAPHIC,            ///< the buffer contains a single graphic block
106329a6ba9949e4127a9c6df2cc75033dbe97f501a9Lajos Molnar        GRAPHIC_CHUNKS,     ///< the buffer contains one of more graphic blocks
1064