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

Unified Diff: cc/resources/video_resource_updater_unittest.cc

Issue 761903003: Update from https://crrev.com/306655 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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
« no previous file with comments | « cc/resources/video_resource_updater.cc ('k') | cc/scheduler/begin_frame_source.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/resources/video_resource_updater_unittest.cc
diff --git a/cc/resources/video_resource_updater_unittest.cc b/cc/resources/video_resource_updater_unittest.cc
index c0a4af402c4511f3c0721ecc9c68e74f3490c086..1e3481bb3b2312a55716b92d60be0bbfb03fa0c0 100644
--- a/cc/resources/video_resource_updater_unittest.cc
+++ b/cc/resources/video_resource_updater_unittest.cc
@@ -17,11 +17,33 @@
namespace cc {
namespace {
+class WebGraphicsContext3DUploadCounter : public TestWebGraphicsContext3D {
+ public:
+ void texSubImage2D(GLenum target,
+ GLint level,
+ GLint xoffset,
+ GLint yoffset,
+ GLsizei width,
+ GLsizei height,
+ GLenum format,
+ GLenum type,
+ const void* pixels) override {
+ ++upload_count_;
+ }
+
+ int UploadCount() { return upload_count_; }
+ void ResetUploadCount() { upload_count_ = 0; }
+
+ private:
+ int upload_count_;
+};
+
class VideoResourceUpdaterTest : public testing::Test {
protected:
VideoResourceUpdaterTest() {
- scoped_ptr<TestWebGraphicsContext3D> context3d =
- TestWebGraphicsContext3D::Create();
+ scoped_ptr<WebGraphicsContext3DUploadCounter> context3d(
+ new WebGraphicsContext3DUploadCounter());
+
context3d_ = context3d.get();
output_surface3d_ =
@@ -60,7 +82,7 @@ class VideoResourceUpdaterTest : public testing::Test {
base::Closure()); // no_longer_needed_cb
}
- TestWebGraphicsContext3D* context3d_;
+ WebGraphicsContext3DUploadCounter* context3d_;
FakeOutputSurfaceClient client_;
scoped_ptr<FakeOutputSurface> output_surface3d_;
scoped_ptr<TestSharedBitmapManager> shared_bitmap_manager_;
@@ -77,5 +99,52 @@ TEST_F(VideoResourceUpdaterTest, SoftwareFrame) {
EXPECT_EQ(VideoFrameExternalResources::YUV_RESOURCE, resources.type);
}
+TEST_F(VideoResourceUpdaterTest, ReuseResource) {
+ VideoResourceUpdater updater(output_surface3d_->context_provider(),
+ resource_provider3d_.get());
+ scoped_refptr<media::VideoFrame> video_frame = CreateTestYUVVideoFrame();
+ video_frame->set_timestamp(base::TimeDelta::FromSeconds(1234));
+
+ // Allocate the resources for a YUV video frame.
+ context3d_->ResetUploadCount();
+ VideoFrameExternalResources resources =
+ updater.CreateExternalResourcesFromVideoFrame(video_frame);
+ EXPECT_EQ(VideoFrameExternalResources::YUV_RESOURCE, resources.type);
+ EXPECT_EQ(size_t(3), resources.mailboxes.size());
+ EXPECT_EQ(size_t(3), resources.release_callbacks.size());
+ // Expect exactly three texture uploads, one for each plane.
+ EXPECT_EQ(3, context3d_->UploadCount());
+
+ const ResourceProvider::ResourceId y_resource =
+ resource_provider3d_->CreateResourceFromTextureMailbox(
+ resources.mailboxes[media::VideoFrame::kYPlane],
+ SingleReleaseCallbackImpl::Create(
+ resources.release_callbacks[media::VideoFrame::kYPlane]));
+ const ResourceProvider::ResourceId u_resource =
+ resource_provider3d_->CreateResourceFromTextureMailbox(
+ resources.mailboxes[media::VideoFrame::kUPlane],
+ SingleReleaseCallbackImpl::Create(
+ resources.release_callbacks[media::VideoFrame::kUPlane]));
+ const ResourceProvider::ResourceId v_resource =
+ resource_provider3d_->CreateResourceFromTextureMailbox(
+ resources.mailboxes[media::VideoFrame::kVPlane],
+ SingleReleaseCallbackImpl::Create(
+ resources.release_callbacks[media::VideoFrame::kVPlane]));
+
+ // Delete the resources.
+ resource_provider3d_->DeleteResource(y_resource);
+ resource_provider3d_->DeleteResource(u_resource);
+ resource_provider3d_->DeleteResource(v_resource);
+
+ // Allocate resources for the same frame.
+ context3d_->ResetUploadCount();
+ resources = updater.CreateExternalResourcesFromVideoFrame(video_frame);
+ EXPECT_EQ(VideoFrameExternalResources::YUV_RESOURCE, resources.type);
+ EXPECT_EQ(size_t(3), resources.mailboxes.size());
+ EXPECT_EQ(size_t(3), resources.release_callbacks.size());
+ // The data should be reused so expect no texture uploads.
+ EXPECT_EQ(0, context3d_->UploadCount());
+}
+
} // namespace
} // namespace cc
« no previous file with comments | « cc/resources/video_resource_updater.cc ('k') | cc/scheduler/begin_frame_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698