Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| 16 #include "third_party/skia/include/core/SkImage.h" | |
| 15 #include "third_party/skia/include/core/SkXfermode.h" | 17 #include "third_party/skia/include/core/SkXfermode.h" |
| 16 #include "ui/gfx/geometry/rect.h" | 18 #include "ui/gfx/geometry/rect.h" |
| 17 | 19 |
| 18 class SkCanvas; | 20 class SkCanvas; |
| 21 class SkImage; | |
| 19 | 22 |
| 20 namespace media { | 23 namespace media { |
| 21 | |
| 22 class VideoFrame; | |
| 23 class VideoImageGenerator; | 24 class VideoImageGenerator; |
| 24 | 25 |
| 25 // Handles rendering of VideoFrames to SkCanvases, doing any necessary YUV | 26 // Handles rendering of VideoFrames to SkCanvases. |
| 26 // conversion and caching of resulting RGB bitmaps. | |
| 27 class MEDIA_EXPORT SkCanvasVideoRenderer { | 27 class MEDIA_EXPORT SkCanvasVideoRenderer { |
| 28 public: | 28 public: |
| 29 SkCanvasVideoRenderer(); | 29 SkCanvasVideoRenderer(); |
| 30 ~SkCanvasVideoRenderer(); | 30 ~SkCanvasVideoRenderer(); |
| 31 | 31 |
| 32 // 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 |
| 33 // dimensions specified by |dest_rect|. | 33 // dimensions specified by |dest_rect|. |
| 34 // If the format of |video_frame| is VideoFrame::NATIVE_TEXTURE, |context_3d| | 34 // If the format of |video_frame| is VideoFrame::NATIVE_TEXTURE, |context_3d| |
| 35 // must be provided. | 35 // must be provided. |
| 36 // | 36 // |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 63 // The format of |video_frame| must be VideoFrame::NATIVE_TEXTURE. | 63 // The format of |video_frame| must be VideoFrame::NATIVE_TEXTURE. |
| 64 static void CopyVideoFrameTextureToGLTexture(gpu::gles2::GLES2Interface* gl, | 64 static void CopyVideoFrameTextureToGLTexture(gpu::gles2::GLES2Interface* gl, |
| 65 VideoFrame* video_frame, | 65 VideoFrame* video_frame, |
| 66 unsigned int texture, | 66 unsigned int texture, |
| 67 unsigned int internal_format, | 67 unsigned int internal_format, |
| 68 unsigned int type, | 68 unsigned int type, |
| 69 bool premultiply_alpha, | 69 bool premultiply_alpha, |
| 70 bool flip_y); | 70 bool flip_y); |
| 71 | 71 |
| 72 private: | 72 private: |
| 73 void ResetLastFrame(); | 73 void ResetCache(); |
| 74 void ResetAcceleratedLastFrame(); | |
| 75 | 74 |
| 76 // An RGB bitmap and corresponding timestamp of the previously converted | 75 // Last image created from a generator. |
| 77 // video frame data by software color space conversion. | 76 skia::RefPtr<SkImage> last_image_; |
| 78 SkBitmap last_frame_; | 77 // Timestamp of the videoframe used to generate |last_image_|. |
| 79 base::TimeDelta last_frame_timestamp_; | 78 base::TimeDelta last_timestamp_ = media::kNoTimestamp(); |
|
dshwang
2015/06/08 12:21:44
is it allowed to initialize here in chromium codin
Daniele Castagna
2015/06/09 23:21:11
It seems so, look for "Non-Static Class Member Ini
dshwang
2015/06/10 07:17:39
Acknowledged.
| |
| 80 // If |last_frame_| is not used for a while, it's deleted to save memory. | 79 // If the last videoframe was software |video_generator_| is the generator |
| 81 base::DelayTimer<SkCanvasVideoRenderer> frame_deleting_timer_; | 80 // used to generate last_image_. SkImage takes ownership of video_generator_, |
| 81 // here we're assuming that video_generator_ is valid as long as the | |
| 82 // associated SkImage is not deleted. | |
| 83 // https://code.google.com/p/skia/issues/detail?id=3870 | |
| 84 VideoImageGenerator* video_generator_ = nullptr; | |
| 82 | 85 |
| 83 // This is a hardware accelerated copy of the frame generated by | 86 // texture object backing |last_image_| if the last videoframe had a native |
| 84 // |accelerated_generator_|. | 87 // texture. |
| 85 // It's used when |canvas| parameter in Paint() is Ganesh canvas. | 88 unsigned last_texture_id_ = 0; |
| 86 // Note: all GrContext in SkCanvas instances are same. | 89 // GL interface used to create last_texture_id_, if set. |
| 87 SkBitmap accelerated_last_frame_; | 90 gpu::gles2::GLES2Interface* last_gl_ = nullptr; |
|
dshwang
2015/06/08 12:21:44
it's very unsafe. it can easily cause sef fault. I
Daniele Castagna
2015/06/09 23:21:11
Agreed.
The idea in this CL is to use SkImage, so
dshwang
2015/06/10 07:17:39
GrTexture is used in here and there. I think it's
| |
| 88 VideoImageGenerator* accelerated_generator_; | |
| 89 base::TimeDelta accelerated_last_frame_timestamp_; | |
| 90 base::DelayTimer<SkCanvasVideoRenderer> accelerated_frame_deleting_timer_; | |
| 91 | 91 |
| 92 DISALLOW_COPY_AND_ASSIGN(SkCanvasVideoRenderer); | 92 DISALLOW_COPY_AND_ASSIGN(SkCanvasVideoRenderer); |
| 93 }; | 93 }; |
| 94 | 94 |
| 95 } // namespace media | 95 } // namespace media |
| 96 | 96 |
| 97 #endif // MEDIA_BLINK_SKCANVAS_VIDEO_RENDERER_H_ | 97 #endif // MEDIA_BLINK_SKCANVAS_VIDEO_RENDERER_H_ |
| OLD | NEW |