OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "ui/gfx/compositor/compositor.h" | 5 #include "ui/gfx/compositor/compositor.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <d3dx10.h> | 8 #include <d3dx10.h> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 CreateDevice(); | 343 CreateDevice(); |
344 LoadEffects(); | 344 LoadEffects(); |
345 Resize(last_bounds_); | 345 Resize(last_bounds_); |
346 InitVertexLayout(); | 346 InitVertexLayout(); |
347 CreateVertexBuffer(); | 347 CreateVertexBuffer(); |
348 CreateIndexBuffer(); | 348 CreateIndexBuffer(); |
349 } | 349 } |
350 | 350 |
351 void CompositorWin::UpdatePerspective(const ui::Transform& transform, | 351 void CompositorWin::UpdatePerspective(const ui::Transform& transform, |
352 const gfx::Size& view_size) { | 352 const gfx::Size& view_size) { |
353 // Apply transform from view. | |
354 const SkMatrix& sk_matrix(transform.matrix()); | |
355 // Use -1 * kMTransY for y-translation as origin for views is upper left. | 353 // Use -1 * kMTransY for y-translation as origin for views is upper left. |
356 D3DXMATRIX transform_matrix( | 354 float transform_data_buffer[16]; |
357 // row 1 | 355 transform.matrix().asRowMajorf((transform_data_buffer); |
358 sk_matrix[SkMatrix::kMScaleX], sk_matrix[SkMatrix::kMSkewX], 0.0f, | 356 D3DXMATRIX transform_matrix(&transform_data_buffer[0]); |
359 sk_matrix[SkMatrix::kMPersp0], | |
360 // row 2 | |
361 sk_matrix[SkMatrix::kMSkewY], sk_matrix[SkMatrix::kMScaleY], 0.0f, | |
362 sk_matrix[SkMatrix::kMPersp1], | |
363 // row 3 | |
364 0.0f, 0.0f, 1.0f, sk_matrix[SkMatrix::kMPersp2], | |
365 // row 4. | |
366 sk_matrix[SkMatrix::kMTransX], -sk_matrix[SkMatrix::kMTransY], 0.0f, | |
367 1.0f); | |
368 | 357 |
369 // Scale so x and y are from 0-2. | 358 // Scale so x and y are from 0-2. |
370 D3DXMATRIX scale_matrix; | 359 D3DXMATRIX scale_matrix; |
371 D3DXMatrixScaling( | 360 D3DXMatrixScaling( |
372 &scale_matrix, | 361 &scale_matrix, |
373 2.0f / static_cast<float>(last_bounds_.width()), | 362 2.0f / static_cast<float>(last_bounds_.width()), |
374 2.0f / static_cast<float>(last_bounds_.height()), | 363 2.0f / static_cast<float>(last_bounds_.height()), |
375 1.0f); | 364 1.0f); |
376 | 365 |
377 // Translate so x and y are from -1,-1 to 1,1. | 366 // Translate so x and y are from -1,-1 to 1,1. |
378 D3DXMATRIX translate_matrix; | 367 D3DXMATRIX translate_matrix; |
379 D3DXMatrixTranslation(&translate_matrix, -1.0f, 1.0f, 0.0f); | 368 D3DXMatrixTranslation(&translate_matrix, -1.0f, 1.0f, 0.0f); |
380 | 369 |
381 D3DXMATRIX projection_matrix; | 370 D3DXMATRIX projection_matrix; |
382 D3DXMatrixIdentity(&projection_matrix); | 371 D3DXMatrixIdentity(&projection_matrix); |
383 D3DXMatrixPerspectiveFovLH(&projection_matrix, | 372 D3DXMatrixPerspectiveFovLH(&projection_matrix, |
384 atanf(.5f) * 2.0f, 1.0f, 1.0f, 1000.0f); | 373 atanf(.5f) * 2.0f, 1.0f, 1.0f, 1000.0f); |
385 D3DXVECTOR3 pos(0.0f, 0.0f, -2.0f); | 374 D3DXVECTOR3 pos(0.0f, 0.0f, -2.0f); |
386 D3DXVECTOR3 target(0.0f, 0.0f, 0.0f); | 375 D3DXVECTOR3 target(0.0f, 0.0f, 0.0f); |
387 D3DXVECTOR3 up(0.0f, 1.0f, 0.0f); | 376 D3DXVECTOR3 up(0.0f, 1.0f, 0.0f); |
388 D3DXMATRIX view; | 377 D3DXMATRIX view; |
389 D3DXMatrixIdentity(&view); | 378 D3DXMatrixIdentity(&view); |
390 D3DXMatrixLookAtLH(&view, &pos, &target, &up); | 379 D3DXMatrixLookAtLH(&view, &pos, &target, &up); |
391 | 380 |
392 D3DXMATRIX wvp = transform_matrix * scale_matrix * translate_matrix * view * | 381 D3DXMATRIX wvp = transform_matrix * scale_matrix * translate_matrix * view * |
393 projection_matrix; | 382 projection_matrix; |
| 383 |
394 fx_->GetVariableByName("gWVP")->AsMatrix()->SetMatrix(wvp); | 384 fx_->GetVariableByName("gWVP")->AsMatrix()->SetMatrix(wvp); |
395 } | 385 } |
396 | 386 |
397 const gfx::Size& CompositorWin::GetHostSize() { | 387 const gfx::Size& CompositorWin::GetHostSize() { |
398 return last_bounds_.size(); | 388 return last_bounds_.size(); |
399 } | 389 } |
400 | 390 |
401 ID3D10Buffer* CompositorWin::GetTextureIndexBuffer() { | 391 ID3D10Buffer* CompositorWin::GetTextureIndexBuffer() { |
402 return index_buffer_.get(); | 392 return index_buffer_.get(); |
403 } | 393 } |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 } // namespace | 814 } // namespace |
825 | 815 |
826 // static | 816 // static |
827 Compositor* Compositor::Create(gfx::AcceleratedWidget widget) { | 817 Compositor* Compositor::Create(gfx::AcceleratedWidget widget) { |
828 CompositorWin* compositor = new CompositorWin(widget); | 818 CompositorWin* compositor = new CompositorWin(widget); |
829 compositor->Init(); | 819 compositor->Init(); |
830 return compositor; | 820 return compositor; |
831 } | 821 } |
832 | 822 |
833 } // namespace ui | 823 } // namespace ui |
OLD | NEW |