Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: cc/resources/video_resource_updater.cc

Issue 178133005: Audit/fix use of media::VideoFrame::coded_size() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: e6f9affb danakj@ comments. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 case media::VideoFrame::UNKNOWN: 80 case media::VideoFrame::UNKNOWN:
81 case media::VideoFrame::HISTOGRAM_MAX: 81 case media::VideoFrame::HISTOGRAM_MAX:
82 case media::VideoFrame::I420: 82 case media::VideoFrame::I420:
83 break; 83 break;
84 } 84 }
85 return false; 85 return false;
86 } 86 }
87 87
88 // For frames that we receive in software format, determine the dimensions of 88 // For frames that we receive in software format, determine the dimensions of
89 // each plane in the frame. 89 // each plane in the frame.
90 static gfx::Size SoftwarePlaneDimension( 90 static gfx::Size SoftwarePlaneDimensions(
91 media::VideoFrame::Format input_frame_format, 91 const scoped_refptr<media::VideoFrame>& input_frame,
92 const gfx::Size& coded_size,
93 ResourceFormat output_resource_format, 92 ResourceFormat output_resource_format,
94 int plane_index) { 93 size_t plane) {
danakj 2014/02/28 22:28:25 prefer keep this as |plane_index|
sheu 2014/03/01 01:56:57 Done.
95 if (output_resource_format == kYUVResourceFormat) { 94 if (output_resource_format == kYUVResourceFormat) {
96 if (plane_index == media::VideoFrame::kYPlane || 95 return media::VideoFrame::PlaneSize(
97 plane_index == media::VideoFrame::kAPlane) 96 input_frame->format(), plane, input_frame->coded_size());
98 return coded_size; 97 } else {
danakj 2014/02/28 22:28:25 no need for else {} since the if{returns}.
sheu 2014/03/01 01:56:57 Done.
99 98 DCHECK_EQ(output_resource_format, kRGBResourceFormat);
100 switch (input_frame_format) { 99 return input_frame->coded_size();
101 case media::VideoFrame::YV12:
102 case media::VideoFrame::YV12A:
103 case media::VideoFrame::YV12J:
104 return gfx::ToFlooredSize(gfx::ScaleSize(coded_size, 0.5f, 0.5f));
105 case media::VideoFrame::YV16:
106 return gfx::ToFlooredSize(gfx::ScaleSize(coded_size, 0.5f, 1.f));
107
108 case media::VideoFrame::UNKNOWN:
109 case media::VideoFrame::I420:
110 case media::VideoFrame::NATIVE_TEXTURE:
111 case media::VideoFrame::HISTOGRAM_MAX:
112 #if defined(VIDEO_HOLE)
113 case media::VideoFrame::HOLE:
114 #endif // defined(VIDEO_HOLE)
115 NOTREACHED();
116 }
117 } 100 }
118
119 DCHECK_EQ(output_resource_format, kRGBResourceFormat);
120 return coded_size;
121 } 101 }
122 102
123 VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes( 103 VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes(
124 const scoped_refptr<media::VideoFrame>& video_frame) { 104 const scoped_refptr<media::VideoFrame>& video_frame) {
125 media::VideoFrame::Format input_frame_format = video_frame->format(); 105 media::VideoFrame::Format input_frame_format = video_frame->format();
126 106
127 #if defined(VIDEO_HOLE) 107 #if defined(VIDEO_HOLE)
128 if (input_frame_format == media::VideoFrame::HOLE) { 108 if (input_frame_format == media::VideoFrame::HOLE) {
129 VideoFrameExternalResources external_resources; 109 VideoFrameExternalResources external_resources;
130 external_resources.type = VideoFrameExternalResources::HOLE; 110 external_resources.type = VideoFrameExternalResources::HOLE;
131 return external_resources; 111 return external_resources;
132 } 112 }
133 #endif // defined(VIDEO_HOLE) 113 #endif // defined(VIDEO_HOLE)
134 114
135 // Only YUV software video frames are supported. 115 // Only YUV software video frames are supported.
136 DCHECK(input_frame_format == media::VideoFrame::YV12 || 116 DCHECK(input_frame_format == media::VideoFrame::YV12 ||
137 input_frame_format == media::VideoFrame::YV12A || 117 input_frame_format == media::VideoFrame::YV12A ||
138 input_frame_format == media::VideoFrame::YV12J || 118 input_frame_format == media::VideoFrame::YV12J ||
139 input_frame_format == media::VideoFrame::YV16); 119 input_frame_format == media::VideoFrame::YV16);
140 if (input_frame_format != media::VideoFrame::YV12 && 120 if (input_frame_format != media::VideoFrame::YV12 &&
141 input_frame_format != media::VideoFrame::YV12A && 121 input_frame_format != media::VideoFrame::YV12A &&
142 input_frame_format != media::VideoFrame::YV12J && 122 input_frame_format != media::VideoFrame::YV12J &&
143 input_frame_format != media::VideoFrame::YV16) 123 input_frame_format != media::VideoFrame::YV16)
144 return VideoFrameExternalResources(); 124 return VideoFrameExternalResources();
145 125
146 bool software_compositor = context_provider_ == NULL; 126 bool software_compositor = context_provider_ == NULL;
147 127
148 ResourceFormat output_resource_format = kYUVResourceFormat; 128 ResourceFormat output_resource_format = kYUVResourceFormat;
149 size_t output_plane_count = 129 size_t output_plane_count = media::VideoFrame::NumPlanes(input_frame_format);
150 (input_frame_format == media::VideoFrame::YV12A) ? 4 : 3;
151 130
152 // TODO(skaslev): If we're in software compositing mode, we do the YUV -> RGB 131 // TODO(skaslev): If we're in software compositing mode, we do the YUV -> RGB
153 // conversion here. That involves an extra copy of each frame to a bitmap. 132 // conversion here. That involves an extra copy of each frame to a bitmap.
154 // Obviously, this is suboptimal and should be addressed once ubercompositor 133 // Obviously, this is suboptimal and should be addressed once ubercompositor
155 // starts shaping up. 134 // starts shaping up.
156 if (software_compositor) { 135 if (software_compositor) {
157 output_resource_format = kRGBResourceFormat; 136 output_resource_format = kRGBResourceFormat;
158 output_plane_count = 1; 137 output_plane_count = 1;
159 } 138 }
160 139
161 int max_resource_size = resource_provider_->max_texture_size(); 140 int max_resource_size = resource_provider_->max_texture_size();
162 gfx::Size coded_frame_size = video_frame->coded_size();
163
164 std::vector<PlaneResource> plane_resources; 141 std::vector<PlaneResource> plane_resources;
165 bool allocation_success = true; 142 bool allocation_success = true;
166 143
167 for (size_t i = 0; i < output_plane_count; ++i) { 144 for (size_t i = 0; i < output_plane_count; ++i) {
168 gfx::Size output_plane_resource_size = 145 gfx::Size output_plane_resource_size =
169 SoftwarePlaneDimension(input_frame_format, 146 SoftwarePlaneDimensions(video_frame, output_resource_format, i);
170 coded_frame_size,
171 output_resource_format,
172 i);
173 if (output_plane_resource_size.IsEmpty() || 147 if (output_plane_resource_size.IsEmpty() ||
174 output_plane_resource_size.width() > max_resource_size || 148 output_plane_resource_size.width() > max_resource_size ||
175 output_plane_resource_size.height() > max_resource_size) { 149 output_plane_resource_size.height() > max_resource_size) {
176 allocation_success = false; 150 allocation_success = false;
177 break; 151 break;
178 } 152 }
179 153
180 ResourceProvider::ResourceId resource_id = 0; 154 ResourceProvider::ResourceId resource_id = 0;
181 gpu::Mailbox mailbox; 155 gpu::Mailbox mailbox;
182 156
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 } 359 }
386 360
387 PlaneResource recycled_resource(data.resource_id, 361 PlaneResource recycled_resource(data.resource_id,
388 data.resource_size, 362 data.resource_size,
389 data.resource_format, 363 data.resource_format,
390 data.mailbox); 364 data.mailbox);
391 updater->recycled_resources_.push_back(recycled_resource); 365 updater->recycled_resources_.push_back(recycled_resource);
392 } 366 }
393 367
394 } // namespace cc 368 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698