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

Side by Side Diff: content/browser/compositor/reflector_impl_unittest.cc

Issue 846063002: compositor: Fix texture flipping for SW mirroring with surfaceless (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add tests Created 5 years, 11 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
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/message_loop/message_loop.h"
6 #include "cc/test/fake_output_surface_client.h"
7 #include "cc/test/test_context_provider.h"
8 #include "cc/test/test_web_graphics_context_3d.h"
9 #include "content/browser/compositor/browser_compositor_output_surface.h"
10 #include "content/browser/compositor/reflector_impl.h"
11 #include "content/browser/compositor/test/no_transport_image_transport_factory.h "
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/compositor/compositor.h"
14 #include "ui/compositor/layer.h"
15 #include "ui/compositor/test/context_factories_for_test.h"
16
17 namespace content {
18 namespace {
19 class TestOutputSurface : public BrowserCompositorOutputSurface {
20 public:
21 TestOutputSurface(
22 const scoped_refptr<cc::ContextProvider>& context_provider,
23 int surface_id,
24 IDMap<BrowserCompositorOutputSurface>* output_surface_map,
25 const scoped_refptr<ui::CompositorVSyncManager>& vsync_manager)
26 : BrowserCompositorOutputSurface(context_provider,
27 surface_id,
28 output_surface_map,
29 vsync_manager) {}
30
31 void SetFlip(bool flip) { capabilities_.flipped_output_surface = flip; }
danakj 2015/01/22 01:04:20 can you override BindToCurrentThread() and set thi
achaulk 2015/01/23 16:45:52 BindToCurrentThread is in the context provider tho
danakj 2015/01/23 17:48:29 Argh right sorry. Fuzzy head.
32
33 void SwapBuffers(cc::CompositorFrame* frame) override {}
34 };
35
36 const gfx::Size size = gfx::Size(256, 256);
danakj 2015/01/22 01:04:20 kSomeDescriptiveNameSize?
achaulk 2015/01/23 16:45:53 Done.
37 } // namespace
danakj 2015/01/22 01:04:21 normally i think we just wrap the whole file in a
achaulk 2015/01/23 16:45:52 ReflectorImplTest is a friend of ReflectorImpl
38
39 class ReflectorImplTest : public testing::Test {
40 public:
41 void SetUp() override {
42 bool enable_pixel_output = false;
43 ui::ContextFactory* context_factory =
44 ui::InitializeContextFactoryForTests(enable_pixel_output);
45 ImageTransportFactory::InitializeForUnitTests(
46 scoped_ptr<ImageTransportFactory>(
47 new NoTransportImageTransportFactory));
48 message_loop_.reset(new base::MessageLoop());
49 proxy_ = message_loop_->message_loop_proxy();
50 compositor_.reset(new ui::Compositor(gfx::kNullAcceleratedWidget,
51 context_factory, proxy_.get()));
52 context_provider_ = cc::TestContextProvider::Create(
53 cc::TestWebGraphicsContext3D::Create().Pass());
54 output_surface_ =
55 scoped_ptr<TestOutputSurface>(
56 new TestOutputSurface(context_provider_, 1, &surface_map_,
57 compositor_->vsync_manager())).Pass();
58 CHECK(output_surface_->BindToClient(&output_surface_client_));
59
60 mirroring_layer_.reset(new ui::Layer());
61 mirroring_layer_->SetBounds(gfx::Rect(size.width(), size.height()));
62
63 int32 surface_id = 1;
64 reflector_ = new ReflectorImpl(compositor_.get(), mirroring_layer_.get(),
65 &surface_map_, proxy_.get(), surface_id);
66 }
67
68 ~ReflectorImplTest() override {
danakj 2015/01/22 01:04:20 I think you want these in Shutdown() rather than t
achaulk 2015/01/23 16:45:52 Done.
69 cc::TextureMailbox mailbox;
70 scoped_ptr<cc::SingleReleaseCallback> release;
71 if (mirroring_layer_->PrepareTextureMailbox(&mailbox, &release, false)) {
72 release->Run(0, false);
73 }
74 compositor_.reset();
75 ui::TerminateContextFactoryForTests();
76 ImageTransportFactory::Terminate();
77 }
78
79 void Init() {
80 gpu::Mailbox mailbox;
81 context_provider_->ContextGL()->GenMailboxCHROMIUM(mailbox.name);
82 reflector_->AttachToOutputSurfaceOnImplThread(
83 gpu::MailboxHolder(mailbox, GL_TEXTURE_2D, 0 /* sync_point */),
84 output_surface_.get());
85 }
86
87 void UpdateTexture() {
88 reflector_->UpdateSubBufferOnMainThread(size, gfx::Rect(0, 0, 64, 64));
89 }
90
91 protected:
92 IDMap<BrowserCompositorOutputSurface> surface_map_;
93 scoped_refptr<cc::ContextProvider> context_provider_;
94 cc::FakeOutputSurfaceClient output_surface_client_;
95 scoped_ptr<base::MessageLoop> message_loop_;
96 scoped_refptr<base::MessageLoopProxy> proxy_;
97 scoped_ptr<ui::Compositor> compositor_;
98 scoped_ptr<ui::Layer> mirroring_layer_;
99 scoped_refptr<ReflectorImpl> reflector_;
100 scoped_ptr<TestOutputSurface> output_surface_;
101 };
102
103 namespace {
104 TEST_F(ReflectorImplTest, CheckNormalOutputSurface) {
105 output_surface_->SetFlip(false);
106 Init();
107 UpdateTexture();
108 EXPECT_TRUE(mirroring_layer_->TextureFlipped());
109 EXPECT_EQ(SkRegion(SkIRect::MakeXYWH(0, size.height() - 64, 64, 64)),
110 mirroring_layer_->damaged_region());
111 }
112
113 TEST_F(ReflectorImplTest, CheckInvertedOutputSurface) {
114 output_surface_->SetFlip(true);
115 Init();
116 UpdateTexture();
117 EXPECT_FALSE(mirroring_layer_->TextureFlipped());
118 EXPECT_EQ(SkRegion(SkIRect::MakeXYWH(0, 0, 64, 64)),
119 mirroring_layer_->damaged_region());
120 }
121
122 } // namespace
123 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698