Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: media/filters/skcanvas_video_renderer.h

Issue 445013002: media: Optimize HW Video to 2D Canvas copy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Resolve comments, rebase to ToT Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MEDIA_FILTERS_SKCANVAS_VIDEO_RENDERER_H_ 5 #ifndef MEDIA_FILTERS_SKCANVAS_VIDEO_RENDERER_H_
6 #define MEDIA_FILTERS_SKCANVAS_VIDEO_RENDERER_H_ 6 #define MEDIA_FILTERS_SKCANVAS_VIDEO_RENDERER_H_
7 7
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "base/timer/timer.h" 10 #include "base/timer/timer.h"
11 #include "media/base/media_export.h" 11 #include "media/base/media_export.h"
12 #include "media/base/video_rotation.h" 12 #include "media/base/video_rotation.h"
13 #include "media/filters/context_3d_provider.h"
13 #include "third_party/skia/include/core/SkBitmap.h" 14 #include "third_party/skia/include/core/SkBitmap.h"
15 #include "third_party/skia/include/core/SkCanvas.h"
14 #include "third_party/skia/include/core/SkXfermode.h" 16 #include "third_party/skia/include/core/SkXfermode.h"
15 #include "ui/gfx/rect.h" 17 #include "ui/gfx/rect.h"
16 18
17 class SkCanvas;
18
19 namespace media { 19 namespace media {
20 20
21 class VideoFrame; 21 class VideoFrame;
22 class VideoImageGenerator; 22 class VideoImageGenerator;
23 23
24 // Handles rendering of VideoFrames to SkCanvases, doing any necessary YUV 24 // Handles rendering of VideoFrames to SkCanvases, doing any necessary YUV
25 // conversion and caching of resulting RGB bitmaps. 25 // conversion and caching of resulting RGB bitmaps.
26 class MEDIA_EXPORT SkCanvasVideoRenderer { 26 class MEDIA_EXPORT SkCanvasVideoRenderer {
27 public: 27 public:
28 SkCanvasVideoRenderer(); 28 SkCanvasVideoRenderer();
29 ~SkCanvasVideoRenderer(); 29 ~SkCanvasVideoRenderer();
30 30
31 // Paints |video_frame| on |canvas|, scaling and rotating the result to fit 31 // Paints |video_frame| on |canvas|, scaling and rotating the result to fit
32 // dimensions specified by |dest_rect|. 32 // dimensions specified by |dest_rect|.
33 // 33 //
34 // Black will be painted on |canvas| if |video_frame| is null. 34 // Black will be painted on |canvas| if |video_frame| is null.
35 void Paint(const scoped_refptr<VideoFrame>& video_frame, 35 void Paint(const scoped_refptr<VideoFrame>& video_frame,
36 SkCanvas* canvas, 36 SkCanvas* canvas,
37 const gfx::RectF& dest_rect, 37 const gfx::RectF& dest_rect,
38 uint8 alpha, 38 uint8 alpha,
39 SkXfermode::Mode mode, 39 SkXfermode::Mode mode,
40 VideoRotation video_rotation); 40 VideoRotation video_rotation,
41 const Context3DProvider& context_provider);
41 42
42 // Copy |video_frame| on |canvas|. 43 // Copy |video_frame| on |canvas|.
43 void Copy(const scoped_refptr<VideoFrame>&, SkCanvas* canvas); 44 void Copy(const scoped_refptr<VideoFrame>&, SkCanvas* canvas);
44 45
46 static void CopyVideoFrameTextureToGLTexture(gpu::gles2::GLES2Interface* gl,
scherkus (not reviewing) 2014/10/30 20:40:13 can we get documentation? for example, it'd be go
dshwang 2014/10/31 09:29:17 Done.
47 media::VideoFrame* video_frame,
scherkus (not reviewing) 2014/10/30 20:40:13 nit: typically we pass these as const-ref (you can
danakj 2014/10/30 21:04:20 If you don't need a reference, passing a T* is mor
dshwang 2014/10/31 09:29:17 I preserve T* because it doesn't need to take a re
48 unsigned int texture,
49 unsigned int level,
50 unsigned int internal_format,
51 unsigned int type,
52 bool premultiply_alpha,
53 bool flip_y);
54
45 private: 55 private:
46 void ResetLastFrame(); 56 void ResetLastFrame();
47 void ResetAcceleratedLastFrame(); 57 void ResetAcceleratedLastFrame();
48 58
49 // An RGB bitmap and corresponding timestamp of the previously converted 59 // An RGB bitmap and corresponding timestamp of the previously converted
50 // video frame data by software color space conversion. 60 // video frame data by software color space conversion.
51 SkBitmap last_frame_; 61 SkBitmap last_frame_;
52 base::TimeDelta last_frame_timestamp_; 62 base::TimeDelta last_frame_timestamp_;
53 // If |last_frame_| is not used for a while, it's deleted to save memory. 63 // If |last_frame_| is not used for a while, it's deleted to save memory.
54 base::DelayTimer<SkCanvasVideoRenderer> frame_deleting_timer_; 64 base::DelayTimer<SkCanvasVideoRenderer> frame_deleting_timer_;
55 65
56 // This is a hardware accelerated copy of the frame generated by 66 // This is a hardware accelerated copy of the frame generated by
57 // |accelerated_generator_|. 67 // |accelerated_generator_|.
58 // It's used when |canvas| parameter in Paint() is Ganesh canvas. 68 // It's used when |canvas| parameter in Paint() is Ganesh canvas.
59 // Note: all GrContext in SkCanvas instances are same. 69 // Note: all GrContext in SkCanvas instances are same.
60 SkBitmap accelerated_last_frame_; 70 SkBitmap accelerated_last_frame_;
61 VideoImageGenerator* accelerated_generator_; 71 VideoImageGenerator* accelerated_generator_;
62 base::TimeDelta accelerated_last_frame_timestamp_; 72 base::TimeDelta accelerated_last_frame_timestamp_;
63 base::DelayTimer<SkCanvasVideoRenderer> accelerated_frame_deleting_timer_; 73 base::DelayTimer<SkCanvasVideoRenderer> accelerated_frame_deleting_timer_;
64 74
65 DISALLOW_COPY_AND_ASSIGN(SkCanvasVideoRenderer); 75 DISALLOW_COPY_AND_ASSIGN(SkCanvasVideoRenderer);
66 }; 76 };
67 77
68 } // namespace media 78 } // namespace media
69 79
70 #endif // MEDIA_FILTERS_SKCANVAS_VIDEO_RENDERER_H_ 80 #endif // MEDIA_FILTERS_SKCANVAS_VIDEO_RENDERER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698