Remove INJECT_EVENTS permissions from test APKs.
[chromium-blink-merge.git] / media / blink / skcanvas_video_renderer.h
blob504495321b94aa0b3bdabf48b0fd059eaa5d7e1e
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_BLINK_SKCANVAS_VIDEO_RENDERER_H_
6 #define MEDIA_BLINK_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 "media/filters/context_3d.h"
14 #include "third_party/skia/include/core/SkBitmap.h"
15 #include "third_party/skia/include/core/SkImage.h"
16 #include "third_party/skia/include/core/SkXfermode.h"
17 #include "ui/gfx/geometry/rect.h"
19 class SkCanvas;
21 namespace media {
23 class VideoFrame;
24 class VideoImageGenerator;
26 // Handles rendering of VideoFrames to SkCanvases, doing any necessary YUV
27 // conversion and caching of resulting RGB bitmaps.
28 class MEDIA_EXPORT SkCanvasVideoRenderer {
29 public:
30 SkCanvasVideoRenderer();
31 ~SkCanvasVideoRenderer();
33 // Paints |video_frame| on |canvas|, scaling and rotating the result to fit
34 // dimensions specified by |dest_rect|.
35 // If the format of |video_frame| is VideoFrame::NATIVE_TEXTURE, |context_3d|
36 // must be provided.
38 // Black will be painted on |canvas| if |video_frame| is null.
39 void Paint(const scoped_refptr<VideoFrame>& video_frame,
40 SkCanvas* canvas,
41 const gfx::RectF& dest_rect,
42 uint8 alpha,
43 SkXfermode::Mode mode,
44 VideoRotation video_rotation,
45 const Context3D& context_3d);
47 // Copy |video_frame| on |canvas|.
48 // If the format of |video_frame| is VideoFrame::NATIVE_TEXTURE, |context_3d|
49 // must be provided.
50 void Copy(const scoped_refptr<VideoFrame>& video_frame,
51 SkCanvas* canvas,
52 const Context3D& context_3d);
54 // Convert the contents of |video_frame| to raw RGB pixels. |rgb_pixels|
55 // should point into a buffer large enough to hold as many 32 bit RGBA pixels
56 // as are in the visible_rect() area of the frame.
57 static void ConvertVideoFrameToRGBPixels(
58 const scoped_refptr<media::VideoFrame>& video_frame,
59 void* rgb_pixels,
60 size_t row_bytes);
62 // Copy the contents of texture of |video_frame| to texture |texture|.
63 // |level|, |internal_format|, |type| specify target texture |texture|.
64 // The format of |video_frame| must be VideoFrame::NATIVE_TEXTURE.
65 static void CopyVideoFrameSingleTextureToGLTexture(
66 gpu::gles2::GLES2Interface* gl,
67 VideoFrame* video_frame,
68 unsigned int texture,
69 unsigned int internal_format,
70 unsigned int type,
71 bool premultiply_alpha,
72 bool flip_y);
74 private:
75 void ResetLastFrame();
76 void ResetAcceleratedLastFrame();
78 // An RGB bitmap and corresponding timestamp of the previously converted
79 // video frame data by software color space conversion.
80 SkBitmap last_frame_;
81 base::TimeDelta last_frame_timestamp_;
82 // If |last_frame_| is not used for a while, it's deleted to save memory.
83 base::DelayTimer<SkCanvasVideoRenderer> frame_deleting_timer_;
85 // This is a hardware accelerated copy of the frame generated by
86 // |accelerated_generator_|.
87 // It's used when |canvas| parameter in Paint() is Ganesh canvas.
88 // Note: all GrContext in SkCanvas instances are same.
89 scoped_ptr<SkImage> accelerated_last_image_;
90 SkBitmap accelerated_last_frame_;
91 VideoImageGenerator* accelerated_generator_;
92 base::TimeDelta accelerated_last_frame_timestamp_;
93 base::DelayTimer<SkCanvasVideoRenderer> accelerated_frame_deleting_timer_;
95 DISALLOW_COPY_AND_ASSIGN(SkCanvasVideoRenderer);
98 } // namespace media
100 #endif // MEDIA_BLINK_SKCANVAS_VIDEO_RENDERER_H_