OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/surface/accelerated_surface_win.h" | 5 #include "ui/surface/accelerated_surface_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 namespace { | 31 namespace { |
32 | 32 |
33 typedef HRESULT (WINAPI *Direct3DCreate9ExFunc)(UINT sdk_version, | 33 typedef HRESULT (WINAPI *Direct3DCreate9ExFunc)(UINT sdk_version, |
34 IDirect3D9Ex **d3d); | 34 IDirect3D9Ex **d3d); |
35 | 35 |
36 const wchar_t kD3D9ModuleName[] = L"d3d9.dll"; | 36 const wchar_t kD3D9ModuleName[] = L"d3d9.dll"; |
37 const char kCreate3D9DeviceExName[] = "Direct3DCreate9Ex"; | 37 const char kCreate3D9DeviceExName[] = "Direct3DCreate9Ex"; |
38 | 38 |
39 const char kGpuBlitDelay[] = "gpu-blit-delay"; | 39 const char kGpuBlitDelay[] = "gpu-blit-delay"; |
| 40 const char kUseOcclusionQuery[] = "use-occlusion-query"; |
40 | 41 |
41 struct Vertex { | 42 struct Vertex { |
42 float x, y, z, w; | 43 float x, y, z, w; |
43 float u, v; | 44 float u, v; |
44 }; | 45 }; |
45 | 46 |
46 // See accelerated_surface_win.hlsl for source and compilation instructions. | 47 // See accelerated_surface_win.hlsl for source and compilation instructions. |
47 const BYTE g_vertexMain[] = { | 48 const BYTE g_vertexMain[] = { |
48 0, 2, 254, 255, 254, 255, | 49 0, 2, 254, 255, 254, 255, |
49 22, 0, 67, 84, 65, 66, | 50 22, 0, 67, 84, 65, 66, |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 D3DDECL_END() | 114 D3DDECL_END() |
114 }; | 115 }; |
115 | 116 |
116 UINT GetPresentationInterval() { | 117 UINT GetPresentationInterval() { |
117 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableGpuVsync)) | 118 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableGpuVsync)) |
118 return D3DPRESENT_INTERVAL_IMMEDIATE; | 119 return D3DPRESENT_INTERVAL_IMMEDIATE; |
119 else | 120 else |
120 return D3DPRESENT_INTERVAL_ONE; | 121 return D3DPRESENT_INTERVAL_ONE; |
121 } | 122 } |
122 | 123 |
| 124 bool UsingOcclusionQuery() { |
| 125 return CommandLine::ForCurrentProcess()->HasSwitch(kUseOcclusionQuery); |
| 126 } |
| 127 |
123 // Calculate the number necessary to transform |src_subrect| into |dst_size| | 128 // Calculate the number necessary to transform |src_subrect| into |dst_size| |
124 // by repeating downsampling of the image of |src_subrect| by a factor no more | 129 // by repeating downsampling of the image of |src_subrect| by a factor no more |
125 // than 2. | 130 // than 2. |
126 int GetResampleCount(const gfx::Rect& src_subrect, | 131 int GetResampleCount(const gfx::Rect& src_subrect, |
127 const gfx::Size& dst_size, | 132 const gfx::Size& dst_size, |
128 const gfx::Size& back_buffer_size) { | 133 const gfx::Size& back_buffer_size) { |
129 if (src_subrect.size() == dst_size) { | 134 if (src_subrect.size() == dst_size) { |
130 // Even when the size of |src_subrect| is equal to |dst_size|, it is | 135 // Even when the size of |src_subrect| is equal to |dst_size|, it is |
131 // necessary to resample pixels at least once unless |src_subrect| exactly | 136 // necessary to resample pixels at least once unless |src_subrect| exactly |
132 // covers the back buffer. | 137 // covers the back buffer. |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 D3DDEVTYPE_HAL, | 295 D3DDEVTYPE_HAL, |
291 window, | 296 window, |
292 D3DCREATE_FPU_PRESERVE | D3DCREATE_SOFTWARE_VERTEXPROCESSING | | 297 D3DCREATE_FPU_PRESERVE | D3DCREATE_SOFTWARE_VERTEXPROCESSING | |
293 D3DCREATE_DISABLE_PSGP_THREADING | D3DCREATE_MULTITHREADED, | 298 D3DCREATE_DISABLE_PSGP_THREADING | D3DCREATE_MULTITHREADED, |
294 ¶meters, | 299 ¶meters, |
295 NULL, | 300 NULL, |
296 device_.Receive()); | 301 device_.Receive()); |
297 if (FAILED(hr)) | 302 if (FAILED(hr)) |
298 return; | 303 return; |
299 | 304 |
300 hr = device_->CreateQuery(D3DQUERYTYPE_EVENT, query_.Receive()); | 305 if (UsingOcclusionQuery()) { |
301 if (FAILED(hr)) { | 306 hr = device_->CreateQuery(D3DQUERYTYPE_OCCLUSION, query_.Receive()); |
302 device_ = NULL; | 307 if (FAILED(hr)) { |
303 return; | 308 device_ = NULL; |
| 309 return; |
| 310 } |
| 311 } else { |
| 312 hr = device_->CreateQuery(D3DQUERYTYPE_EVENT, query_.Receive()); |
| 313 if (FAILED(hr)) { |
| 314 device_ = NULL; |
| 315 return; |
| 316 } |
304 } | 317 } |
305 | 318 |
306 base::win::ScopedComPtr<IDirect3DVertexShader9> vertex_shader; | 319 base::win::ScopedComPtr<IDirect3DVertexShader9> vertex_shader; |
307 hr = device_->CreateVertexShader(reinterpret_cast<const DWORD*>(g_vertexMain), | 320 hr = device_->CreateVertexShader(reinterpret_cast<const DWORD*>(g_vertexMain), |
308 vertex_shader.Receive()); | 321 vertex_shader.Receive()); |
309 if (FAILED(hr)) { | 322 if (FAILED(hr)) { |
310 device_ = NULL; | 323 device_ = NULL; |
311 query_ = NULL; | 324 query_ = NULL; |
312 return; | 325 return; |
313 } | 326 } |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 | 807 |
795 float halfPixelX = -1.0f / size.width(); | 808 float halfPixelX = -1.0f / size.width(); |
796 float halfPixelY = 1.0f / size.height(); | 809 float halfPixelY = 1.0f / size.height(); |
797 Vertex vertices[] = { | 810 Vertex vertices[] = { |
798 { halfPixelX - 1, halfPixelY + 1, 0.5f, 1, 0, 1 }, | 811 { halfPixelX - 1, halfPixelY + 1, 0.5f, 1, 0, 1 }, |
799 { halfPixelX + 1, halfPixelY + 1, 0.5f, 1, 1, 1 }, | 812 { halfPixelX + 1, halfPixelY + 1, 0.5f, 1, 1, 1 }, |
800 { halfPixelX + 1, halfPixelY - 1, 0.5f, 1, 1, 0 }, | 813 { halfPixelX + 1, halfPixelY - 1, 0.5f, 1, 1, 0 }, |
801 { halfPixelX - 1, halfPixelY - 1, 0.5f, 1, 0, 0 } | 814 { halfPixelX - 1, halfPixelY - 1, 0.5f, 1, 0, 0 } |
802 }; | 815 }; |
803 | 816 |
| 817 if (UsingOcclusionQuery()) { |
| 818 present_thread_->query()->Issue(D3DISSUE_BEGIN); |
| 819 } |
| 820 |
804 present_thread_->device()->BeginScene(); | 821 present_thread_->device()->BeginScene(); |
805 present_thread_->device()->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, | 822 present_thread_->device()->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, |
806 arraysize(vertices), | 823 arraysize(vertices), |
807 vertices, | 824 vertices, |
808 sizeof(vertices[0])); | 825 sizeof(vertices[0])); |
809 present_thread_->device()->EndScene(); | 826 present_thread_->device()->EndScene(); |
810 | 827 |
811 present_thread_->device()->SetTexture(0, NULL); | 828 present_thread_->device()->SetTexture(0, NULL); |
812 present_thread_->device()->SetRenderTarget(0, default_render_target); | 829 present_thread_->device()->SetRenderTarget(0, default_render_target); |
813 default_render_target->Release(); | 830 default_render_target->Release(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
879 return presenter_->CopyTo(src_subrect, dst_size, buf); | 896 return presenter_->CopyTo(src_subrect, dst_size, buf); |
880 } | 897 } |
881 | 898 |
882 void AcceleratedSurface::Suspend() { | 899 void AcceleratedSurface::Suspend() { |
883 presenter_->Suspend(); | 900 presenter_->Suspend(); |
884 } | 901 } |
885 | 902 |
886 void AcceleratedSurface::WasHidden() { | 903 void AcceleratedSurface::WasHidden() { |
887 presenter_->WasHidden(); | 904 presenter_->WasHidden(); |
888 } | 905 } |
OLD | NEW |