summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordanakj <danakj@chromium.org>2015-02-19 15:40:02 -0800
committerCommit bot <commit-bot@chromium.org>2015-02-19 23:41:28 +0000
commite3f994390b28d440bacfa88031077761a29f1854 (patch)
treee482270661ab7928ff2294924a8b9d29de757d20
parentd73f477d8ba33f1b478f3c9b49fc7cd57cea700a (diff)
downloadchromium_src-e3f994390b28d440bacfa88031077761a29f1854.zip
chromium_src-e3f994390b28d440bacfa88031077761a29f1854.tar.gz
chromium_src-e3f994390b28d440bacfa88031077761a29f1854.tar.bz2
cc: Make VideoResourceUpdater use CopyToResource instead of SetPixels.
This makes video stop relying on the TextureUploader class. I've ported the stride-handling code from TextureUploader to the VideoResourceUpdater class, since it is the only place that will make use for it for now. R=enne BUG=454575 Review URL: https://codereview.chromium.org/935383004 Cr-Commit-Position: refs/heads/master@{#317171}
-rw-r--r--cc/resources/video_resource_updater.cc44
-rw-r--r--cc/resources/video_resource_updater.h1
2 files changed, 37 insertions, 8 deletions
diff --git a/cc/resources/video_resource_updater.cc b/cc/resources/video_resource_updater.cc
index 0e772eb..4a5f642 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"
@@ -317,14 +318,41 @@ 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 GpuMemoryBuffers here to improve performance.
+
+ // 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_.resize(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_[0];
+ }
+
+ resource_provider_->CopyToResource(plane_resource.resource_id, pixels,
+ resource_size_pixels);
SetPlaneResourceUniqueId(video_frame.get(), i, &plane_resource);
}
diff --git a/cc/resources/video_resource_updater.h b/cc/resources/video_resource_updater.h
index 622fe68..1bccf79 100644
--- a/cc/resources/video_resource_updater.h
+++ b/cc/resources/video_resource_updater.h
@@ -131,6 +131,7 @@ class CC_EXPORT VideoResourceUpdater
ContextProvider* context_provider_;
ResourceProvider* resource_provider_;
scoped_ptr<media::SkCanvasVideoRenderer> video_renderer_;
+ std::vector<uint8_t> upload_pixels_;
// Recycle resources so that we can reduce the number of allocations and
// data transfers.