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

Side by Side 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 unified diff | 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 »
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 "base/memory/shared_memory.h" 7 #include "base/memory/shared_memory.h"
8 #include "cc/resources/resource_provider.h" 8 #include "cc/resources/resource_provider.h"
9 #include "cc/test/fake_output_surface.h" 9 #include "cc/test/fake_output_surface.h"
10 #include "cc/test/fake_output_surface_client.h" 10 #include "cc/test/fake_output_surface_client.h"
11 #include "cc/test/test_shared_bitmap_manager.h" 11 #include "cc/test/test_shared_bitmap_manager.h"
12 #include "cc/test/test_web_graphics_context_3d.h" 12 #include "cc/test/test_web_graphics_context_3d.h"
13 #include "cc/trees/blocking_task_runner.h" 13 #include "cc/trees/blocking_task_runner.h"
14 #include "media/base/video_frame.h" 14 #include "media/base/video_frame.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 namespace cc { 17 namespace cc {
18 namespace { 18 namespace {
19 19
20 class WebGraphicsContext3DUploadCounter : public TestWebGraphicsContext3D {
21 public:
22 void texSubImage2D(GLenum target,
23 GLint level,
24 GLint xoffset,
25 GLint yoffset,
26 GLsizei width,
27 GLsizei height,
28 GLenum format,
29 GLenum type,
30 const void* pixels) override {
31 ++upload_count_;
32 }
33
34 int UploadCount() { return upload_count_; }
35 void ResetUploadCount() { upload_count_ = 0; }
36
37 private:
38 int upload_count_;
39 };
40
20 class VideoResourceUpdaterTest : public testing::Test { 41 class VideoResourceUpdaterTest : public testing::Test {
21 protected: 42 protected:
22 VideoResourceUpdaterTest() { 43 VideoResourceUpdaterTest() {
23 scoped_ptr<TestWebGraphicsContext3D> context3d = 44 scoped_ptr<WebGraphicsContext3DUploadCounter> context3d(
24 TestWebGraphicsContext3D::Create(); 45 new WebGraphicsContext3DUploadCounter());
46
25 context3d_ = context3d.get(); 47 context3d_ = context3d.get();
26 48
27 output_surface3d_ = 49 output_surface3d_ =
28 FakeOutputSurface::Create3d(context3d.Pass()); 50 FakeOutputSurface::Create3d(context3d.Pass());
29 CHECK(output_surface3d_->BindToClient(&client_)); 51 CHECK(output_surface3d_->BindToClient(&client_));
30 shared_bitmap_manager_.reset(new TestSharedBitmapManager()); 52 shared_bitmap_manager_.reset(new TestSharedBitmapManager());
31 resource_provider3d_ = 53 resource_provider3d_ =
32 ResourceProvider::Create(output_surface3d_.get(), 54 ResourceProvider::Create(output_surface3d_.get(),
33 shared_bitmap_manager_.get(), 55 shared_bitmap_manager_.get(),
34 NULL, 56 NULL,
(...skipping 18 matching lines...) Expand all
53 size.width(), // y_stride 75 size.width(), // y_stride
54 size.width() / 2, // u_stride 76 size.width() / 2, // u_stride
55 size.width() / 2, // v_stride 77 size.width() / 2, // v_stride
56 y_data, // y_data 78 y_data, // y_data
57 u_data, // u_data 79 u_data, // u_data
58 v_data, // v_data 80 v_data, // v_data
59 base::TimeDelta(), // timestamp, 81 base::TimeDelta(), // timestamp,
60 base::Closure()); // no_longer_needed_cb 82 base::Closure()); // no_longer_needed_cb
61 } 83 }
62 84
63 TestWebGraphicsContext3D* context3d_; 85 WebGraphicsContext3DUploadCounter* context3d_;
64 FakeOutputSurfaceClient client_; 86 FakeOutputSurfaceClient client_;
65 scoped_ptr<FakeOutputSurface> output_surface3d_; 87 scoped_ptr<FakeOutputSurface> output_surface3d_;
66 scoped_ptr<TestSharedBitmapManager> shared_bitmap_manager_; 88 scoped_ptr<TestSharedBitmapManager> shared_bitmap_manager_;
67 scoped_ptr<ResourceProvider> resource_provider3d_; 89 scoped_ptr<ResourceProvider> resource_provider3d_;
68 }; 90 };
69 91
70 TEST_F(VideoResourceUpdaterTest, SoftwareFrame) { 92 TEST_F(VideoResourceUpdaterTest, SoftwareFrame) {
71 VideoResourceUpdater updater(output_surface3d_->context_provider(), 93 VideoResourceUpdater updater(output_surface3d_->context_provider(),
72 resource_provider3d_.get()); 94 resource_provider3d_.get());
73 scoped_refptr<media::VideoFrame> video_frame = CreateTestYUVVideoFrame(); 95 scoped_refptr<media::VideoFrame> video_frame = CreateTestYUVVideoFrame();
74 96
75 VideoFrameExternalResources resources = 97 VideoFrameExternalResources resources =
76 updater.CreateExternalResourcesFromVideoFrame(video_frame); 98 updater.CreateExternalResourcesFromVideoFrame(video_frame);
77 EXPECT_EQ(VideoFrameExternalResources::YUV_RESOURCE, resources.type); 99 EXPECT_EQ(VideoFrameExternalResources::YUV_RESOURCE, resources.type);
78 } 100 }
79 101
102 TEST_F(VideoResourceUpdaterTest, ReuseResource) {
103 VideoResourceUpdater updater(output_surface3d_->context_provider(),
104 resource_provider3d_.get());
105 scoped_refptr<media::VideoFrame> video_frame = CreateTestYUVVideoFrame();
106 video_frame->set_timestamp(base::TimeDelta::FromSeconds(1234));
107
108 // Allocate the resources for a YUV video frame.
109 context3d_->ResetUploadCount();
110 VideoFrameExternalResources resources =
111 updater.CreateExternalResourcesFromVideoFrame(video_frame);
112 EXPECT_EQ(VideoFrameExternalResources::YUV_RESOURCE, resources.type);
113 EXPECT_EQ(size_t(3), resources.mailboxes.size());
114 EXPECT_EQ(size_t(3), resources.release_callbacks.size());
115 // Expect exactly three texture uploads, one for each plane.
116 EXPECT_EQ(3, context3d_->UploadCount());
117
118 const ResourceProvider::ResourceId y_resource =
119 resource_provider3d_->CreateResourceFromTextureMailbox(
120 resources.mailboxes[media::VideoFrame::kYPlane],
121 SingleReleaseCallbackImpl::Create(
122 resources.release_callbacks[media::VideoFrame::kYPlane]));
123 const ResourceProvider::ResourceId u_resource =
124 resource_provider3d_->CreateResourceFromTextureMailbox(
125 resources.mailboxes[media::VideoFrame::kUPlane],
126 SingleReleaseCallbackImpl::Create(
127 resources.release_callbacks[media::VideoFrame::kUPlane]));
128 const ResourceProvider::ResourceId v_resource =
129 resource_provider3d_->CreateResourceFromTextureMailbox(
130 resources.mailboxes[media::VideoFrame::kVPlane],
131 SingleReleaseCallbackImpl::Create(
132 resources.release_callbacks[media::VideoFrame::kVPlane]));
133
134 // Delete the resources.
135 resource_provider3d_->DeleteResource(y_resource);
136 resource_provider3d_->DeleteResource(u_resource);
137 resource_provider3d_->DeleteResource(v_resource);
138
139 // Allocate resources for the same frame.
140 context3d_->ResetUploadCount();
141 resources = updater.CreateExternalResourcesFromVideoFrame(video_frame);
142 EXPECT_EQ(VideoFrameExternalResources::YUV_RESOURCE, resources.type);
143 EXPECT_EQ(size_t(3), resources.mailboxes.size());
144 EXPECT_EQ(size_t(3), resources.release_callbacks.size());
145 // The data should be reused so expect no texture uploads.
146 EXPECT_EQ(0, context3d_->UploadCount());
147 }
148
80 } // namespace 149 } // namespace
81 } // namespace cc 150 } // namespace cc
OLDNEW
« 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