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_FILTERS_SKCANVAS_VIDEO_RENDERER_H_
6 #define MEDIA_FILTERS_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/video_rotation.h"
13 #include "third_party/skia/include/core/SkBitmap.h"
14 #include "third_party/skia/include/core/SkXfermode.h"
15 #include "ui/gfx/rect.h"
22 class VideoImageGenerator
;
24 // Handles rendering of VideoFrames to SkCanvases, doing any necessary YUV
25 // conversion and caching of resulting RGB bitmaps.
26 class MEDIA_EXPORT SkCanvasVideoRenderer
{
28 SkCanvasVideoRenderer();
29 ~SkCanvasVideoRenderer();
31 // Paints |video_frame| on |canvas|, scaling and rotating the result to fit
32 // dimensions specified by |dest_rect|.
34 // Black will be painted on |canvas| if |video_frame| is null.
35 void Paint(const scoped_refptr
<VideoFrame
>& video_frame
,
37 const gfx::RectF
& dest_rect
,
39 SkXfermode::Mode mode
,
40 VideoRotation video_rotation
);
42 // Copy |video_frame| on |canvas|.
43 void Copy(const scoped_refptr
<VideoFrame
>&, SkCanvas
* canvas
);
46 void ResetLastFrame();
47 void ResetAcceleratedLastFrame();
49 // An RGB bitmap and corresponding timestamp of the previously converted
50 // video frame data by software color space conversion.
52 base::TimeDelta last_frame_timestamp_
;
53 // If |last_frame_| is not used for a while, it's deleted to save memory.
54 base::DelayTimer
<SkCanvasVideoRenderer
> frame_deleting_timer_
;
56 // This is a hardware accelerated copy of the frame generated by
57 // |accelerated_generator_|.
58 // It's used when |canvas| parameter in Paint() is Ganesh canvas.
59 // Note: all GrContext in SkCanvas instances are same.
60 SkBitmap accelerated_last_frame_
;
61 VideoImageGenerator
* accelerated_generator_
;
62 base::TimeDelta accelerated_last_frame_timestamp_
;
63 base::DelayTimer
<SkCanvasVideoRenderer
> accelerated_frame_deleting_timer_
;
65 DISALLOW_COPY_AND_ASSIGN(SkCanvasVideoRenderer
);
70 #endif // MEDIA_FILTERS_SKCANVAS_VIDEO_RENDERER_H_