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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
331 CreateDevice(); | 331 CreateDevice(); |
332 LoadEffects(); | 332 LoadEffects(); |
333 Resize(last_bounds_); | 333 Resize(last_bounds_); |
334 InitVertexLayout(); | 334 InitVertexLayout(); |
335 CreateVertexBuffer(); | 335 CreateVertexBuffer(); |
336 CreateIndexBuffer(); | 336 CreateIndexBuffer(); |
337 } | 337 } |
338 | 338 |
339 void CompositorWin::UpdatePerspective(const ui::Transform& transform, | 339 void CompositorWin::UpdatePerspective(const ui::Transform& transform, |
340 const gfx::Size& view_size) { | 340 const gfx::Size& view_size) { |
341 // Apply transform from view. | 341 float transform_data_buffer[16]; |
342 const SkMatrix& sk_matrix(transform.matrix()); | 342 transform.matrix().asColMajorf(transform_data_buffer); |
343 // Use -1 * kMTransY for y-translation as origin for views is upper left. | 343 D3DXMATRIX transform_matrix(&transform_data_buffer[0]); |
344 D3DXMATRIX transform_matrix( | 344 std::swap(transform_matrix._12,transform_matrix._21); |
sky
2011/06/24 20:58:19
nit: space after ',' on all these lines.
| |
345 // row 1 | 345 std::swap(transform_matrix._13,transform_matrix._31); |
346 sk_matrix[SkMatrix::kMScaleX], sk_matrix[SkMatrix::kMSkewX], 0.0f, | 346 std::swap(transform_matrix._23,transform_matrix._32); |
347 sk_matrix[SkMatrix::kMPersp0], | 347 |
348 // row 2 | 348 // Different coordinate system; flip the y. |
349 sk_matrix[SkMatrix::kMSkewY], sk_matrix[SkMatrix::kMScaleY], 0.0f, | 349 transform_matrix._42 *= -1; |
350 sk_matrix[SkMatrix::kMPersp1], | |
351 // row 3 | |
352 0.0f, 0.0f, 1.0f, sk_matrix[SkMatrix::kMPersp2], | |
353 // row 4. | |
354 sk_matrix[SkMatrix::kMTransX], -sk_matrix[SkMatrix::kMTransY], 0.0f, | |
355 1.0f); | |
356 | 350 |
357 // Scale so x and y are from 0-2. | 351 // Scale so x and y are from 0-2. |
358 D3DXMATRIX scale_matrix; | 352 D3DXMATRIX scale_matrix; |
359 D3DXMatrixScaling( | 353 D3DXMatrixScaling( |
360 &scale_matrix, | 354 &scale_matrix, |
361 2.0f / static_cast<float>(last_bounds_.width()), | 355 2.0f / static_cast<float>(last_bounds_.width()), |
362 2.0f / static_cast<float>(last_bounds_.height()), | 356 2.0f / static_cast<float>(last_bounds_.height()), |
363 1.0f); | 357 1.0f); |
364 | 358 |
365 // Translate so x and y are from -1,-1 to 1,1. | 359 // Translate so x and y are from -1,-1 to 1,1. |
366 D3DXMATRIX translate_matrix; | 360 D3DXMATRIX translate_matrix; |
367 D3DXMatrixTranslation(&translate_matrix, -1.0f, 1.0f, 0.0f); | 361 D3DXMatrixTranslation(&translate_matrix, -1.0f, 1.0f, 0.0f); |
368 | 362 |
369 D3DXMATRIX projection_matrix; | 363 D3DXMATRIX projection_matrix; |
370 D3DXMatrixIdentity(&projection_matrix); | 364 D3DXMatrixIdentity(&projection_matrix); |
371 D3DXMatrixPerspectiveFovLH(&projection_matrix, | 365 D3DXMatrixPerspectiveFovLH(&projection_matrix, |
372 atanf(.5f) * 2.0f, 1.0f, 1.0f, 1000.0f); | 366 atanf(.5f) * 2.0f, 1.0f, 1.0f, 1000.0f); |
373 D3DXVECTOR3 pos(0.0f, 0.0f, -2.0f); | 367 D3DXVECTOR3 pos(0.0f, 0.0f, -2.0f); |
374 D3DXVECTOR3 target(0.0f, 0.0f, 0.0f); | 368 D3DXVECTOR3 target(0.0f, 0.0f, 0.0f); |
375 D3DXVECTOR3 up(0.0f, 1.0f, 0.0f); | 369 D3DXVECTOR3 up(0.0f, 1.0f, 0.0f); |
376 D3DXMATRIX view; | 370 D3DXMATRIX view; |
377 D3DXMatrixIdentity(&view); | 371 D3DXMatrixIdentity(&view); |
378 D3DXMatrixLookAtLH(&view, &pos, &target, &up); | 372 D3DXMatrixLookAtLH(&view, &pos, &target, &up); |
379 | 373 |
380 D3DXMATRIX wvp = transform_matrix * scale_matrix * translate_matrix * view * | 374 D3DXMATRIX wvp = transform_matrix * scale_matrix * translate_matrix * view * |
381 projection_matrix; | 375 projection_matrix; |
376 | |
382 fx_->GetVariableByName("gWVP")->AsMatrix()->SetMatrix(wvp); | 377 fx_->GetVariableByName("gWVP")->AsMatrix()->SetMatrix(wvp); |
383 } | 378 } |
384 | 379 |
385 const gfx::Size& CompositorWin::GetHostSize() { | 380 const gfx::Size& CompositorWin::GetHostSize() { |
386 return last_bounds_.size(); | 381 return last_bounds_.size(); |
387 } | 382 } |
388 | 383 |
389 ID3D10Buffer* CompositorWin::GetTextureIndexBuffer() { | 384 ID3D10Buffer* CompositorWin::GetTextureIndexBuffer() { |
390 return index_buffer_.get(); | 385 return index_buffer_.get(); |
391 } | 386 } |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
818 } // namespace | 813 } // namespace |
819 | 814 |
820 // static | 815 // static |
821 Compositor* Compositor::Create(gfx::AcceleratedWidget widget) { | 816 Compositor* Compositor::Create(gfx::AcceleratedWidget widget) { |
822 CompositorWin* compositor = new CompositorWin(widget); | 817 CompositorWin* compositor = new CompositorWin(widget); |
823 compositor->Init(); | 818 compositor->Init(); |
824 return compositor; | 819 return compositor; |
825 } | 820 } |
826 | 821 |
827 } // namespace ui | 822 } // namespace ui |
OLD | NEW |