1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_VIZ_COMMON_QUADS_COMPOSITOR_FRAME_TRANSITION_DIRECTIVE_H_
#define COMPONENTS_VIZ_COMMON_QUADS_COMPOSITOR_FRAME_TRANSITION_DIRECTIVE_H_
#include <string>
#include <vector>
#include "base/time/time.h"
#include "components/viz/common/quads/compositor_render_pass.h"
#include "components/viz/common/view_transition_element_resource_id.h"
#include "components/viz/common/viz_common_export.h"
#include "ui/gfx/display_color_spaces.h"
namespace viz {
// This is a transition directive that can be associated with a compositor
// frame. The intent is to be able to animate a compositor frame into the right
// place instead of simply drawing the final result at the final destination.
// This is used by a JavaScript-exposed view transitions API. See
// third_party/blink/renderer/core/view_transition/README.md for more
// information.
class VIZ_COMMON_EXPORT CompositorFrameTransitionDirective {
public:
// What is the directive?
// - Save means that the currently submitted frame will be used in the future
// as the source frame of the animation. The animation could be driven by
// the renderer or Viz process. This directive must be followed by the
// Animate or AnimateRenderer directive.
//
// - AnimateRenderer means that content in the current and subsequent frames
// will use cached resources from the frame with the Save directive.
// Ownership of the cached resources is passed to the renderer process. This
// directive must be followed by Release to delete the cached resources.
//
// - Release means that cached textures in the Viz process can be deleted.
// This is used in the mode where the renderer is driving this animation.
enum class Type { kSave, kAnimateRenderer, kRelease };
struct VIZ_COMMON_EXPORT SharedElement {
SharedElement();
~SharedElement();
SharedElement(const SharedElement&);
SharedElement& operator=(const SharedElement&);
SharedElement(SharedElement&&);
SharedElement& operator=(SharedElement&&);
friend bool operator==(const SharedElement&,
const SharedElement&) = default;
// The render pass corresponding to a DOM element. The id is scoped to the
// same frame that the directive corresponds to.
CompositorRenderPassId render_pass_id;
// An identifier to tag the cached texture for this shared element in the
// Viz process.
ViewTransitionElementResourceId view_transition_element_resource_id;
};
// This is public only for mojo deserialization.
CompositorFrameTransitionDirective();
static CompositorFrameTransitionDirective CreateSave(
const blink::ViewTransitionToken& transition_token,
bool maybe_cross_frame_sink,
uint32_t sequence_id,
std::vector<SharedElement> shared_elements,
const gfx::DisplayColorSpaces& display_color_spaces);
static CompositorFrameTransitionDirective CreateAnimate(
const blink::ViewTransitionToken& transition_token,
bool maybe_cross_frame_sink,
uint32_t sequence_id);
static CompositorFrameTransitionDirective CreateRelease(
const blink::ViewTransitionToken& transition_token,
bool maybe_cross_frame_sink,
uint32_t sequence_id);
CompositorFrameTransitionDirective(const CompositorFrameTransitionDirective&);
~CompositorFrameTransitionDirective();
CompositorFrameTransitionDirective& operator=(
const CompositorFrameTransitionDirective&);
// A monotonically increasing sequence_id for a given communication channel
// (i.e. surface). This is used to distinguish new directives from directives
// that have already been processed.
uint32_t sequence_id() const { return sequence_id_; }
// The type of this directive.
Type type() const { return type_; }
blink::ViewTransitionToken transition_token() const {
return transition_token_;
}
// Shared elements.
const std::vector<SharedElement>& shared_elements() const {
return shared_elements_;
}
bool maybe_cross_frame_sink() const { return maybe_cross_frame_sink_; }
const gfx::DisplayColorSpaces& display_color_spaces() const {
return display_color_spaces_;
}
private:
CompositorFrameTransitionDirective(
const blink::ViewTransitionToken& transition_token,
bool maybe_cross_frame_sink,
uint32_t sequence_id,
Type type,
std::vector<SharedElement> shared_elements = {},
const gfx::DisplayColorSpaces& display_color_spaces = {});
blink::ViewTransitionToken transition_token_;
bool maybe_cross_frame_sink_ = false;
uint32_t sequence_id_ = 0;
Type type_ = Type::kSave;
std::vector<SharedElement> shared_elements_;
gfx::DisplayColorSpaces display_color_spaces_;
};
} // namespace viz
#endif // COMPONENTS_VIZ_COMMON_QUADS_COMPOSITOR_FRAME_TRANSITION_DIRECTIVE_H_
|