This sets up API to release OutputSurface from LTHClient.
[chromium-blink-merge.git] / media / blink / skcanvas_video_renderer.h
blobb82fe0a7847457d3684257654d8d38198a268b17
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef MEDIA_BLINK_SKCANVAS_VIDEO_RENDERER_H_
6 #define MEDIA_BLINK_SKCANVAS_VIDEO_RENDERER_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/time/time.h"
10 #include "base/timer/timer.h"
11 #include "media/base/media_export.h"
12 #include "media/base/timestamp_constants.h"
13 #include "media/base/video_frame.h"
14 #include "media/base/video_rotation.h"
15 #include "media/filters/context_3d.h"
16 #include "skia/ext/refptr.h"
17 #include "third_party/skia/include/core/SkImage.h"
18 #include "third_party/skia/include/core/SkXfermode.h"
20 class SkCanvas;
21 class SkImage;
23 namespace gfx {
24 class RectF;
27 namespace media {
28 class VideoImageGenerator;
30 // Handles rendering of VideoFrames to SkCanvases.
31 class MEDIA_EXPORT SkCanvasVideoRenderer {
32 public:
33 SkCanvasVideoRenderer();
34 ~SkCanvasVideoRenderer();
36 // Paints |video_frame| on |canvas|, scaling and rotating the result to fit
37 // dimensions specified by |dest_rect|.
38 // If the format of |video_frame| is PIXEL_FORMAT_NATIVE_TEXTURE, |context_3d|
39 // must be provided.
41 // Black will be painted on |canvas| if |video_frame| is null.
42 void Paint(const scoped_refptr<VideoFrame>& video_frame,
43 SkCanvas* canvas,
44 const gfx::RectF& dest_rect,
45 uint8 alpha,
46 SkXfermode::Mode mode,
47 VideoRotation video_rotation,
48 const Context3D& context_3d);
50 // Copy |video_frame| on |canvas|.
51 // If the format of |video_frame| is PIXEL_FORMAT_NATIVE_TEXTURE, |context_3d|
52 // must be provided.
53 void Copy(const scoped_refptr<VideoFrame>& video_frame,
54 SkCanvas* canvas,
55 const Context3D& context_3d);
57 // Convert the contents of |video_frame| to raw RGB pixels. |rgb_pixels|
58 // should point into a buffer large enough to hold as many 32 bit RGBA pixels
59 // as are in the visible_rect() area of the frame.
60 static void ConvertVideoFrameToRGBPixels(const media::VideoFrame* video_frame,
61 void* rgb_pixels,
62 size_t row_bytes);
64 // Copy the contents of texture of |video_frame| to texture |texture|.
65 // |level|, |internal_format|, |type| specify target texture |texture|.
66 // The format of |video_frame| must be VideoFrame::NATIVE_TEXTURE.
67 static void CopyVideoFrameSingleTextureToGLTexture(
68 gpu::gles2::GLES2Interface* gl,
69 VideoFrame* video_frame,
70 unsigned int texture,
71 unsigned int internal_format,
72 unsigned int type,
73 bool premultiply_alpha,
74 bool flip_y);
76 private:
77 void ResetCache();
79 // Last image used to draw to the canvas.
80 skia::RefPtr<SkImage> last_image_;
81 // Timestamp of the videoframe used to generate |last_image_|.
82 base::TimeDelta last_timestamp_ = media::kNoTimestamp();
83 // If |last_image_| is not used for a while, it's deleted to save memory.
84 base::DelayTimer<SkCanvasVideoRenderer> last_image_deleting_timer_;
86 DISALLOW_COPY_AND_ASSIGN(SkCanvasVideoRenderer);
89 } // namespace media
91 #endif // MEDIA_BLINK_SKCANVAS_VIDEO_RENDERER_H_