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

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

Issue 2981713002: Revert of Allow presenting DXGI share handles as overlays. (Closed)
Patch Set: 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) {
116 D3D11_TEXTURE2D_DESC desc = {}; 115 D3D11_TEXTURE2D_DESC desc = {};
117 desc.Width = size.width(); 116 desc.Width = size.width();
118 desc.Height = size.height(); 117 desc.Height = size.height();
119 desc.MipLevels = 1; 118 desc.MipLevels = 1;
120 desc.ArraySize = 1; 119 desc.ArraySize = 1;
121 desc.Format = DXGI_FORMAT_NV12; 120 desc.Format = DXGI_FORMAT_NV12;
122 desc.Usage = D3D11_USAGE_DEFAULT; 121 desc.Usage = D3D11_USAGE_DEFAULT;
123 desc.SampleDesc.Count = 1; 122 desc.SampleDesc.Count = 1;
124 desc.BindFlags = 0; 123 desc.BindFlags = 0;
125 if (shared) {
126 desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX |
127 D3D11_RESOURCE_MISC_SHARED_NTHANDLE;
128 }
129 124
130 std::vector<char> image_data(size.width() * size.height() * 3 / 2); 125 std::vector<char> image_data(size.width() * size.height() * 3 / 2);
131 // Y, U, and V should all be Oxff. Output color should be pink. 126 // Y, U, and V should all be Oxff. Output color should be pink.
132 memset(&image_data[0], 0xff, size.width() * size.height() * 3 / 2); 127 memset(&image_data[0], 0xff, size.width() * size.height() * 3 / 2);
133 128
134 D3D11_SUBRESOURCE_DATA data = {}; 129 D3D11_SUBRESOURCE_DATA data = {};
135 data.pSysMem = (const void*)&image_data[0]; 130 data.pSysMem = (const void*)&image_data[0];
136 data.SysMemPitch = size.width(); 131 data.SysMemPitch = size.width();
137 132
138 base::win::ScopedComPtr<ID3D11Texture2D> texture; 133 base::win::ScopedComPtr<ID3D11Texture2D> texture;
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 gfx::Size window_size(100, 100); 310 gfx::Size window_size(100, 100);
316 311
317 scoped_refptr<gl::GLContext> context = 312 scoped_refptr<gl::GLContext> context =
318 gl::init::CreateGLContext(nullptr, surface.get(), gl::GLContextAttribs()); 313 gl::init::CreateGLContext(nullptr, surface.get(), gl::GLContextAttribs());
319 314
320 base::win::ScopedComPtr<ID3D11Device> d3d11_device = 315 base::win::ScopedComPtr<ID3D11Device> d3d11_device =
321 gl::QueryD3D11DeviceObjectFromANGLE(); 316 gl::QueryD3D11DeviceObjectFromANGLE();
322 317
323 gfx::Size texture_size(50, 50); 318 gfx::Size texture_size(50, 50);
324 base::win::ScopedComPtr<ID3D11Texture2D> texture = 319 base::win::ScopedComPtr<ID3D11Texture2D> texture =
325 CreateNV12Texture(d3d11_device, texture_size, false); 320 CreateNV12Texture(d3d11_device, texture_size);
326 321
327 scoped_refptr<gl::GLImageDXGI> image_dxgi( 322 scoped_refptr<gl::GLImageDXGI> image_dxgi(
328 new gl::GLImageDXGI(texture_size, nullptr)); 323 new gl::GLImageDXGI(texture_size, nullptr));
329 image_dxgi->SetTexture(texture, 0); 324 image_dxgi->SetTexture(texture, 0);
330 325
331 ui::DCRendererLayerParams params( 326 ui::DCRendererLayerParams params(
332 false, gfx::Rect(), 1, gfx::Transform(), 327 false, gfx::Rect(), 1, gfx::Transform(),
333 std::vector<scoped_refptr<gl::GLImage>>{image_dxgi}, 328 std::vector<scoped_refptr<gl::GLImage>>{image_dxgi},
334 gfx::RectF(gfx::Rect(texture_size)), gfx::Rect(window_size), 0, 0, 1.0, 329 gfx::RectF(gfx::Rect(texture_size)), gfx::Rect(window_size), 0, 0, 1.0,
335 0); 330 0);
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 486
492 scoped_refptr<gl::GLContext> context = gl::init::CreateGLContext( 487 scoped_refptr<gl::GLContext> context = gl::init::CreateGLContext(
493 nullptr, surface_.get(), gl::GLContextAttribs()); 488 nullptr, surface_.get(), gl::GLContextAttribs());
494 EXPECT_TRUE(surface_->Resize(window_size, 1.0, true)); 489 EXPECT_TRUE(surface_->Resize(window_size, 1.0, true));
495 490
496 base::win::ScopedComPtr<ID3D11Device> d3d11_device = 491 base::win::ScopedComPtr<ID3D11Device> d3d11_device =
497 gl::QueryD3D11DeviceObjectFromANGLE(); 492 gl::QueryD3D11DeviceObjectFromANGLE();
498 493
499 gfx::Size texture_size(50, 50); 494 gfx::Size texture_size(50, 50);
500 base::win::ScopedComPtr<ID3D11Texture2D> texture = 495 base::win::ScopedComPtr<ID3D11Texture2D> texture =
501 CreateNV12Texture(d3d11_device, texture_size, false); 496 CreateNV12Texture(d3d11_device, texture_size);
502 497
503 scoped_refptr<gl::GLImageDXGI> image_dxgi( 498 scoped_refptr<gl::GLImageDXGI> image_dxgi(
504 new gl::GLImageDXGI(texture_size, nullptr)); 499 new gl::GLImageDXGI(texture_size, nullptr));
505 image_dxgi->SetTexture(texture, 0); 500 image_dxgi->SetTexture(texture, 0);
506 501
507 ui::DCRendererLayerParams params( 502 ui::DCRendererLayerParams params(
508 false, gfx::Rect(), 1, gfx::Transform(), 503 false, gfx::Rect(), 1, gfx::Transform(),
509 std::vector<scoped_refptr<gl::GLImage>>{image_dxgi}, 504 std::vector<scoped_refptr<gl::GLImage>>{image_dxgi},
510 gfx::RectF(gfx::Rect(texture_size)), gfx::Rect(texture_size), 0, 0, 1.0, 505 gfx::RectF(gfx::Rect(texture_size)), gfx::Rect(texture_size), 0, 0, 1.0,
511 0); 506 0);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 SkColor expected_color = SkColorSetRGB(0xff, 0xb7, 0xff); 575 SkColor expected_color = SkColorSetRGB(0xff, 0xb7, 0xff);
581 SkColor actual_color = 576 SkColor actual_color =
582 ReadBackWindowPixel(window_.hwnd(), gfx::Point(75, 75)); 577 ReadBackWindowPixel(window_.hwnd(), gfx::Point(75, 75));
583 EXPECT_TRUE(AreColorsSimilar(expected_color, actual_color)) 578 EXPECT_TRUE(AreColorsSimilar(expected_color, actual_color))
584 << std::hex << "Expected " << expected_color << " Actual " 579 << std::hex << "Expected " << expected_color << " Actual "
585 << actual_color; 580 << actual_color;
586 581
587 context = nullptr; 582 context = nullptr;
588 DestroySurface(std::move(surface_)); 583 DestroySurface(std::move(surface_));
589 } 584 }
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
640 } // namespace 585 } // namespace
641 } // namespace gpu 586 } // 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