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

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

Issue 935383004: cc: Make VideoResourceUpdater use CopyToResource instead of SetPixels. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
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 <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
11 #include "cc/base/util.h"
11 #include "cc/output/gl_renderer.h" 12 #include "cc/output/gl_renderer.h"
12 #include "cc/resources/resource_provider.h" 13 #include "cc/resources/resource_provider.h"
13 #include "gpu/GLES2/gl2extchromium.h" 14 #include "gpu/GLES2/gl2extchromium.h"
14 #include "gpu/command_buffer/client/gles2_interface.h" 15 #include "gpu/command_buffer/client/gles2_interface.h"
15 #include "media/base/video_frame.h" 16 #include "media/base/video_frame.h"
16 #include "media/filters/skcanvas_video_renderer.h" 17 #include "media/filters/skcanvas_video_renderer.h"
17 #include "third_party/khronos/GLES2/gl2.h" 18 #include "third_party/khronos/GLES2/gl2.h"
18 #include "third_party/khronos/GLES2/gl2ext.h" 19 #include "third_party/khronos/GLES2/gl2ext.h"
19 #include "ui/gfx/geometry/size_conversions.h" 20 #include "ui/gfx/geometry/size_conversions.h"
20 21
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 plane_resource->timestamp = video_frame->timestamp(); 74 plane_resource->timestamp = video_frame->timestamp();
74 } 75 }
75 76
76 VideoFrameExternalResources::VideoFrameExternalResources() : type(NONE) {} 77 VideoFrameExternalResources::VideoFrameExternalResources() : type(NONE) {}
77 78
78 VideoFrameExternalResources::~VideoFrameExternalResources() {} 79 VideoFrameExternalResources::~VideoFrameExternalResources() {}
79 80
80 VideoResourceUpdater::VideoResourceUpdater(ContextProvider* context_provider, 81 VideoResourceUpdater::VideoResourceUpdater(ContextProvider* context_provider,
81 ResourceProvider* resource_provider) 82 ResourceProvider* resource_provider)
82 : context_provider_(context_provider), 83 : context_provider_(context_provider),
83 resource_provider_(resource_provider) { 84 resource_provider_(resource_provider),
85 upload_pixels_size_(0) {
84 } 86 }
85 87
86 VideoResourceUpdater::~VideoResourceUpdater() { 88 VideoResourceUpdater::~VideoResourceUpdater() {
87 for (const PlaneResource& plane_resource : all_resources_) 89 for (const PlaneResource& plane_resource : all_resources_)
88 resource_provider_->DeleteResource(plane_resource.resource_id); 90 resource_provider_->DeleteResource(plane_resource.resource_id);
89 } 91 }
90 92
91 VideoResourceUpdater::ResourceList::iterator 93 VideoResourceUpdater::ResourceList::iterator
92 VideoResourceUpdater::AllocateResource(const gfx::Size& plane_size, 94 VideoResourceUpdater::AllocateResource(const gfx::Size& plane_size,
93 ResourceFormat format, 95 ResourceFormat format,
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 } 312 }
311 313
312 for (size_t i = 0; i < plane_resources.size(); ++i) { 314 for (size_t i = 0; i < plane_resources.size(); ++i) {
313 PlaneResource& plane_resource = *plane_resources[i]; 315 PlaneResource& plane_resource = *plane_resources[i];
314 // Update each plane's resource id with its content. 316 // Update each plane's resource id with its content.
315 DCHECK_EQ(plane_resource.resource_format, 317 DCHECK_EQ(plane_resource.resource_format,
316 resource_provider_->yuv_resource_format()); 318 resource_provider_->yuv_resource_format());
317 319
318 if (!PlaneResourceMatchesUniqueID(plane_resource, video_frame.get(), i)) { 320 if (!PlaneResourceMatchesUniqueID(plane_resource, video_frame.get(), i)) {
319 // We need to transfer data from |video_frame| to the plane resource. 321 // We need to transfer data from |video_frame| to the plane resource.
320 const uint8_t* input_plane_pixels = video_frame->data(i); 322 // TODO(reveman): Can use of GpuMemoryBuffers here to improve performance.
enne (OOO) 2015/02/19 19:53:03 s/of//
321 323
322 gfx::Rect image_rect(0, 0, video_frame->stride(i), 324 // The |resource_size_pixels| is the size of the resource we want to
323 plane_resource.resource_size.height()); 325 // upload to.
324 gfx::Rect source_rect(plane_resource.resource_size); 326 gfx::Size resource_size_pixels = plane_resource.resource_size;
325 resource_provider_->SetPixels(plane_resource.resource_id, 327 // The |video_stride_pixels| is the width of the video frame we are
326 input_plane_pixels, image_rect, source_rect, 328 // uploading (including non-frame data to fill in the stride).
327 gfx::Vector2d()); 329 size_t video_stride_pixels = video_frame->stride(i);
330
331 size_t bytes_per_pixel = BitsPerPixel(plane_resource.resource_format) / 8;
332 // Use 4-byte row alignment (OpenGL default) for upload performance.
333 // Assuming that GL_UNPACK_ALIGNMENT has not changed from default.
334 size_t upload_image_stride =
335 RoundUp<size_t>(bytes_per_pixel * resource_size_pixels.width(), 4u);
336
337 const uint8_t* pixels;
338 if (upload_image_stride == video_stride_pixels * bytes_per_pixel) {
339 pixels = video_frame->data(i);
340 } else {
341 // Avoid malloc for each frame/plane if possible.
342 size_t needed_size =
343 upload_image_stride * resource_size_pixels.height();
344 if (upload_pixels_size_ < needed_size) {
345 upload_pixels_.reset(new uint8_t[needed_size]);
346 upload_pixels_size_ = needed_size;
347 }
348 for (int row = 0; row < resource_size_pixels.height(); ++row) {
349 uint8_t* dst = &upload_pixels_[upload_image_stride * row];
350 const uint8_t* src = video_frame->data(i) +
351 bytes_per_pixel * video_stride_pixels * row;
352 memcpy(dst, src, resource_size_pixels.width() * bytes_per_pixel);
353 }
354 pixels = upload_pixels_.get();
355 }
356
357 resource_provider_->CopyToResource(plane_resource.resource_id, pixels,
358 resource_size_pixels);
328 SetPlaneResourceUniqueId(video_frame.get(), i, &plane_resource); 359 SetPlaneResourceUniqueId(video_frame.get(), i, &plane_resource);
329 } 360 }
330 361
331 external_resources.mailboxes.push_back( 362 external_resources.mailboxes.push_back(
332 TextureMailbox(plane_resource.mailbox, GL_TEXTURE_2D, 0)); 363 TextureMailbox(plane_resource.mailbox, GL_TEXTURE_2D, 0));
333 external_resources.release_callbacks.push_back( 364 external_resources.release_callbacks.push_back(
334 base::Bind(&RecycleResource, AsWeakPtr(), plane_resource.resource_id)); 365 base::Bind(&RecycleResource, AsWeakPtr(), plane_resource.resource_id));
335 } 366 }
336 367
337 external_resources.type = VideoFrameExternalResources::YUV_RESOURCE; 368 external_resources.type = VideoFrameExternalResources::YUV_RESOURCE;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 resource_it->ref_count = 0; 458 resource_it->ref_count = 0;
428 updater->DeleteResource(resource_it); 459 updater->DeleteResource(resource_it);
429 return; 460 return;
430 } 461 }
431 462
432 --resource_it->ref_count; 463 --resource_it->ref_count;
433 DCHECK_GE(resource_it->ref_count, 0); 464 DCHECK_GE(resource_it->ref_count, 0);
434 } 465 }
435 466
436 } // namespace cc 467 } // namespace cc
OLDNEW
« cc/resources/video_resource_updater.h ('K') | « cc/resources/video_resource_updater.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698