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

Side by Side Diff: ui/gfx/compositor/compositor_win.cc

Issue 7044062: Use SkMatrix44 for the underlying implementation of ui::Transform (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Gardening patch Created 9 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 | Annotate | Revision Log
« no previous file with comments | « ui/gfx/compositor/compositor_gl.cc ('k') | ui/gfx/compositor/layer_animator.h » ('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 (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 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 CreateDevice(); 332 CreateDevice();
333 LoadEffects(); 333 LoadEffects();
334 Resize(last_size_); 334 Resize(last_size_);
335 InitVertexLayout(); 335 InitVertexLayout();
336 CreateVertexBuffer(); 336 CreateVertexBuffer();
337 CreateIndexBuffer(); 337 CreateIndexBuffer();
338 } 338 }
339 339
340 void CompositorWin::UpdatePerspective(const ui::Transform& transform, 340 void CompositorWin::UpdatePerspective(const ui::Transform& transform,
341 const gfx::Size& view_size) { 341 const gfx::Size& view_size) {
342 // Apply transform from view. 342 float transform_data_buffer[16];
343 const SkMatrix& sk_matrix(transform.matrix()); 343 transform.matrix().asColMajorf(transform_data_buffer);
344 // Use -1 * kMTransY for y-translation as origin for views is upper left. 344 D3DXMATRIX transform_matrix(&transform_data_buffer[0]);
345 D3DXMATRIX transform_matrix( 345 std::swap(transform_matrix._12, transform_matrix._21);
346 // row 1 346 std::swap(transform_matrix._13, transform_matrix._31);
347 sk_matrix[SkMatrix::kMScaleX], sk_matrix[SkMatrix::kMSkewX], 0.0f, 347 std::swap(transform_matrix._23, transform_matrix._32);
348 sk_matrix[SkMatrix::kMPersp0], 348
349 // row 2 349 // Different coordinate system; flip the y.
350 sk_matrix[SkMatrix::kMSkewY], sk_matrix[SkMatrix::kMScaleY], 0.0f, 350 transform_matrix._42 *= -1;
351 sk_matrix[SkMatrix::kMPersp1],
352 // row 3
353 0.0f, 0.0f, 1.0f, sk_matrix[SkMatrix::kMPersp2],
354 // row 4.
355 sk_matrix[SkMatrix::kMTransX], -sk_matrix[SkMatrix::kMTransY], 0.0f,
356 1.0f);
357 351
358 // Scale so x and y are from 0-2. 352 // Scale so x and y are from 0-2.
359 D3DXMATRIX scale_matrix; 353 D3DXMATRIX scale_matrix;
360 D3DXMatrixScaling( 354 D3DXMatrixScaling(
361 &scale_matrix, 355 &scale_matrix,
362 2.0f / static_cast<float>(last_size_.width()), 356 2.0f / static_cast<float>(last_size_.width()),
363 2.0f / static_cast<float>(last_size_.height()), 357 2.0f / static_cast<float>(last_size_.height()),
364 1.0f); 358 1.0f);
365 359
366 // Translate so x and y are from -1,-1 to 1,1. 360 // Translate so x and y are from -1,-1 to 1,1.
367 D3DXMATRIX translate_matrix; 361 D3DXMATRIX translate_matrix;
368 D3DXMatrixTranslation(&translate_matrix, -1.0f, 1.0f, 0.0f); 362 D3DXMatrixTranslation(&translate_matrix, -1.0f, 1.0f, 0.0f);
369 363
370 D3DXMATRIX projection_matrix; 364 D3DXMATRIX projection_matrix;
371 D3DXMatrixIdentity(&projection_matrix); 365 D3DXMatrixIdentity(&projection_matrix);
372 D3DXMatrixPerspectiveFovLH(&projection_matrix, 366 D3DXMatrixPerspectiveFovLH(&projection_matrix,
373 atanf(.5f) * 2.0f, 1.0f, 1.0f, 1000.0f); 367 atanf(.5f) * 2.0f, 1.0f, 1.0f, 1000.0f);
374 D3DXVECTOR3 pos(0.0f, 0.0f, -2.0f); 368 D3DXVECTOR3 pos(0.0f, 0.0f, -2.0f);
375 D3DXVECTOR3 target(0.0f, 0.0f, 0.0f); 369 D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);
376 D3DXVECTOR3 up(0.0f, 1.0f, 0.0f); 370 D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
377 D3DXMATRIX view; 371 D3DXMATRIX view;
378 D3DXMatrixIdentity(&view); 372 D3DXMatrixIdentity(&view);
379 D3DXMatrixLookAtLH(&view, &pos, &target, &up); 373 D3DXMatrixLookAtLH(&view, &pos, &target, &up);
380 374
381 D3DXMATRIX wvp = transform_matrix * scale_matrix * translate_matrix * view * 375 D3DXMATRIX wvp = transform_matrix * scale_matrix * translate_matrix * view *
382 projection_matrix; 376 projection_matrix;
377
383 fx_->GetVariableByName("gWVP")->AsMatrix()->SetMatrix(wvp); 378 fx_->GetVariableByName("gWVP")->AsMatrix()->SetMatrix(wvp);
384 } 379 }
385 380
386 const gfx::Size& CompositorWin::GetHostSize() { 381 const gfx::Size& CompositorWin::GetHostSize() {
387 return last_size_; 382 return last_size_;
388 } 383 }
389 384
390 ID3D10Buffer* CompositorWin::GetTextureIndexBuffer() { 385 ID3D10Buffer* CompositorWin::GetTextureIndexBuffer() {
391 return index_buffer_.get(); 386 return index_buffer_.get();
392 } 387 }
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 807
813 // static 808 // static
814 Compositor* Compositor::Create(gfx::AcceleratedWidget widget, 809 Compositor* Compositor::Create(gfx::AcceleratedWidget widget,
815 const gfx::Size& size) { 810 const gfx::Size& size) {
816 CompositorWin* compositor = new CompositorWin(widget, size); 811 CompositorWin* compositor = new CompositorWin(widget, size);
817 compositor->Init(); 812 compositor->Init();
818 return compositor; 813 return compositor;
819 } 814 }
820 815
821 } // namespace ui 816 } // namespace ui
OLDNEW
« no previous file with comments | « ui/gfx/compositor/compositor_gl.cc ('k') | ui/gfx/compositor/layer_animator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698