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_RENDERERS_SKCANVAS_VIDEO_RENDERER_H_ | 5 #ifndef MEDIA_RENDERERS_SKCANVAS_VIDEO_RENDERER_H_ |
6 #define MEDIA_RENDERERS_SKCANVAS_VIDEO_RENDERER_H_ | 6 #define MEDIA_RENDERERS_SKCANVAS_VIDEO_RENDERER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/threading/thread_checker.h" | 13 #include "base/threading/thread_checker.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "base/timer/timer.h" | 15 #include "base/timer/timer.h" |
16 #include "media/base/media_export.h" | 16 #include "media/base/media_export.h" |
17 #include "media/base/timestamp_constants.h" | 17 #include "media/base/timestamp_constants.h" |
18 #include "media/base/video_frame.h" | 18 #include "media/base/video_frame.h" |
19 #include "media/base/video_rotation.h" | 19 #include "media/base/video_rotation.h" |
20 #include "media/filters/context_3d.h" | 20 #include "media/filters/context_3d.h" |
21 #include "third_party/skia/include/core/SkImage.h" | 21 #include "third_party/skia/include/core/SkImage.h" |
22 #include "third_party/skia/include/core/SkRefCnt.h" | 22 #include "third_party/skia/include/core/SkRefCnt.h" |
23 #include "third_party/skia/include/core/SkXfermode.h" | 23 #include "third_party/skia/include/core/SkXfermode.h" |
24 | 24 |
25 class SkCanvas; | 25 class SkCanvas; |
26 class SkImage; | |
27 | 26 |
28 namespace gfx { | 27 namespace gfx { |
29 class RectF; | 28 class RectF; |
30 } | 29 } |
31 | 30 |
32 namespace media { | 31 namespace media { |
33 class VideoImageGenerator; | 32 class VideoImageGenerator; |
34 | 33 |
35 // Handles rendering of VideoFrames to SkCanvases. | 34 // Handles rendering of VideoFrames to SkCanvases. |
36 class MEDIA_EXPORT SkCanvasVideoRenderer { | 35 class MEDIA_EXPORT SkCanvasVideoRenderer { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 bool CopyVideoFrameTexturesToGLTexture( | 86 bool CopyVideoFrameTexturesToGLTexture( |
88 const Context3D& context_3d, | 87 const Context3D& context_3d, |
89 gpu::gles2::GLES2Interface* destination_gl, | 88 gpu::gles2::GLES2Interface* destination_gl, |
90 const scoped_refptr<VideoFrame>& video_frame, | 89 const scoped_refptr<VideoFrame>& video_frame, |
91 unsigned int texture, | 90 unsigned int texture, |
92 unsigned int internal_format, | 91 unsigned int internal_format, |
93 unsigned int type, | 92 unsigned int type, |
94 bool premultiply_alpha, | 93 bool premultiply_alpha, |
95 bool flip_y); | 94 bool flip_y); |
96 | 95 |
| 96 // Method handles reinterpreting two components RG8 as 16 bit value for Y16 |
| 97 // format and optimizing upload-to-texture for some video frame and texture |
| 98 // formats. If needed, there is a conversion followed by a tex(Sub)Image2D or |
| 99 // tex(Sub)Image3D call. |
| 100 // |format|, |internal_format|, |type| specify target texture |texture|. |
| 101 // |xoffset|, |yoffset|, |zoffset| are used when functionID defines sub image |
| 102 // calls. |
| 103 // Returns false if there is no implementation for given parameters or if the |
| 104 // call fails. |
| 105 static bool TexImageImpl(const char* functionID, |
| 106 unsigned target, |
| 107 gpu::gles2::GLES2Interface* gl, |
| 108 VideoFrame* video_frame, |
| 109 int level, |
| 110 int internalformat, |
| 111 unsigned format, |
| 112 unsigned type, |
| 113 int xoffset, |
| 114 int yoffset, |
| 115 int zoffset, |
| 116 bool flipY, |
| 117 bool premultiplyAlpha); |
| 118 |
97 // In general, We hold the most recently painted frame to increase the | 119 // In general, We hold the most recently painted frame to increase the |
98 // performance for the case that the same frame needs to be painted | 120 // performance for the case that the same frame needs to be painted |
99 // repeatedly. Call this function if you are sure the most recent frame will | 121 // repeatedly. Call this function if you are sure the most recent frame will |
100 // never be painted again, so we can release the resource. | 122 // never be painted again, so we can release the resource. |
101 void ResetCache(); | 123 void ResetCache(); |
102 | 124 |
103 private: | 125 private: |
104 // Update the cache holding the most-recently-painted frame. Returns false | 126 // Update the cache holding the most-recently-painted frame. Returns false |
105 // if the image couldn't be updated. | 127 // if the image couldn't be updated. |
106 bool UpdateLastImage(const scoped_refptr<VideoFrame>& video_frame, | 128 bool UpdateLastImage(const scoped_refptr<VideoFrame>& video_frame, |
107 const Context3D& context_3d); | 129 const Context3D& context_3d); |
108 | 130 |
| 131 // Reinterpret the content of RG8 texture as R16 (normalized value) and then |
| 132 // copy to single red component (both float and integer formats are supported) |
| 133 // texture. |
| 134 // Reinterpretting texture happens on canvas gl (context_3d) to enable caching |
| 135 // resources for following calls. Target |texture| should live on |target_gl| |
| 136 // after the call. |
| 137 void CopyRG8ToRedTextureData(const Context3D& context_3d, |
| 138 gpu::gles2::GLES2Interface* target_gl, |
| 139 VideoFrame* video_frame, |
| 140 unsigned texture, |
| 141 unsigned internal_format, |
| 142 unsigned type, |
| 143 bool flip_y); |
| 144 |
| 145 // Helper method used by CopyRG8ToRedTextureData. Target used for both |
| 146 // |source_texture| and |target_texture| is GL_TEXTURE_2D. |
| 147 void DoCopyRG8ToRedTextureData(gpu::gles2::GLES2Interface* local_gl, |
| 148 unsigned source_texture, |
| 149 unsigned target_texture, |
| 150 unsigned internal_format, |
| 151 unsigned type, |
| 152 unsigned width, |
| 153 unsigned height, |
| 154 bool flip_y); |
| 155 |
109 // Last image used to draw to the canvas. | 156 // Last image used to draw to the canvas. |
110 sk_sp<SkImage> last_image_; | 157 sk_sp<SkImage> last_image_; |
111 // Timestamp of the videoframe used to generate |last_image_|. | 158 // Timestamp of the videoframe used to generate |last_image_|. |
112 base::TimeDelta last_timestamp_ = media::kNoTimestamp; | 159 base::TimeDelta last_timestamp_ = media::kNoTimestamp; |
113 // If |last_image_| is not used for a while, it's deleted to save memory. | 160 // If |last_image_| is not used for a while, it's deleted to save memory. |
114 base::DelayTimer last_image_deleting_timer_; | 161 base::DelayTimer last_image_deleting_timer_; |
115 | 162 |
116 // Used for DCHECKs to ensure method calls executed in the correct thread. | 163 // Used for DCHECKs to ensure method calls executed in the correct thread. |
117 base::ThreadChecker thread_checker_; | 164 base::ThreadChecker thread_checker_; |
| 165 // Used for GPU conversion of RG8 to R32F textures. |
| 166 unsigned rg8_to_red_program_; |
118 | 167 |
119 DISALLOW_COPY_AND_ASSIGN(SkCanvasVideoRenderer); | 168 DISALLOW_COPY_AND_ASSIGN(SkCanvasVideoRenderer); |
120 }; | 169 }; |
121 | 170 |
122 } // namespace media | 171 } // namespace media |
123 | 172 |
124 #endif // MEDIA_RENDERERS_SKCANVAS_VIDEO_RENDERER_H_ | 173 #endif // MEDIA_RENDERERS_SKCANVAS_VIDEO_RENDERER_H_ |
OLD | NEW |