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

Side by Side Diff: cc/trees/layer_tree_host_unittest.cc

Issue 14098007: cc: Add a test that the IOSurface drawing path makes the right context calls. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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/trees/layer_tree_host.h" 5 #include "cc/trees/layer_tree_host.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/synchronization/lock.h" 9 #include "base/synchronization/lock.h"
10 #include "cc/animation/timing_function.h" 10 #include "cc/animation/timing_function.h"
11 #include "cc/layers/content_layer.h" 11 #include "cc/layers/content_layer.h"
12 #include "cc/layers/content_layer_client.h" 12 #include "cc/layers/content_layer_client.h"
13 #include "cc/layers/io_surface_layer.h"
13 #include "cc/layers/layer_impl.h" 14 #include "cc/layers/layer_impl.h"
14 #include "cc/layers/picture_layer.h" 15 #include "cc/layers/picture_layer.h"
15 #include "cc/layers/scrollbar_layer.h" 16 #include "cc/layers/scrollbar_layer.h"
16 #include "cc/output/output_surface.h" 17 #include "cc/output/output_surface.h"
17 #include "cc/resources/prioritized_resource.h" 18 #include "cc/resources/prioritized_resource.h"
18 #include "cc/resources/prioritized_resource_manager.h" 19 #include "cc/resources/prioritized_resource_manager.h"
19 #include "cc/resources/resource_update_queue.h" 20 #include "cc/resources/resource_update_queue.h"
20 #include "cc/scheduler/frame_rate_controller.h" 21 #include "cc/scheduler/frame_rate_controller.h"
21 #include "cc/test/fake_content_layer.h" 22 #include "cc/test/fake_content_layer.h"
22 #include "cc/test/fake_content_layer_client.h" 23 #include "cc/test/fake_content_layer_client.h"
23 #include "cc/test/fake_layer_tree_host_client.h" 24 #include "cc/test/fake_layer_tree_host_client.h"
24 #include "cc/test/fake_output_surface.h" 25 #include "cc/test/fake_output_surface.h"
25 #include "cc/test/fake_proxy.h" 26 #include "cc/test/fake_proxy.h"
26 #include "cc/test/fake_scrollbar_layer.h" 27 #include "cc/test/fake_scrollbar_layer.h"
27 #include "cc/test/geometry_test_utils.h" 28 #include "cc/test/geometry_test_utils.h"
28 #include "cc/test/layer_tree_test.h" 29 #include "cc/test/layer_tree_test.h"
29 #include "cc/test/occlusion_tracker_test_common.h" 30 #include "cc/test/occlusion_tracker_test_common.h"
30 #include "cc/trees/layer_tree_host_impl.h" 31 #include "cc/trees/layer_tree_host_impl.h"
31 #include "cc/trees/layer_tree_impl.h" 32 #include "cc/trees/layer_tree_impl.h"
32 #include "cc/trees/single_thread_proxy.h" 33 #include "cc/trees/single_thread_proxy.h"
33 #include "cc/trees/thread_proxy.h" 34 #include "cc/trees/thread_proxy.h"
35 #include "gpu/GLES2/gl2extchromium.h"
34 #include "skia/ext/refptr.h" 36 #include "skia/ext/refptr.h"
35 #include "testing/gmock/include/gmock/gmock.h" 37 #include "testing/gmock/include/gmock/gmock.h"
36 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" 38 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h"
37 #include "third_party/khronos/GLES2/gl2.h" 39 #include "third_party/khronos/GLES2/gl2.h"
38 #include "third_party/khronos/GLES2/gl2ext.h" 40 #include "third_party/khronos/GLES2/gl2ext.h"
39 #include "third_party/skia/include/core/SkPicture.h" 41 #include "third_party/skia/include/core/SkPicture.h"
40 #include "ui/gfx/point_conversions.h" 42 #include "ui/gfx/point_conversions.h"
41 #include "ui/gfx/size_conversions.h" 43 #include "ui/gfx/size_conversions.h"
42 #include "ui/gfx/vector2d_conversions.h" 44 #include "ui/gfx/vector2d_conversions.h"
43 45
46 using testing::_;
47 using testing::AnyNumber;
48 using testing::AtLeast;
49 using testing::Mock;
50
44 namespace cc { 51 namespace cc {
45 namespace { 52 namespace {
46 53
47 class LayerTreeHostTest : public LayerTreeTest { 54 class LayerTreeHostTest : public LayerTreeTest {
48 }; 55 };
49 56
50 // Test interleaving of redraws and commits 57 // Test interleaving of redraws and commits
51 class LayerTreeHostTestCommitingWithContinuousRedraw 58 class LayerTreeHostTestCommitingWithContinuousRedraw
52 : public LayerTreeHostTest { 59 : public LayerTreeHostTest {
53 public: 60 public:
(...skipping 2267 matching lines...) Expand 10 before | Expand all | Expand 10 after
2321 } 2328 }
2322 } 2329 }
2323 2330
2324 private: 2331 private:
2325 SetBoundsClient client_; 2332 SetBoundsClient client_;
2326 int num_commits_; 2333 int num_commits_;
2327 }; 2334 };
2328 2335
2329 SINGLE_THREAD_TEST_F(LayerTreeHostTestChangeLayerPropertiesInPaintContents); 2336 SINGLE_THREAD_TEST_F(LayerTreeHostTestChangeLayerPropertiesInPaintContents);
2330 2337
2338 class MockIOSurfaceWebGraphicsContext3D : public FakeWebGraphicsContext3D {
2339 public:
2340 MockIOSurfaceWebGraphicsContext3D()
2341 : FakeWebGraphicsContext3D() {}
2342
2343 virtual WebKit::WebGLId createTexture() OVERRIDE {
2344 return 1;
2345 }
2346
2347 virtual WebKit::WebString getString(WebKit::WGC3Denum name) OVERRIDE {
2348 if (name == GL_EXTENSIONS) {
2349 return WebKit::WebString(
2350 "GL_CHROMIUM_iosurface GL_ARB_texture_rectangle");
2351 }
2352 return WebKit::WebString();
2353 }
2354
2355 MOCK_METHOD1(activeTexture, void(WebKit::WGC3Denum texture));
2356 MOCK_METHOD2(bindTexture, void(WebKit::WGC3Denum target,
2357 WebKit::WebGLId texture_id));
2358 MOCK_METHOD3(texParameteri, void(WebKit::WGC3Denum target,
2359 WebKit::WGC3Denum pname,
2360 WebKit::WGC3Dint param));
2361 MOCK_METHOD5(texImageIOSurface2DCHROMIUM, void(WebKit::WGC3Denum target,
2362 WebKit::WGC3Dint width,
2363 WebKit::WGC3Dint height,
2364 WebKit::WGC3Duint ioSurfaceId,
2365 WebKit::WGC3Duint plane));
2366 MOCK_METHOD4(drawElements, void(WebKit::WGC3Denum mode,
2367 WebKit::WGC3Dsizei count,
2368 WebKit::WGC3Denum type,
2369 WebKit::WGC3Dintptr offset));
2370 };
2371
2372
2373 class LayerTreeHostTestIOSurfaceDrawing : public LayerTreeHostTest {
2374 protected:
2375 virtual scoped_ptr<OutputSurface> CreateOutputSurface() OVERRIDE {
2376 scoped_ptr<MockIOSurfaceWebGraphicsContext3D> context(
2377 new MockIOSurfaceWebGraphicsContext3D);
2378 mock_context_ = context.get();
2379 scoped_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(
2380 context.PassAs<WebKit::WebGraphicsContext3D>()).PassAs<OutputSurface>();
2381 return output_surface.Pass();
2382 }
2383
2384 virtual void SetupTree() OVERRIDE {
2385 LayerTreeHostTest::SetupTree();
2386
2387 layer_tree_host()->root_layer()->SetIsDrawable(false);
2388
2389 io_surface_id_ = 9;
2390 io_surface_size_ = gfx::Size(6, 7);
2391
2392 scoped_refptr<IOSurfaceLayer> io_surface_layer = IOSurfaceLayer::Create();
2393 io_surface_layer->SetBounds(gfx::Size(10, 10));
2394 io_surface_layer->SetAnchorPoint(gfx::PointF());
2395 io_surface_layer->SetIsDrawable(true);
2396 io_surface_layer->SetIOSurfaceProperties(io_surface_id_, io_surface_size_);
2397 layer_tree_host()->root_layer()->AddChild(io_surface_layer);
2398 }
2399
2400 virtual void BeginTest() OVERRIDE {
2401 PostSetNeedsCommitToMainThread();
2402 }
2403
2404 virtual void TreeActivatedOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
2405 // In WillDraw, the IOSurfaceLayer sets up the io surface texture.
2406
2407 EXPECT_CALL(*mock_context_, activeTexture(_))
2408 .Times(0);
2409 EXPECT_CALL(*mock_context_, bindTexture(GL_TEXTURE_RECTANGLE_ARB, 1))
2410 .Times(AtLeast(1));
2411 EXPECT_CALL(*mock_context_, texParameteri(GL_TEXTURE_RECTANGLE_ARB,
2412 GL_TEXTURE_MIN_FILTER,
2413 GL_LINEAR))
2414 .Times(1);
2415 EXPECT_CALL(*mock_context_, texParameteri(GL_TEXTURE_RECTANGLE_ARB,
2416 GL_TEXTURE_MAG_FILTER,
2417 GL_LINEAR))
2418 .Times(1);
2419 EXPECT_CALL(*mock_context_, texParameteri(GL_TEXTURE_RECTANGLE_ARB,
2420 GL_TEXTURE_WRAP_S,
2421 GL_CLAMP_TO_EDGE))
2422 .Times(1);
2423 EXPECT_CALL(*mock_context_, texParameteri(GL_TEXTURE_RECTANGLE_ARB,
2424 GL_TEXTURE_WRAP_T,
2425 GL_CLAMP_TO_EDGE))
2426 .Times(1);
2427
2428 EXPECT_CALL(*mock_context_, texImageIOSurface2DCHROMIUM(
2429 GL_TEXTURE_RECTANGLE_ARB,
2430 io_surface_size_.width(),
2431 io_surface_size_.height(),
2432 io_surface_id_,
2433 0))
2434 .Times(1);
2435
2436 EXPECT_CALL(*mock_context_, bindTexture(_, 0))
2437 .Times(AnyNumber());
2438 }
2439
2440 virtual bool PrepareToDrawOnThread(
2441 LayerTreeHostImpl* host_impl,
2442 LayerTreeHostImpl::FrameData* frame,
2443 bool result) OVERRIDE {
2444 Mock::VerifyAndClearExpectations(&mock_context_);
2445
2446 // The io surface layer's texture is drawn.
2447 EXPECT_CALL(*mock_context_, activeTexture(GL_TEXTURE0))
2448 .Times(AtLeast(1));
2449 EXPECT_CALL(*mock_context_, bindTexture(GL_TEXTURE_RECTANGLE_ARB, 1))
2450 .Times(1);
2451 EXPECT_CALL(*mock_context_, drawElements(GL_TRIANGLES, 6, _, _))
2452 .Times(AtLeast(1));
2453
2454 return result;
2455 }
2456
2457 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
2458 Mock::VerifyAndClearExpectations(&mock_context_);
2459 EndTest();
2460 }
2461
2462 virtual void AfterTest() OVERRIDE {}
2463
2464 int io_surface_id_;
2465 MockIOSurfaceWebGraphicsContext3D* mock_context_;
2466 gfx::Size io_surface_size_;
2467 };
2468
2469 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestIOSurfaceDrawing);
2470
2331 } // namespace 2471 } // namespace
2332 } // namespace cc 2472 } // namespace cc
OLDNEW
« cc/layers/io_surface_layer_impl.cc ('K') | « cc/layers/io_surface_layer_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698