| 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_transformer_win.h" | 5 #include "ui/surface/accelerated_surface_transformer_win.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "accelerated_surface_transformer_win_hlsl_compiled.h" | 9 #include "accelerated_surface_transformer_win_hlsl_compiled.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 private: | 62 private: |
| 63 ScopedComPtr<IDirect3DDevice9> device_; | 63 ScopedComPtr<IDirect3DDevice9> device_; |
| 64 int target_id_; | 64 int target_id_; |
| 65 ScopedComPtr<IDirect3DSurface9> original_render_target_; | 65 ScopedComPtr<IDirect3DSurface9> original_render_target_; |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 // Calculate the number necessary to transform |src_subrect| into |dst_size| | 68 // Calculate the number necessary to transform |src_subrect| into |dst_size| |
| 69 // by repeating downsampling of the image of |src_subrect| by a factor no more | 69 // by repeating downsampling of the image of |src_subrect| by a factor no more |
| 70 // than 2. | 70 // than 2. |
| 71 int GetResampleCount(const gfx::Rect& src_subrect, | 71 int GetResampleCount(const gfx::Rect& src_subrect, |
| 72 const gfx::Size& dst_size, | 72 const gfx::Size& dst_size) { |
| 73 const gfx::Size& back_buffer_size) { | |
| 74 // At least one copy is required, since the back buffer itself is not | 73 // At least one copy is required, since the back buffer itself is not |
| 75 // lockable. | 74 // lockable. |
| 76 int min_resample_count = 1; | 75 int min_resample_count = 1; |
| 77 int width_count = 0; | 76 int width_count = 0; |
| 78 int width = src_subrect.width(); | 77 int width = src_subrect.width(); |
| 79 while (width > dst_size.width()) { | 78 while (width > dst_size.width()) { |
| 80 ++width_count; | 79 ++width_count; |
| 81 width >>= 1; | 80 width >>= 1; |
| 82 } | 81 } |
| 83 int height_count = 0; | 82 int height_count = 0; |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 vertices, | 311 vertices, |
| 313 sizeof(vertices[0])); | 312 sizeof(vertices[0])); |
| 314 device()->EndScene(); | 313 device()->EndScene(); |
| 315 | 314 |
| 316 } | 315 } |
| 317 | 316 |
| 318 // Resize an RGB surface using repeated linear interpolation. | 317 // Resize an RGB surface using repeated linear interpolation. |
| 319 bool AcceleratedSurfaceTransformer::ResizeBilinear( | 318 bool AcceleratedSurfaceTransformer::ResizeBilinear( |
| 320 IDirect3DSurface9* src_surface, | 319 IDirect3DSurface9* src_surface, |
| 321 const gfx::Rect& src_subrect, | 320 const gfx::Rect& src_subrect, |
| 322 IDirect3DSurface9* dst_surface) { | 321 IDirect3DSurface9* dst_surface, |
| 323 gfx::Size src_size = d3d_utils::GetSize(src_surface); | 322 const gfx::Rect& dst_rect) { |
| 324 gfx::Size dst_size = d3d_utils::GetSize(dst_surface); | 323 gfx::Size src_size = src_subrect.size(); |
| 324 gfx::Size dst_size = dst_rect.size(); |
| 325 | 325 |
| 326 if (src_size.IsEmpty() || dst_size.IsEmpty()) | 326 if (src_size.IsEmpty() || dst_size.IsEmpty()) |
| 327 return false; | 327 return false; |
| 328 | 328 |
| 329 HRESULT hr = S_OK; | 329 HRESULT hr = S_OK; |
| 330 // Set up intermediate buffers needed for downsampling. | 330 // Set up intermediate buffers needed for downsampling. |
| 331 const int resample_count = | 331 const int resample_count = GetResampleCount(src_subrect, dst_size); |
| 332 GetResampleCount(src_subrect, dst_size, src_size); | |
| 333 base::win::ScopedComPtr<IDirect3DSurface9> temp_buffer[2]; | 332 base::win::ScopedComPtr<IDirect3DSurface9> temp_buffer[2]; |
| 334 const gfx::Size half_size = | 333 const gfx::Size half_size = |
| 335 GetHalfSizeNoLessThan(src_subrect.size(), dst_size); | 334 GetHalfSizeNoLessThan(src_subrect.size(), dst_size); |
| 336 if (resample_count > 1) { | 335 if (resample_count > 1) { |
| 337 TRACE_EVENT0("gpu", "CreateTemporarySurface"); | 336 TRACE_EVENT0("gpu", "CreateTemporarySurface"); |
| 338 if (!d3d_utils::CreateTemporaryLockableSurface(device(), | 337 if (!d3d_utils::CreateTemporaryLockableSurface(device(), |
| 339 half_size, | 338 half_size, |
| 340 temp_buffer[0].Receive())) | 339 temp_buffer[0].Receive())) |
| 341 return false; | 340 return false; |
| 342 } | 341 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 353 // |dst_size|. We keep the factor of each downsampling no more than two | 352 // |dst_size|. We keep the factor of each downsampling no more than two |
| 354 // because using a factor more than two can introduce aliasing. | 353 // because using a factor more than two can introduce aliasing. |
| 355 RECT read_rect = src_subrect.ToRECT(); | 354 RECT read_rect = src_subrect.ToRECT(); |
| 356 gfx::Size write_size = half_size; | 355 gfx::Size write_size = half_size; |
| 357 int read_buffer_index = 1; | 356 int read_buffer_index = 1; |
| 358 int write_buffer_index = 0; | 357 int write_buffer_index = 0; |
| 359 for (int i = 0; i < resample_count; ++i) { | 358 for (int i = 0; i < resample_count; ++i) { |
| 360 TRACE_EVENT0("gpu", "StretchRect"); | 359 TRACE_EVENT0("gpu", "StretchRect"); |
| 361 IDirect3DSurface9* read_buffer = | 360 IDirect3DSurface9* read_buffer = |
| 362 (i == 0) ? src_surface : temp_buffer[read_buffer_index]; | 361 (i == 0) ? src_surface : temp_buffer[read_buffer_index]; |
| 363 IDirect3DSurface9* write_buffer = | 362 IDirect3DSurface9* write_buffer; |
| 364 (i == resample_count - 1) ? dst_surface : | 363 RECT write_rect; |
| 365 temp_buffer[write_buffer_index]; | 364 if (i == resample_count - 1) { |
| 366 RECT write_rect = gfx::Rect(write_size).ToRECT(); | 365 write_buffer = dst_surface; |
| 366 write_rect = dst_rect.ToRECT(); |
| 367 } else { |
| 368 write_buffer = temp_buffer[write_buffer_index]; |
| 369 write_rect = gfx::Rect(write_size).ToRECT(); |
| 370 } |
| 371 |
| 367 hr = device()->StretchRect(read_buffer, | 372 hr = device()->StretchRect(read_buffer, |
| 368 &read_rect, | 373 &read_rect, |
| 369 write_buffer, | 374 write_buffer, |
| 370 &write_rect, | 375 &write_rect, |
| 371 D3DTEXF_LINEAR); | 376 D3DTEXF_LINEAR); |
| 372 | 377 |
| 373 if (FAILED(hr)) | 378 if (FAILED(hr)) |
| 374 return false; | 379 return false; |
| 375 read_rect = write_rect; | 380 read_rect = write_rect; |
| 376 write_size = GetHalfSizeNoLessThan(write_size, dst_size); | 381 write_size = GetHalfSizeNoLessThan(write_size, dst_size); |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 return false; | 592 return false; |
| 588 | 593 |
| 589 HRESULT hr = device()->SetVertexShader(vertex_shaders_[combo]); | 594 HRESULT hr = device()->SetVertexShader(vertex_shaders_[combo]); |
| 590 if (!SUCCEEDED(hr)) | 595 if (!SUCCEEDED(hr)) |
| 591 return false; | 596 return false; |
| 592 hr = device()->SetPixelShader(pixel_shaders_[combo]); | 597 hr = device()->SetPixelShader(pixel_shaders_[combo]); |
| 593 if (!SUCCEEDED(hr)) | 598 if (!SUCCEEDED(hr)) |
| 594 return false; | 599 return false; |
| 595 return true; | 600 return true; |
| 596 } | 601 } |
| OLD | NEW |