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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 CompositorWin(gfx::AcceleratedWidget widget, | 90 CompositorWin(gfx::AcceleratedWidget widget, |
91 const gfx::Size& size); | 91 const gfx::Size& size); |
92 | 92 |
93 void Init(); | 93 void Init(); |
94 | 94 |
95 // Invoked to update the perspective needed by this texture. |transform| is | 95 // Invoked to update the perspective needed by this texture. |transform| is |
96 // the transform for the texture, and |size| the size of the texture. | 96 // the transform for the texture, and |size| the size of the texture. |
97 void UpdatePerspective(const ui::Transform& transform, | 97 void UpdatePerspective(const ui::Transform& transform, |
98 const gfx::Size& view_size); | 98 const gfx::Size& view_size); |
99 | 99 |
100 // Returns the overall size of the compositor. | |
101 const gfx::Size& GetHostSize(); | |
102 | |
103 // Returns the index buffer used for drawing a texture. | 100 // Returns the index buffer used for drawing a texture. |
104 ID3D10Buffer* GetTextureIndexBuffer(); | 101 ID3D10Buffer* GetTextureIndexBuffer(); |
105 | 102 |
106 // Compositor: | 103 // Compositor: |
107 virtual Texture* CreateTexture() OVERRIDE; | 104 virtual Texture* CreateTexture() OVERRIDE; |
108 virtual void NotifyStart() OVERRIDE; | 105 virtual void NotifyStart() OVERRIDE; |
109 virtual void NotifyEnd() OVERRIDE; | 106 virtual void NotifyEnd() OVERRIDE; |
110 virtual void Blur(const gfx::Rect& bounds) OVERRIDE; | 107 virtual void Blur(const gfx::Rect& bounds) OVERRIDE; |
111 virtual void SchedulePaint() OVERRIDE; | 108 virtual void SchedulePaint() OVERRIDE; |
112 virtual void OnWidgetSizeChanged(const gfx::Size& size) OVERRIDE; | 109 virtual void OnWidgetSizeChanged(const gfx::Size& size) OVERRIDE; |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
298 (SkColorGetA(color) << 24) | | 295 (SkColorGetA(color) << 24) | |
299 (SkColorGetB(color) << 16) | | 296 (SkColorGetB(color) << 16) | |
300 (SkColorGetG(color) << 8) | | 297 (SkColorGetG(color) << 8) | |
301 (SkColorGetR(color)); | 298 (SkColorGetR(color)); |
302 } | 299 } |
303 } | 300 } |
304 } | 301 } |
305 | 302 |
306 void ViewTexture::CreateVertexBuffer(const gfx::Size& size) { | 303 void ViewTexture::CreateVertexBuffer(const gfx::Size& size) { |
307 vertex_buffer_.Release(); | 304 vertex_buffer_.Release(); |
308 const gfx::Size& host_size = compositor_->GetHostSize(); | 305 const gfx::Size& host_size = compositor_->size(); |
309 float x = static_cast<float>(host_size.width()) / 2.0f; | 306 float x = static_cast<float>(host_size.width()) / 2.0f; |
310 float y = static_cast<float>(host_size.height()) / 2.0f; | 307 float y = static_cast<float>(host_size.height()) / 2.0f; |
311 float w = static_cast<float>(size.width()); | 308 float w = static_cast<float>(size.width()); |
312 float h = static_cast<float>(size.height()); | 309 float h = static_cast<float>(size.height()); |
313 Vertex vertices[] = { | 310 Vertex vertices[] = { |
314 { D3DXVECTOR3(0.0f, -h, 0.0f), D3DXVECTOR2(0.0f, 1.0f) }, | 311 { D3DXVECTOR3(0.0f, -h, 0.0f), D3DXVECTOR2(0.0f, 1.0f) }, |
315 { D3DXVECTOR3(0.0f, 0.0f, 0.0f), D3DXVECTOR2(0.0f, 0.0f) }, | 312 { D3DXVECTOR3(0.0f, 0.0f, 0.0f), D3DXVECTOR2(0.0f, 0.0f) }, |
316 { D3DXVECTOR3( w, 0.0f, 0.0f), D3DXVECTOR2(1.0f, 0.0f) }, | 313 { D3DXVECTOR3( w, 0.0f, 0.0f), D3DXVECTOR2(1.0f, 0.0f) }, |
317 { D3DXVECTOR3( w, -h, 0.0f), D3DXVECTOR2(1.0f, 1.0f) }, | 314 { D3DXVECTOR3( w, -h, 0.0f), D3DXVECTOR2(1.0f, 1.0f) }, |
318 }; | 315 }; |
319 | 316 |
320 // Create the vertex buffer containing the points. | 317 // Create the vertex buffer containing the points. |
321 D3D10_BUFFER_DESC buffer_desc; | 318 D3D10_BUFFER_DESC buffer_desc; |
322 buffer_desc.Usage = D3D10_USAGE_IMMUTABLE; | 319 buffer_desc.Usage = D3D10_USAGE_IMMUTABLE; |
323 buffer_desc.ByteWidth = sizeof(Vertex) * ARRAYSIZE_UNSAFE(vertices); | 320 buffer_desc.ByteWidth = sizeof(Vertex) * ARRAYSIZE_UNSAFE(vertices); |
324 buffer_desc.BindFlags = D3D10_BIND_VERTEX_BUFFER; | 321 buffer_desc.BindFlags = D3D10_BIND_VERTEX_BUFFER; |
325 buffer_desc.CPUAccessFlags = 0; | 322 buffer_desc.CPUAccessFlags = 0; |
326 buffer_desc.MiscFlags = 0; | 323 buffer_desc.MiscFlags = 0; |
327 D3D10_SUBRESOURCE_DATA init_data; | 324 D3D10_SUBRESOURCE_DATA init_data; |
328 init_data.pSysMem = vertices; | 325 init_data.pSysMem = vertices; |
329 RETURN_IF_FAILED(device_->CreateBuffer(&buffer_desc, &init_data, | 326 RETURN_IF_FAILED(device_->CreateBuffer(&buffer_desc, &init_data, |
330 vertex_buffer_.Receive())); | 327 vertex_buffer_.Receive())); |
331 } | 328 } |
332 | 329 |
333 CompositorWin::CompositorWin(gfx::AcceleratedWidget widget, | 330 CompositorWin::CompositorWin(gfx::AcceleratedWidget widget, |
334 const gfx::Size& size) | 331 const gfx::Size& size) |
335 : host_(widget), | 332 : Compositor(size), |
336 technique_(NULL), | 333 host_(widget), |
337 last_size_(size) { | 334 technique_(NULL) { |
338 } | 335 } |
339 | 336 |
340 void CompositorWin::Init() { | 337 void CompositorWin::Init() { |
341 CreateDevice(); | 338 CreateDevice(); |
342 LoadEffects(); | 339 LoadEffects(); |
343 Resize(last_size_); | 340 Resize(size()); |
344 InitVertexLayout(); | 341 InitVertexLayout(); |
345 CreateVertexBuffer(); | 342 CreateVertexBuffer(); |
346 CreateIndexBuffer(); | 343 CreateIndexBuffer(); |
347 } | 344 } |
348 | 345 |
349 void CompositorWin::UpdatePerspective(const ui::Transform& transform, | 346 void CompositorWin::UpdatePerspective(const ui::Transform& transform, |
350 const gfx::Size& view_size) { | 347 const gfx::Size& view_size) { |
351 float transform_data_buffer[16]; | 348 float transform_data_buffer[16]; |
352 transform.matrix().asColMajorf(transform_data_buffer); | 349 transform.matrix().asColMajorf(transform_data_buffer); |
353 D3DXMATRIX transform_matrix(&transform_data_buffer[0]); | 350 D3DXMATRIX transform_matrix(&transform_data_buffer[0]); |
(...skipping 26 matching lines...) Expand all Loading... | |
380 D3DXMATRIX view; | 377 D3DXMATRIX view; |
381 D3DXMatrixIdentity(&view); | 378 D3DXMatrixIdentity(&view); |
382 D3DXMatrixLookAtLH(&view, &pos, &target, &up); | 379 D3DXMatrixLookAtLH(&view, &pos, &target, &up); |
383 | 380 |
384 D3DXMATRIX wvp = transform_matrix * scale_matrix * translate_matrix * view * | 381 D3DXMATRIX wvp = transform_matrix * scale_matrix * translate_matrix * view * |
385 projection_matrix; | 382 projection_matrix; |
386 | 383 |
387 fx_->GetVariableByName("gWVP")->AsMatrix()->SetMatrix(wvp); | 384 fx_->GetVariableByName("gWVP")->AsMatrix()->SetMatrix(wvp); |
388 } | 385 } |
389 | 386 |
390 const gfx::Size& CompositorWin::GetHostSize() { | |
391 return last_size_; | |
sky
2011/08/24 21:17:08
I don't think you wired up changing the size corre
jonathan.backer
2011/08/25 18:57:18
Done.
| |
392 } | |
393 | |
394 ID3D10Buffer* CompositorWin::GetTextureIndexBuffer() { | 387 ID3D10Buffer* CompositorWin::GetTextureIndexBuffer() { |
395 return index_buffer_.get(); | 388 return index_buffer_.get(); |
396 } | 389 } |
397 | 390 |
398 Texture* CompositorWin::CreateTexture() { | 391 Texture* CompositorWin::CreateTexture() { |
399 return new ViewTexture(this, device_.get(), fx_.get()); | 392 return new ViewTexture(this, device_.get(), fx_.get()); |
400 } | 393 } |
401 | 394 |
402 void CompositorWin::NotifyStart() { | 395 void CompositorWin::NotifyStart() { |
403 ID3D10RenderTargetView* target_view = main_render_target_view_.get(); | 396 ID3D10RenderTargetView* target_view = main_render_target_view_.get(); |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
816 | 809 |
817 // static | 810 // static |
818 Compositor* Compositor::Create(gfx::AcceleratedWidget widget, | 811 Compositor* Compositor::Create(gfx::AcceleratedWidget widget, |
819 const gfx::Size& size) { | 812 const gfx::Size& size) { |
820 CompositorWin* compositor = new CompositorWin(widget, size); | 813 CompositorWin* compositor = new CompositorWin(widget, size); |
821 compositor->Init(); | 814 compositor->Init(); |
822 return compositor; | 815 return compositor; |
823 } | 816 } |
824 | 817 |
825 } // namespace ui | 818 } // namespace ui |
OLD | NEW |