OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "cc/resources/video_resource_updater.h" | 5 #include "cc/resources/video_resource_updater.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "cc/output/gl_renderer.h" | 8 #include "cc/output/gl_renderer.h" |
9 #include "cc/resources/resource_provider.h" | 9 #include "cc/resources/resource_provider.h" |
10 #include "gpu/GLES2/gl2extchromium.h" | 10 #include "gpu/GLES2/gl2extchromium.h" |
11 #include "media/base/video_frame.h" | 11 #include "media/base/video_frame.h" |
12 #include "media/filters/skcanvas_video_renderer.h" | 12 #include "media/filters/skcanvas_video_renderer.h" |
13 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" | 13 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" |
14 #include "third_party/khronos/GLES2/gl2.h" | 14 #include "third_party/khronos/GLES2/gl2.h" |
15 #include "third_party/khronos/GLES2/gl2ext.h" | 15 #include "third_party/khronos/GLES2/gl2ext.h" |
16 #include "ui/gfx/size_conversions.h" | 16 #include "ui/gfx/size_conversions.h" |
17 | 17 |
18 const unsigned kYUVResourceFormat = GL_LUMINANCE; | 18 namespace cc { |
19 const unsigned kRGBResourceFormat = GL_RGBA; | |
20 | 19 |
21 namespace cc { | 20 const ResourceProvider::Format kYUVResourceFormat = |
| 21 ResourceProvider::LUMINANCE_8; |
| 22 const ResourceProvider::Format kRGBResourceFormat = |
| 23 ResourceProvider::RGBA_8888; |
22 | 24 |
23 VideoFrameExternalResources::VideoFrameExternalResources() : type(NONE) {} | 25 VideoFrameExternalResources::VideoFrameExternalResources() : type(NONE) {} |
24 | 26 |
25 VideoFrameExternalResources::~VideoFrameExternalResources() {} | 27 VideoFrameExternalResources::~VideoFrameExternalResources() {} |
26 | 28 |
27 VideoResourceUpdater::VideoResourceUpdater(ContextProvider* context_provider, | 29 VideoResourceUpdater::VideoResourceUpdater(ContextProvider* context_provider, |
28 ResourceProvider* resource_provider) | 30 ResourceProvider* resource_provider) |
29 : context_provider_(context_provider), | 31 : context_provider_(context_provider), |
30 resource_provider_(resource_provider) { | 32 resource_provider_(resource_provider) { |
31 } | 33 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 break; | 85 break; |
84 } | 86 } |
85 return false; | 87 return false; |
86 } | 88 } |
87 | 89 |
88 // For frames that we receive in software format, determine the dimensions of | 90 // For frames that we receive in software format, determine the dimensions of |
89 // each plane in the frame. | 91 // each plane in the frame. |
90 static gfx::Size SoftwarePlaneDimension( | 92 static gfx::Size SoftwarePlaneDimension( |
91 media::VideoFrame::Format input_frame_format, | 93 media::VideoFrame::Format input_frame_format, |
92 gfx::Size coded_size, | 94 gfx::Size coded_size, |
93 GLenum output_resource_format, | 95 ResourceProvider::Format output_resource_format, |
94 int plane_index) { | 96 int plane_index) { |
95 if (output_resource_format == kYUVResourceFormat) { | 97 if (output_resource_format == kYUVResourceFormat) { |
96 if (plane_index == media::VideoFrame::kYPlane || | 98 if (plane_index == media::VideoFrame::kYPlane || |
97 plane_index == media::VideoFrame::kAPlane) | 99 plane_index == media::VideoFrame::kAPlane) |
98 return coded_size; | 100 return coded_size; |
99 | 101 |
100 switch (input_frame_format) { | 102 switch (input_frame_format) { |
101 case media::VideoFrame::YV12: | 103 case media::VideoFrame::YV12: |
102 case media::VideoFrame::YV12A: | 104 case media::VideoFrame::YV12A: |
103 return gfx::ToFlooredSize(gfx::ScaleSize(coded_size, 0.5f, 0.5f)); | 105 return gfx::ToFlooredSize(gfx::ScaleSize(coded_size, 0.5f, 0.5f)); |
104 case media::VideoFrame::YV16: | 106 case media::VideoFrame::YV16: |
105 return gfx::ToFlooredSize(gfx::ScaleSize(coded_size, 0.5f, 1.f)); | 107 return gfx::ToFlooredSize(gfx::ScaleSize(coded_size, 0.5f, 1.f)); |
106 | 108 |
107 case media::VideoFrame::INVALID: | 109 case media::VideoFrame::INVALID: |
108 case media::VideoFrame::RGB32: | 110 case media::VideoFrame::RGB32: |
109 case media::VideoFrame::EMPTY: | 111 case media::VideoFrame::EMPTY: |
110 case media::VideoFrame::I420: | 112 case media::VideoFrame::I420: |
111 case media::VideoFrame::NATIVE_TEXTURE: | 113 case media::VideoFrame::NATIVE_TEXTURE: |
112 #if defined(GOOGLE_TV) | 114 #if defined(GOOGLE_TV) |
113 case media::VideoFrame::HOLE: | 115 case media::VideoFrame::HOLE: |
114 #endif | 116 #endif |
115 NOTREACHED(); | 117 NOTREACHED(); |
116 } | 118 } |
117 } | 119 } |
118 | 120 |
119 DCHECK_EQ(output_resource_format, static_cast<unsigned>(kRGBResourceFormat)); | 121 DCHECK_EQ(output_resource_format, kRGBResourceFormat); |
120 return coded_size; | 122 return coded_size; |
121 } | 123 } |
122 | 124 |
123 VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes( | 125 VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes( |
124 const scoped_refptr<media::VideoFrame>& video_frame) { | 126 const scoped_refptr<media::VideoFrame>& video_frame) { |
125 media::VideoFrame::Format input_frame_format = video_frame->format(); | 127 media::VideoFrame::Format input_frame_format = video_frame->format(); |
126 | 128 |
127 #if defined(GOOGLE_TV) | 129 #if defined(GOOGLE_TV) |
128 if (input_frame_format == media::VideoFrame::HOLE) { | 130 if (input_frame_format == media::VideoFrame::HOLE) { |
129 VideoFrameExternalResources external_resources; | 131 VideoFrameExternalResources external_resources; |
130 external_resources.type = VideoFrameExternalResources::HOLE; | 132 external_resources.type = VideoFrameExternalResources::HOLE; |
131 return external_resources; | 133 return external_resources; |
132 } | 134 } |
133 #endif | 135 #endif |
134 | 136 |
135 // Only YUV software video frames are supported. | 137 // Only YUV software video frames are supported. |
136 DCHECK(input_frame_format == media::VideoFrame::YV12 || | 138 DCHECK(input_frame_format == media::VideoFrame::YV12 || |
137 input_frame_format == media::VideoFrame::YV12A || | 139 input_frame_format == media::VideoFrame::YV12A || |
138 input_frame_format == media::VideoFrame::YV16); | 140 input_frame_format == media::VideoFrame::YV16); |
139 if (input_frame_format != media::VideoFrame::YV12 && | 141 if (input_frame_format != media::VideoFrame::YV12 && |
140 input_frame_format != media::VideoFrame::YV12A && | 142 input_frame_format != media::VideoFrame::YV12A && |
141 input_frame_format != media::VideoFrame::YV16) | 143 input_frame_format != media::VideoFrame::YV16) |
142 return VideoFrameExternalResources(); | 144 return VideoFrameExternalResources(); |
143 | 145 |
144 bool software_compositor = context_provider_ == NULL; | 146 bool software_compositor = context_provider_ == NULL; |
145 | 147 |
146 GLenum output_resource_format = kYUVResourceFormat; | 148 ResourceProvider::Format output_resource_format = kYUVResourceFormat; |
147 size_t output_plane_count = | 149 size_t output_plane_count = |
148 (input_frame_format == media::VideoFrame::YV12A) ? 4 : 3; | 150 (input_frame_format == media::VideoFrame::YV12A) ? 4 : 3; |
149 | 151 |
150 // TODO(skaslev): If we're in software compositing mode, we do the YUV -> RGB | 152 // TODO(skaslev): If we're in software compositing mode, we do the YUV -> RGB |
151 // conversion here. That involves an extra copy of each frame to a bitmap. | 153 // conversion here. That involves an extra copy of each frame to a bitmap. |
152 // Obviously, this is suboptimal and should be addressed once ubercompositor | 154 // Obviously, this is suboptimal and should be addressed once ubercompositor |
153 // starts shaping up. | 155 // starts shaping up. |
154 if (software_compositor) { | 156 if (software_compositor) { |
155 output_resource_format = kRGBResourceFormat; | 157 output_resource_format = kRGBResourceFormat; |
156 output_plane_count = 1; | 158 output_plane_count = 1; |
(...skipping 30 matching lines...) Expand all Loading... |
187 recycled_resources_.erase(recycled_resources_.begin() + i); | 189 recycled_resources_.erase(recycled_resources_.begin() + i); |
188 break; | 190 break; |
189 } | 191 } |
190 } | 192 } |
191 | 193 |
192 if (resource_id == 0) { | 194 if (resource_id == 0) { |
193 // TODO(danakj): Abstract out hw/sw resource create/delete from | 195 // TODO(danakj): Abstract out hw/sw resource create/delete from |
194 // ResourceProvider and stop using ResourceProvider in this class. | 196 // ResourceProvider and stop using ResourceProvider in this class. |
195 resource_id = | 197 resource_id = |
196 resource_provider_->CreateResource(output_plane_resource_size, | 198 resource_provider_->CreateResource(output_plane_resource_size, |
197 output_resource_format, | |
198 GL_CLAMP_TO_EDGE, | 199 GL_CLAMP_TO_EDGE, |
199 ResourceProvider::TextureUsageAny); | 200 ResourceProvider::TextureUsageAny, |
| 201 output_resource_format); |
200 | 202 |
201 DCHECK(mailbox.IsZero()); | 203 DCHECK(mailbox.IsZero()); |
202 | 204 |
203 if (!software_compositor) { | 205 if (!software_compositor) { |
204 DCHECK(context_provider_); | 206 DCHECK(context_provider_); |
205 | 207 |
206 WebKit::WebGraphicsContext3D* context = | 208 WebKit::WebGraphicsContext3D* context = |
207 context_provider_->Context3d(); | 209 context_provider_->Context3d(); |
208 | 210 |
209 GLC(context, context->genMailboxCHROMIUM(mailbox.name)); | 211 GLC(context, context->genMailboxCHROMIUM(mailbox.name)); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 } | 402 } |
401 | 403 |
402 PlaneResource recycled_resource(data.resource_id, | 404 PlaneResource recycled_resource(data.resource_id, |
403 data.resource_size, | 405 data.resource_size, |
404 data.resource_format, | 406 data.resource_format, |
405 data.mailbox); | 407 data.mailbox); |
406 updater->recycled_resources_.push_back(recycled_resource); | 408 updater->recycled_resources_.push_back(recycled_resource); |
407 } | 409 } |
408 | 410 |
409 } // namespace cc | 411 } // namespace cc |
OLD | NEW |