/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <utils/Timers.h>

#include <optional>
#include <string>

#include "Properties.h"
#include "SkSize.h"
#include "SkippedFrameInfo.h"
#include "utils/Macros.h"

namespace android {
namespace uirenderer {

namespace renderthread {
class CanvasContext;
}

class DamageAccumulator;
class LayerUpdateQueue;
class RenderNode;
class RenderState;

class ErrorHandler {
public:
    virtual void onError(const std::string& message) = 0;

    virtual ~ErrorHandler() = default;
};

class TreeObserver {
public:
    // Called when a RenderNode's parent count hits 0.
    // Due to the unordered nature of tree pushes, once prepareTree
    // is finished it is possible that the node was "resurrected" and has
    // a non-zero parent count.
    virtual void onMaybeRemovedFromTree(RenderNode* node) = 0;

protected:
    virtual ~TreeObserver() = default;
};

// This would be a struct, but we want to PREVENT_COPY_AND_ASSIGN
class TreeInfo {
    PREVENT_COPY_AND_ASSIGN(TreeInfo);

public:
    enum TraversalMode {
        // The full monty - sync, push, run animators, etc... Used by DrawFrameTask
        // May only be used if both the UI thread and RT thread are blocked on the
        // prepare
        MODE_FULL,
        // Run only what can be done safely on RT thread. Currently this only means
        // animators, but potentially things like SurfaceTexture updates
        // could be handled by this as well if there are no listeners
        MODE_RT_ONLY,
    };

    TreeInfo(TraversalMode mode, renderthread::CanvasContext& canvasContext);

    TraversalMode mode;
    // TODO: Remove this? Currently this is used to signal to stop preparing
    // textures if we run out of cache space.
    bool prepareTextures;
    renderthread::CanvasContext& canvasContext;
    // TODO: buildLayer uses this to suppress running any animations, but this
    // should probably be refactored somehow. The reason this is done is
    // because buildLayer is not setup for injecting the animationHook, as well
    // as this being otherwise wasted work as all the animators will be
    // re-evaluated when the frame is actually drawn
    bool runAnimations = true;

    // Must not be null during actual usage
    DamageAccumulator* damageAccumulator = nullptr;
    int64_t damageGenerationId = 0;

    LayerUpdateQueue* layerUpdateQueue = nullptr;
    ErrorHandler* errorHandler = nullptr;

    bool updateWindowPositions = false;

    int disableForceDark;

    const SkISize screenSize;

    int stretchEffectCount = 0;

    bool forceDrawFrame = false;

    struct Out {
        bool hasFunctors = false;
        // This is only updated if evaluateAnimations is true
        bool hasAnimations = false;
        // This is set to true if there is an animation that RenderThread cannot
        // animate itself, such as if hasFunctors is true
        // This is only set if hasAnimations is true
        bool requiresUiRedraw = false;
        // This is set to nullopt if draw() can be called this frame
        // A value means that we must delay until the next vsync pulse as frame
        // production is outrunning consumption
        // NOTE that if this has a value CanvasContext will set either requiresUiRedraw
        // *OR* will post itself for the next vsync automatically, use this
        // only to avoid calling draw()
        std::optional<SkippedFrameReason> skippedFrameReason;
        // Sentinel for animatedImageDelay meaning there is no need to post such
        // a message.
        static constexpr nsecs_t kNoAnimatedImageDelay = -1;
        // This is used to post a message to redraw when it is time to draw the
        // next frame of an AnimatedImageDrawable.
        nsecs_t animatedImageDelay = kNoAnimatedImageDelay;
        // This is used to determine if there were only TextureView updates in this frame.
        // This info is passed to SurfaceFlinger to determine whether it should use vsyncIds
        // for refresh rate selection.
        bool solelyTextureViewUpdates = true;
    } out;

    // This flag helps to disable projection for receiver nodes that do not have any backward
    // projected children.
    bool hasBackwardProjectedNodes = false;
    // TODO: Damage calculations
};

} /* namespace uirenderer */
} /* namespace android */
