| 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_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.h" |  | 
|  14 #include "third_party/skia/include/core/SkBitmap.h" |  13 #include "third_party/skia/include/core/SkBitmap.h" | 
|  15 #include "third_party/skia/include/core/SkXfermode.h" |  14 #include "third_party/skia/include/core/SkXfermode.h" | 
|  16 #include "ui/gfx/geometry/rect.h" |  15 #include "ui/gfx/geometry/rect.h" | 
|  17  |  16  | 
|  18 class SkCanvas; |  17 class SkCanvas; | 
|  19  |  18  | 
|  20 namespace media { |  19 namespace media { | 
|  21  |  20  | 
|  22 class VideoFrame; |  21 class VideoFrame; | 
|  23 class VideoImageGenerator; |  22 class VideoImageGenerator; | 
|  24  |  23  | 
|  25 // Handles rendering of VideoFrames to SkCanvases, doing any necessary YUV |  24 // Handles rendering of VideoFrames to SkCanvases, doing any necessary YUV | 
|  26 // conversion and caching of resulting RGB bitmaps. |  25 // conversion and caching of resulting RGB bitmaps. | 
|  27 class MEDIA_EXPORT SkCanvasVideoRenderer { |  26 class MEDIA_EXPORT SkCanvasVideoRenderer { | 
|  28  public: |  27  public: | 
|  29   SkCanvasVideoRenderer(); |  28   SkCanvasVideoRenderer(); | 
|  30   ~SkCanvasVideoRenderer(); |  29   ~SkCanvasVideoRenderer(); | 
|  31  |  30  | 
|  32   // 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 | 
|  33   // dimensions specified by |dest_rect|. |  32   // dimensions specified by |dest_rect|. | 
|  34   // If the format of |video_frame| is VideoFrame::NATIVE_TEXTURE and |canvas| |  | 
|  35   // is ganeshed, |context_3d| must be provided. |  | 
|  36   // |  33   // | 
|  37   // Black will be painted on |canvas| if |video_frame| is null. |  34   // Black will be painted on |canvas| if |video_frame| is null. | 
|  38   void Paint(const scoped_refptr<VideoFrame>& video_frame, |  35   void Paint(const scoped_refptr<VideoFrame>& video_frame, | 
|  39              SkCanvas* canvas, |  36              SkCanvas* canvas, | 
|  40              const gfx::RectF& dest_rect, |  37              const gfx::RectF& dest_rect, | 
|  41              uint8 alpha, |  38              uint8 alpha, | 
|  42              SkXfermode::Mode mode, |  39              SkXfermode::Mode mode, | 
|  43              VideoRotation video_rotation, |  40              VideoRotation video_rotation); | 
|  44              const Context3D& context_3d); |  | 
|  45  |  41  | 
|  46   // Copy |video_frame| on |canvas|. |  42   // Copy |video_frame| on |canvas|. | 
|  47   void Copy(const scoped_refptr<VideoFrame>&, SkCanvas* canvas); |  43   void Copy(const scoped_refptr<VideoFrame>&, SkCanvas* canvas); | 
|  48  |  44  | 
|  49   // Copy the contents of texture of |video_frame| to texture |texture|. |  | 
|  50   // |level|, |internal_format|, |type| specify target texture |texture|. |  | 
|  51   // The format of |video_frame| must be VideoFrame::NATIVE_TEXTURE. |  | 
|  52   static void CopyVideoFrameTextureToGLTexture(gpu::gles2::GLES2Interface* gl, |  | 
|  53                                                VideoFrame* video_frame, |  | 
|  54                                                unsigned int texture, |  | 
|  55                                                unsigned int level, |  | 
|  56                                                unsigned int internal_format, |  | 
|  57                                                unsigned int type, |  | 
|  58                                                bool premultiply_alpha, |  | 
|  59                                                bool flip_y); |  | 
|  60  |  | 
|  61  private: |  45  private: | 
|  62   void ResetLastFrame(); |  46   void ResetLastFrame(); | 
|  63   void ResetAcceleratedLastFrame(); |  47   void ResetAcceleratedLastFrame(); | 
|  64  |  48  | 
|  65   // An RGB bitmap and corresponding timestamp of the previously converted |  49   // An RGB bitmap and corresponding timestamp of the previously converted | 
|  66   // video frame data by software color space conversion. |  50   // video frame data by software color space conversion. | 
|  67   SkBitmap last_frame_; |  51   SkBitmap last_frame_; | 
|  68   base::TimeDelta last_frame_timestamp_; |  52   base::TimeDelta last_frame_timestamp_; | 
|  69   // If |last_frame_| is not used for a while, it's deleted to save memory. |  53   // If |last_frame_| is not used for a while, it's deleted to save memory. | 
|  70   base::DelayTimer<SkCanvasVideoRenderer> frame_deleting_timer_; |  54   base::DelayTimer<SkCanvasVideoRenderer> frame_deleting_timer_; | 
|  71  |  55  | 
|  72   // This is a hardware accelerated copy of the frame generated by |  56   // This is a hardware accelerated copy of the frame generated by | 
|  73   // |accelerated_generator_|. |  57   // |accelerated_generator_|. | 
|  74   // It's used when |canvas| parameter in Paint() is Ganesh canvas. |  58   // It's used when |canvas| parameter in Paint() is Ganesh canvas. | 
|  75   // Note: all GrContext in SkCanvas instances are same. |  59   // Note: all GrContext in SkCanvas instances are same. | 
|  76   SkBitmap accelerated_last_frame_; |  60   SkBitmap accelerated_last_frame_; | 
|  77   VideoImageGenerator* accelerated_generator_; |  61   VideoImageGenerator* accelerated_generator_; | 
|  78   base::TimeDelta accelerated_last_frame_timestamp_; |  62   base::TimeDelta accelerated_last_frame_timestamp_; | 
|  79   base::DelayTimer<SkCanvasVideoRenderer> accelerated_frame_deleting_timer_; |  63   base::DelayTimer<SkCanvasVideoRenderer> accelerated_frame_deleting_timer_; | 
|  80  |  64  | 
|  81   DISALLOW_COPY_AND_ASSIGN(SkCanvasVideoRenderer); |  65   DISALLOW_COPY_AND_ASSIGN(SkCanvasVideoRenderer); | 
|  82 }; |  66 }; | 
|  83  |  67  | 
|  84 }  // namespace media |  68 }  // namespace media | 
|  85  |  69  | 
|  86 #endif  // MEDIA_FILTERS_SKCANVAS_VIDEO_RENDERER_H_ |  70 #endif  // MEDIA_FILTERS_SKCANVAS_VIDEO_RENDERER_H_ | 
| OLD | NEW |