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

Side by Side Diff: gpu/ipc/service/direct_composition_surface_win_unittest.cc

Issue 2968503003: Allow presenting DXGI share handles as overlays. (Closed)
Patch Set: fix keyed mutex usage Created 3 years, 5 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 | « gpu/ipc/service/direct_composition_surface_win.cc ('k') | media/gpu/dxva_picture_buffer_win.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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "gpu/ipc/service/direct_composition_surface_win.h" 5 #include "gpu/ipc/service/direct_composition_surface_win.h"
6 6
7 #include "base/memory/ref_counted_memory.h" 7 #include "base/memory/ref_counted_memory.h"
8 #include "base/memory/weak_ptr.h" 8 #include "base/memory/weak_ptr.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 // Ensure that the ChildWindowWin posts the task to delete the thread to the 104 // Ensure that the ChildWindowWin posts the task to delete the thread to the
105 // main loop before doing RunUntilIdle. Otherwise the child threads could 105 // main loop before doing RunUntilIdle. Otherwise the child threads could
106 // outlive the main thread. 106 // outlive the main thread.
107 RunPendingTasks(task_runner); 107 RunPendingTasks(task_runner);
108 108
109 base::RunLoop().RunUntilIdle(); 109 base::RunLoop().RunUntilIdle();
110 } 110 }
111 111
112 base::win::ScopedComPtr<ID3D11Texture2D> CreateNV12Texture( 112 base::win::ScopedComPtr<ID3D11Texture2D> CreateNV12Texture(
113 const base::win::ScopedComPtr<ID3D11Device>& d3d11_device, 113 const base::win::ScopedComPtr<ID3D11Device>& d3d11_device,
114 const gfx::Size& size) { 114 const gfx::Size& size,
115 bool shared) {
115 D3D11_TEXTURE2D_DESC desc = {}; 116 D3D11_TEXTURE2D_DESC desc = {};
116 desc.Width = size.width(); 117 desc.Width = size.width();
117 desc.Height = size.height(); 118 desc.Height = size.height();
118 desc.MipLevels = 1; 119 desc.MipLevels = 1;
119 desc.ArraySize = 1; 120 desc.ArraySize = 1;
120 desc.Format = DXGI_FORMAT_NV12; 121 desc.Format = DXGI_FORMAT_NV12;
121 desc.Usage = D3D11_USAGE_DEFAULT; 122 desc.Usage = D3D11_USAGE_DEFAULT;
122 desc.SampleDesc.Count = 1; 123 desc.SampleDesc.Count = 1;
123 desc.BindFlags = 0; 124 desc.BindFlags = 0;
125 if (shared) {
126 desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX |
127 D3D11_RESOURCE_MISC_SHARED_NTHANDLE;
128 }
124 129
125 std::vector<char> image_data(size.width() * size.height() * 3 / 2); 130 std::vector<char> image_data(size.width() * size.height() * 3 / 2);
126 // Y, U, and V should all be Oxff. Output color should be pink. 131 // Y, U, and V should all be Oxff. Output color should be pink.
127 memset(&image_data[0], 0xff, size.width() * size.height() * 3 / 2); 132 memset(&image_data[0], 0xff, size.width() * size.height() * 3 / 2);
128 133
129 D3D11_SUBRESOURCE_DATA data = {}; 134 D3D11_SUBRESOURCE_DATA data = {};
130 data.pSysMem = (const void*)&image_data[0]; 135 data.pSysMem = (const void*)&image_data[0];
131 data.SysMemPitch = size.width(); 136 data.SysMemPitch = size.width();
132 137
133 base::win::ScopedComPtr<ID3D11Texture2D> texture; 138 base::win::ScopedComPtr<ID3D11Texture2D> texture;
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 gfx::Size window_size(100, 100); 315 gfx::Size window_size(100, 100);
311 316
312 scoped_refptr<gl::GLContext> context = 317 scoped_refptr<gl::GLContext> context =
313 gl::init::CreateGLContext(nullptr, surface.get(), gl::GLContextAttribs()); 318 gl::init::CreateGLContext(nullptr, surface.get(), gl::GLContextAttribs());
314 319
315 base::win::ScopedComPtr<ID3D11Device> d3d11_device = 320 base::win::ScopedComPtr<ID3D11Device> d3d11_device =
316 gl::QueryD3D11DeviceObjectFromANGLE(); 321 gl::QueryD3D11DeviceObjectFromANGLE();
317 322
318 gfx::Size texture_size(50, 50); 323 gfx::Size texture_size(50, 50);
319 base::win::ScopedComPtr<ID3D11Texture2D> texture = 324 base::win::ScopedComPtr<ID3D11Texture2D> texture =
320 CreateNV12Texture(d3d11_device, texture_size); 325 CreateNV12Texture(d3d11_device, texture_size, false);
321 326
322 scoped_refptr<gl::GLImageDXGI> image_dxgi( 327 scoped_refptr<gl::GLImageDXGI> image_dxgi(
323 new gl::GLImageDXGI(texture_size, nullptr)); 328 new gl::GLImageDXGI(texture_size, nullptr));
324 image_dxgi->SetTexture(texture, 0); 329 image_dxgi->SetTexture(texture, 0);
325 330
326 ui::DCRendererLayerParams params( 331 ui::DCRendererLayerParams params(
327 false, gfx::Rect(), 1, gfx::Transform(), 332 false, gfx::Rect(), 1, gfx::Transform(),
328 std::vector<scoped_refptr<gl::GLImage>>{image_dxgi}, 333 std::vector<scoped_refptr<gl::GLImage>>{image_dxgi},
329 gfx::RectF(gfx::Rect(texture_size)), gfx::Rect(window_size), 0, 0, 1.0, 334 gfx::RectF(gfx::Rect(texture_size)), gfx::Rect(window_size), 0, 0, 1.0,
330 0); 335 0);
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 491
487 scoped_refptr<gl::GLContext> context = gl::init::CreateGLContext( 492 scoped_refptr<gl::GLContext> context = gl::init::CreateGLContext(
488 nullptr, surface_.get(), gl::GLContextAttribs()); 493 nullptr, surface_.get(), gl::GLContextAttribs());
489 EXPECT_TRUE(surface_->Resize(window_size, 1.0, true)); 494 EXPECT_TRUE(surface_->Resize(window_size, 1.0, true));
490 495
491 base::win::ScopedComPtr<ID3D11Device> d3d11_device = 496 base::win::ScopedComPtr<ID3D11Device> d3d11_device =
492 gl::QueryD3D11DeviceObjectFromANGLE(); 497 gl::QueryD3D11DeviceObjectFromANGLE();
493 498
494 gfx::Size texture_size(50, 50); 499 gfx::Size texture_size(50, 50);
495 base::win::ScopedComPtr<ID3D11Texture2D> texture = 500 base::win::ScopedComPtr<ID3D11Texture2D> texture =
496 CreateNV12Texture(d3d11_device, texture_size); 501 CreateNV12Texture(d3d11_device, texture_size, false);
497 502
498 scoped_refptr<gl::GLImageDXGI> image_dxgi( 503 scoped_refptr<gl::GLImageDXGI> image_dxgi(
499 new gl::GLImageDXGI(texture_size, nullptr)); 504 new gl::GLImageDXGI(texture_size, nullptr));
500 image_dxgi->SetTexture(texture, 0); 505 image_dxgi->SetTexture(texture, 0);
501 506
502 ui::DCRendererLayerParams params( 507 ui::DCRendererLayerParams params(
503 false, gfx::Rect(), 1, gfx::Transform(), 508 false, gfx::Rect(), 1, gfx::Transform(),
504 std::vector<scoped_refptr<gl::GLImage>>{image_dxgi}, 509 std::vector<scoped_refptr<gl::GLImage>>{image_dxgi},
505 gfx::RectF(gfx::Rect(texture_size)), gfx::Rect(texture_size), 0, 0, 1.0, 510 gfx::RectF(gfx::Rect(texture_size)), gfx::Rect(texture_size), 0, 0, 1.0,
506 0); 511 0);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 SkColor expected_color = SkColorSetRGB(0xff, 0xb7, 0xff); 580 SkColor expected_color = SkColorSetRGB(0xff, 0xb7, 0xff);
576 SkColor actual_color = 581 SkColor actual_color =
577 ReadBackWindowPixel(window_.hwnd(), gfx::Point(75, 75)); 582 ReadBackWindowPixel(window_.hwnd(), gfx::Point(75, 75));
578 EXPECT_TRUE(AreColorsSimilar(expected_color, actual_color)) 583 EXPECT_TRUE(AreColorsSimilar(expected_color, actual_color))
579 << std::hex << "Expected " << expected_color << " Actual " 584 << std::hex << "Expected " << expected_color << " Actual "
580 << actual_color; 585 << actual_color;
581 586
582 context = nullptr; 587 context = nullptr;
583 DestroySurface(std::move(surface_)); 588 DestroySurface(std::move(surface_));
584 } 589 }
590
591 TEST_F(DirectCompositionPixelTest, VideoHandleSwapchain) {
592 if (!CheckIfDCSupported())
593 return;
594 InitializeSurface();
595 surface_->SetEnableDCLayers(true);
596 gfx::Size window_size(100, 100);
597
598 scoped_refptr<gl::GLContext> context = gl::init::CreateGLContext(
599 nullptr, surface_.get(), gl::GLContextAttribs());
600 EXPECT_TRUE(surface_->Resize(window_size, 1.0, true));
601
602 base::win::ScopedComPtr<ID3D11Device> d3d11_device =
603 gl::QueryD3D11DeviceObjectFromANGLE();
604
605 gfx::Size texture_size(50, 50);
606 base::win::ScopedComPtr<ID3D11Texture2D> texture =
607 CreateNV12Texture(d3d11_device, texture_size, true);
608 base::win::ScopedComPtr<IDXGIResource1> resource;
609 texture.CopyTo(resource.GetAddressOf());
610 HANDLE handle;
611 resource->CreateSharedHandle(nullptr, DXGI_SHARED_RESOURCE_READ, nullptr,
612 &handle);
613
614 scoped_refptr<gl::GLImageDXGIHandle> image_dxgi(new gl::GLImageDXGIHandle(
615 texture_size, base::win::ScopedHandle(handle), 0));
616 ASSERT_TRUE(image_dxgi->Initialize());
617
618 ui::DCRendererLayerParams params(
619 false, gfx::Rect(), 1, gfx::Transform(),
620 std::vector<scoped_refptr<gl::GLImage>>{image_dxgi},
621 gfx::RectF(gfx::Rect(texture_size)), gfx::Rect(window_size), 0, 0, 1.0,
622 0);
623 surface_->ScheduleDCLayer(params);
624
625 EXPECT_EQ(gfx::SwapResult::SWAP_ACK, surface_->SwapBuffers());
626
627 Sleep(1000);
628
629 SkColor expected_color = SkColorSetRGB(0xff, 0xb7, 0xff);
630 SkColor actual_color =
631 ReadBackWindowPixel(window_.hwnd(), gfx::Point(75, 75));
632 EXPECT_TRUE(AreColorsSimilar(expected_color, actual_color))
633 << std::hex << "Expected " << expected_color << " Actual "
634 << actual_color;
635
636 context = nullptr;
637 DestroySurface(std::move(surface_));
638 }
639
585 } // namespace 640 } // namespace
586 } // namespace gpu 641 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/ipc/service/direct_composition_surface_win.cc ('k') | media/gpu/dxva_picture_buffer_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698