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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: cc/resources/video_resource_updater.cc
diff --git a/cc/resources/video_resource_updater.cc b/cc/resources/video_resource_updater.cc
index 0e772ebf22eccac90563463f609d3807b03989c1..41ee16a28cc13fbe1f7bf39e5ee553af148e6735 100644
--- a/cc/resources/video_resource_updater.cc
+++ b/cc/resources/video_resource_updater.cc
@@ -8,6 +8,7 @@
#include "base/bind.h"
#include "base/trace_event/trace_event.h"
+#include "cc/base/util.h"
#include "cc/output/gl_renderer.h"
#include "cc/resources/resource_provider.h"
#include "gpu/GLES2/gl2extchromium.h"
@@ -80,7 +81,8 @@ VideoFrameExternalResources::~VideoFrameExternalResources() {}
VideoResourceUpdater::VideoResourceUpdater(ContextProvider* context_provider,
ResourceProvider* resource_provider)
: context_provider_(context_provider),
- resource_provider_(resource_provider) {
+ resource_provider_(resource_provider),
+ upload_pixels_size_(0) {
}
VideoResourceUpdater::~VideoResourceUpdater() {
@@ -317,14 +319,43 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes(
if (!PlaneResourceMatchesUniqueID(plane_resource, video_frame.get(), i)) {
// We need to transfer data from |video_frame| to the plane resource.
- const uint8_t* input_plane_pixels = video_frame->data(i);
-
- gfx::Rect image_rect(0, 0, video_frame->stride(i),
- plane_resource.resource_size.height());
- gfx::Rect source_rect(plane_resource.resource_size);
- resource_provider_->SetPixels(plane_resource.resource_id,
- input_plane_pixels, image_rect, source_rect,
- gfx::Vector2d());
+ // TODO(reveman): Can use of GpuMemoryBuffers here to improve performance.
enne (OOO) 2015/02/19 19:53:03 s/of//
+
+ // The |resource_size_pixels| is the size of the resource we want to
+ // upload to.
+ gfx::Size resource_size_pixels = plane_resource.resource_size;
+ // The |video_stride_pixels| is the width of the video frame we are
+ // uploading (including non-frame data to fill in the stride).
+ size_t video_stride_pixels = video_frame->stride(i);
+
+ size_t bytes_per_pixel = BitsPerPixel(plane_resource.resource_format) / 8;
+ // Use 4-byte row alignment (OpenGL default) for upload performance.
+ // Assuming that GL_UNPACK_ALIGNMENT has not changed from default.
+ size_t upload_image_stride =
+ RoundUp<size_t>(bytes_per_pixel * resource_size_pixels.width(), 4u);
+
+ const uint8_t* pixels;
+ if (upload_image_stride == video_stride_pixels * bytes_per_pixel) {
+ pixels = video_frame->data(i);
+ } else {
+ // Avoid malloc for each frame/plane if possible.
+ size_t needed_size =
+ upload_image_stride * resource_size_pixels.height();
+ if (upload_pixels_size_ < needed_size) {
+ upload_pixels_.reset(new uint8_t[needed_size]);
+ upload_pixels_size_ = needed_size;
+ }
+ for (int row = 0; row < resource_size_pixels.height(); ++row) {
+ uint8_t* dst = &upload_pixels_[upload_image_stride * row];
+ const uint8_t* src = video_frame->data(i) +
+ bytes_per_pixel * video_stride_pixels * row;
+ memcpy(dst, src, resource_size_pixels.width() * bytes_per_pixel);
+ }
+ pixels = upload_pixels_.get();
+ }
+
+ resource_provider_->CopyToResource(plane_resource.resource_id, pixels,
+ resource_size_pixels);
SetPlaneResourceUniqueId(video_frame.get(), i, &plane_resource);
}
« 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