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

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

Issue 1144323003: media: Refactor SkCanvasVideoRenderer to use SkImages and not SkBitmaps. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update syncpoint a the end of Paint. Created 5 years, 4 months 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_BLINK_SKCANVAS_VIDEO_RENDERER_H_ 5 #ifndef MEDIA_BLINK_SKCANVAS_VIDEO_RENDERER_H_
6 #define MEDIA_BLINK_SKCANVAS_VIDEO_RENDERER_H_ 6 #define MEDIA_BLINK_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_frame.h"
12 #include "media/base/video_rotation.h" 13 #include "media/base/video_rotation.h"
13 #include "media/filters/context_3d.h" 14 #include "media/filters/context_3d.h"
14 #include "third_party/skia/include/core/SkBitmap.h" 15 #include "skia/ext/refptr.h"
15 #include "third_party/skia/include/core/SkImage.h" 16 #include "third_party/skia/include/core/SkImage.h"
16 #include "third_party/skia/include/core/SkXfermode.h" 17 #include "third_party/skia/include/core/SkXfermode.h"
17 #include "ui/gfx/geometry/rect.h" 18 #include "ui/gfx/geometry/rect.h"
18 19
19 class SkCanvas; 20 class SkCanvas;
21 class SkImage;
20 22
21 namespace media { 23 namespace media {
22
23 class VideoFrame;
24 class VideoImageGenerator; 24 class VideoImageGenerator;
25 25
26 // Handles rendering of VideoFrames to SkCanvases, doing any necessary YUV 26 // Handles rendering of VideoFrames to SkCanvases.
27 // conversion and caching of resulting RGB bitmaps.
28 class MEDIA_EXPORT SkCanvasVideoRenderer { 27 class MEDIA_EXPORT SkCanvasVideoRenderer {
29 public: 28 public:
30 SkCanvasVideoRenderer(); 29 SkCanvasVideoRenderer();
31 ~SkCanvasVideoRenderer(); 30 ~SkCanvasVideoRenderer();
32 31
33 // Paints |video_frame| on |canvas|, scaling and rotating the result to fit 32 // Paints |video_frame| on |canvas|, scaling and rotating the result to fit
34 // dimensions specified by |dest_rect|. 33 // dimensions specified by |dest_rect|.
35 // If the format of |video_frame| is PIXEL_FORMAT_NATIVE_TEXTURE, |context_3d| 34 // If the format of |video_frame| is PIXEL_FORMAT_NATIVE_TEXTURE, |context_3d|
36 // must be provided. 35 // must be provided.
37 // 36 //
(...skipping 27 matching lines...) Expand all
65 static void CopyVideoFrameSingleTextureToGLTexture( 64 static void CopyVideoFrameSingleTextureToGLTexture(
66 gpu::gles2::GLES2Interface* gl, 65 gpu::gles2::GLES2Interface* gl,
67 VideoFrame* video_frame, 66 VideoFrame* video_frame,
68 unsigned int texture, 67 unsigned int texture,
69 unsigned int internal_format, 68 unsigned int internal_format,
70 unsigned int type, 69 unsigned int type,
71 bool premultiply_alpha, 70 bool premultiply_alpha,
72 bool flip_y); 71 bool flip_y);
73 72
74 private: 73 private:
75 void ResetLastFrame(); 74 void ResetCache();
76 void ResetAcceleratedLastFrame();
77 75
78 // An RGB bitmap and corresponding timestamp of the previously converted 76 // Last image used to draw to the canvas.
79 // video frame data by software color space conversion. 77 skia::RefPtr<SkImage> last_image_;
80 SkBitmap last_frame_; 78 // Timestamp of the videoframe used to generate |last_image_|.
81 base::TimeDelta last_frame_timestamp_; 79 base::TimeDelta last_timestamp_ = media::kNoTimestamp();
82 // If |last_frame_| is not used for a while, it's deleted to save memory. 80 // If the last videoframe was software |video_generator_| is the generator
83 base::DelayTimer<SkCanvasVideoRenderer> frame_deleting_timer_; 81 // used to generate last_image_. SkImage takes ownership of video_generator_,
84 82 // here we're assuming that video_generator_ is valid as long as the
85 // This is a hardware accelerated copy of the frame generated by 83 // associated SkImage is not deleted.
86 // |accelerated_generator_|. 84 // https://code.google.com/p/skia/issues/detail?id=3870
87 // It's used when |canvas| parameter in Paint() is Ganesh canvas. 85 VideoImageGenerator* video_generator_ = nullptr;
88 // Note: all GrContext in SkCanvas instances are same. 86 // If |last_image_| is not used for a while, it's deleted to save memory.
89 scoped_ptr<SkImage> accelerated_last_image_; 87 base::DelayTimer<SkCanvasVideoRenderer> last_image_deleting_timer_;
90 SkBitmap accelerated_last_frame_;
91 VideoImageGenerator* accelerated_generator_;
92 base::TimeDelta accelerated_last_frame_timestamp_;
93 base::DelayTimer<SkCanvasVideoRenderer> accelerated_frame_deleting_timer_;
94 88
95 DISALLOW_COPY_AND_ASSIGN(SkCanvasVideoRenderer); 89 DISALLOW_COPY_AND_ASSIGN(SkCanvasVideoRenderer);
96 }; 90 };
97 91
98 } // namespace media 92 } // namespace media
99 93
100 #endif // MEDIA_BLINK_SKCANVAS_VIDEO_RENDERER_H_ 94 #endif // MEDIA_BLINK_SKCANVAS_VIDEO_RENDERER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698