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

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

Issue 952893003: Update from https://crrev.com/317530 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Fix gn for nacl 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
« no previous file with comments | « cc/resources/video_resource_updater.h ('k') | cc/resources/video_resource_updater_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 resource_provider_->DeleteResource(plane_resource.resource_id); 89 resource_provider_->DeleteResource(plane_resource.resource_id);
89 } 90 }
90 91
91 VideoResourceUpdater::ResourceList::iterator 92 VideoResourceUpdater::ResourceList::iterator
92 VideoResourceUpdater::AllocateResource(const gfx::Size& plane_size, 93 VideoResourceUpdater::AllocateResource(const gfx::Size& plane_size,
93 ResourceFormat format, 94 ResourceFormat format,
94 bool has_mailbox) { 95 bool has_mailbox) {
95 // TODO(danakj): Abstract out hw/sw resource create/delete from 96 // TODO(danakj): Abstract out hw/sw resource create/delete from
96 // ResourceProvider and stop using ResourceProvider in this class. 97 // ResourceProvider and stop using ResourceProvider in this class.
97 const ResourceProvider::ResourceId resource_id = 98 const ResourceProvider::ResourceId resource_id =
98 resource_provider_->CreateResource(plane_size, GL_CLAMP_TO_EDGE, 99 resource_provider_->CreateResource(
99 ResourceProvider::TextureHintImmutable, 100 plane_size, GL_CLAMP_TO_EDGE,
100 format); 101 ResourceProvider::TEXTURE_HINT_IMMUTABLE, format);
101 if (resource_id == 0) 102 if (resource_id == 0)
102 return all_resources_.end(); 103 return all_resources_.end();
103 104
104 gpu::Mailbox mailbox; 105 gpu::Mailbox mailbox;
105 if (has_mailbox) { 106 if (has_mailbox) {
106 DCHECK(context_provider_); 107 DCHECK(context_provider_);
107 108
108 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); 109 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL();
109 110
110 GLC(gl, gl->GenMailboxCHROMIUM(mailbox.name)); 111 GLC(gl, gl->GenMailboxCHROMIUM(mailbox.name));
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 } 311 }
311 312
312 for (size_t i = 0; i < plane_resources.size(); ++i) { 313 for (size_t i = 0; i < plane_resources.size(); ++i) {
313 PlaneResource& plane_resource = *plane_resources[i]; 314 PlaneResource& plane_resource = *plane_resources[i];
314 // Update each plane's resource id with its content. 315 // Update each plane's resource id with its content.
315 DCHECK_EQ(plane_resource.resource_format, 316 DCHECK_EQ(plane_resource.resource_format,
316 resource_provider_->yuv_resource_format()); 317 resource_provider_->yuv_resource_format());
317 318
318 if (!PlaneResourceMatchesUniqueID(plane_resource, video_frame.get(), i)) { 319 if (!PlaneResourceMatchesUniqueID(plane_resource, video_frame.get(), i)) {
319 // We need to transfer data from |video_frame| to the plane resource. 320 // We need to transfer data from |video_frame| to the plane resource.
320 const uint8_t* input_plane_pixels = video_frame->data(i); 321 // TODO(reveman): Can use GpuMemoryBuffers here to improve performance.
321 322
322 gfx::Rect image_rect(0, 0, video_frame->stride(i), 323 // The |resource_size_pixels| is the size of the resource we want to
323 plane_resource.resource_size.height()); 324 // upload to.
324 gfx::Rect source_rect(plane_resource.resource_size); 325 gfx::Size resource_size_pixels = plane_resource.resource_size;
325 resource_provider_->SetPixels(plane_resource.resource_id, 326 // The |video_stride_pixels| is the width of the video frame we are
326 input_plane_pixels, image_rect, source_rect, 327 // uploading (including non-frame data to fill in the stride).
327 gfx::Vector2d()); 328 size_t video_stride_pixels = video_frame->stride(i);
329
330 size_t bytes_per_pixel = BitsPerPixel(plane_resource.resource_format) / 8;
331 // Use 4-byte row alignment (OpenGL default) for upload performance.
332 // Assuming that GL_UNPACK_ALIGNMENT has not changed from default.
333 size_t upload_image_stride =
334 RoundUp<size_t>(bytes_per_pixel * resource_size_pixels.width(), 4u);
335
336 const uint8_t* pixels;
337 if (upload_image_stride == video_stride_pixels * bytes_per_pixel) {
338 pixels = video_frame->data(i);
339 } else {
340 // Avoid malloc for each frame/plane if possible.
341 size_t needed_size =
342 upload_image_stride * resource_size_pixels.height();
343 if (upload_pixels_.size() < needed_size)
344 upload_pixels_.resize(needed_size);
345 for (int row = 0; row < resource_size_pixels.height(); ++row) {
346 uint8_t* dst = &upload_pixels_[upload_image_stride * row];
347 const uint8_t* src = video_frame->data(i) +
348 bytes_per_pixel * video_stride_pixels * row;
349 memcpy(dst, src, resource_size_pixels.width() * bytes_per_pixel);
350 }
351 pixels = &upload_pixels_[0];
352 }
353
354 resource_provider_->CopyToResource(plane_resource.resource_id, pixels,
355 resource_size_pixels);
328 SetPlaneResourceUniqueId(video_frame.get(), i, &plane_resource); 356 SetPlaneResourceUniqueId(video_frame.get(), i, &plane_resource);
329 } 357 }
330 358
331 external_resources.mailboxes.push_back( 359 external_resources.mailboxes.push_back(
332 TextureMailbox(plane_resource.mailbox, GL_TEXTURE_2D, 0)); 360 TextureMailbox(plane_resource.mailbox, GL_TEXTURE_2D, 0));
333 external_resources.release_callbacks.push_back( 361 external_resources.release_callbacks.push_back(
334 base::Bind(&RecycleResource, AsWeakPtr(), plane_resource.resource_id)); 362 base::Bind(&RecycleResource, AsWeakPtr(), plane_resource.resource_id));
335 } 363 }
336 364
337 external_resources.type = VideoFrameExternalResources::YUV_RESOURCE; 365 external_resources.type = VideoFrameExternalResources::YUV_RESOURCE;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 resource_it->ref_count = 0; 455 resource_it->ref_count = 0;
428 updater->DeleteResource(resource_it); 456 updater->DeleteResource(resource_it);
429 return; 457 return;
430 } 458 }
431 459
432 --resource_it->ref_count; 460 --resource_it->ref_count;
433 DCHECK_GE(resource_it->ref_count, 0); 461 DCHECK_GE(resource_it->ref_count, 0);
434 } 462 }
435 463
436 } // namespace cc 464 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/video_resource_updater.h ('k') | cc/resources/video_resource_updater_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698