File: video_frame_image_util.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (135 lines) | stat: -rw-r--r-- 5,634 bytes parent folder | download | duplicates (5)
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
135
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_VIDEO_FRAME_IMAGE_UTIL_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_VIDEO_FRAME_IMAGE_UTIL_H_

#include <memory>

#include "base/memory/scoped_refptr.h"
#include "components/viz/common/resources/shared_image_format.h"
#include "media/base/video_transformation.h"
#include "third_party/blink/renderer/platform/graphics/image_orientation.h"
#include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/skia/include/core/SkAlphaType.h"
#include "ui/gfx/color_space.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"

// Note: Don't include "media/base/video_frame.h" here without good reason,
// since it includes a lot of non-blink types which can pollute the namespace.
namespace media {
class PaintCanvasVideoRenderer;
class VideoFrame;
}  // namespace media

namespace viz {
class RasterContextProvider;
}

namespace cc {
class PaintCanvas;
class PaintFlags;
}  // namespace cc

namespace blink {
class CanvasResourceProvider;
class StaticBitmapImage;

// Converts a media orientation into a blink one or vice versa.
PLATFORM_EXPORT ImageOrientationEnum
VideoTransformationToImageOrientation(media::VideoTransformation transform);
PLATFORM_EXPORT media::VideoTransformation
ImageOrientationToVideoTransformation(ImageOrientationEnum orientation);

// Returns true if CreateImageFromVideoFrame() expects to create an
// AcceleratedStaticBitmapImage. Note: This may be overridden if a software
// |resource_provider| is given to CreateImageFromVideoFrame().
PLATFORM_EXPORT bool WillCreateAcceleratedImagesFromVideoFrame(
    const media::VideoFrame* frame);

// Returns a StaticBitmapImage for the given frame. Accelerated images will be
// preferred if possible. A zero copy mechanism will be preferred if possible
// unless |allow_zero_copy_images| is false.
//
// |video_renderer| may optionally be provided in cases where the same frame may
// end up repeatedly converted.
//
// Likewise |resource_provider| may be provided to prevent thrashing when this
// method is called with high frequency.
//
// The default resource provider size is the frame's visible size. The default
// |dest_rect| is the visible size aligned to the origin. Callers may choose to
// provide their own |resource_provider| and |dest_rect| for rendering to the
// frame's natural size.
//
// When an external |resource_provider| is provided a |dest_rect| may also be
// provided to control where in the canvas the VideoFrame will be drawn. A
// non-empty |dest_rect| will disable zero copy image support.
//
// If |prefer_tagged_orientation| is true, CreateImageFromVideoFrame() will just
// tag the StaticBitmapImage with the correct orientation ("soft flip") instead
// of drawing the frame with the correct orientation ("hard flip").
//
// If `reinterpret_video_as_srgb` true, then the video will be reinterpreted as
// being originally having been in sRGB.
//
// Returns nullptr if a StaticBitmapImage can't be created.
PLATFORM_EXPORT scoped_refptr<StaticBitmapImage> CreateImageFromVideoFrame(
    scoped_refptr<media::VideoFrame> frame,
    bool allow_zero_copy_images = true,
    CanvasResourceProvider* resource_provider = nullptr,
    media::PaintCanvasVideoRenderer* video_renderer = nullptr,
    const gfx::Rect& dest_rect = gfx::Rect(),
    bool prefer_tagged_orientation = true,
    bool reinterpret_video_as_srgb = false);

// Similar to the above, but just skips creating the StaticBitmapImage from the
// CanvasResourceProvider. Returns true if the frame could be drawn or false
// otherwise. Note: In certain failure modes a black frame will be drawn.
//
// |video_renderer| may optionally be provided in cases where the same frame may
// end up repeatedly drawn.
//
// A |raster_context_provider| is required to convert texture backed frames.
//
// If |ignore_video_transformation| is true, the media::VideoTransformation on
// the |frame| will be ignored.
//
// If `reinterpret_video_as_srgb` true, then the video will be reinterpreted as
// being originally having been in sRGB.
PLATFORM_EXPORT bool DrawVideoFrameIntoResourceProvider(
    scoped_refptr<media::VideoFrame> frame,
    CanvasResourceProvider* resource_provider,
    viz::RasterContextProvider* raster_context_provider,
    const gfx::Rect& dest_rect,
    media::PaintCanvasVideoRenderer* video_renderer = nullptr,
    bool ignore_video_transformation = false,
    bool reinterpret_video_as_srgb = false);

PLATFORM_EXPORT void DrawVideoFrameIntoCanvas(
    scoped_refptr<media::VideoFrame> frame,
    cc::PaintCanvas* canvas,
    cc::PaintFlags& flags,
    bool ignore_video_transformation = false);

// Extract a RasterContextProvider from the current SharedGpuContext.
PLATFORM_EXPORT scoped_refptr<viz::RasterContextProvider>
GetRasterContextProvider();

// Creates a CanvasResourceProvider which is appropriate for drawing VideoFrame
// objects into. Some callers to CreateImageFromVideoFrame() may choose to cache
// their resource providers. If |raster_context_provider| is null a software
// resource provider will be returned.
PLATFORM_EXPORT std::unique_ptr<CanvasResourceProvider>
CreateResourceProviderForVideoFrame(
    gfx::Size size,
    viz::SharedImageFormat format,
    SkAlphaType alpha_type,
    const gfx::ColorSpace& color_space,
    viz::RasterContextProvider* raster_context_provider);

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_VIDEO_FRAME_IMAGE_UTIL_H_