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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 ScopedComPtr<ID3D10Texture2D> texture_; | 79 ScopedComPtr<ID3D10Texture2D> texture_; |
80 ScopedComPtr<ID3D10ShaderResourceView> shader_view_; | 80 ScopedComPtr<ID3D10ShaderResourceView> shader_view_; |
81 ScopedComPtr<ID3D10Buffer> vertex_buffer_; | 81 ScopedComPtr<ID3D10Buffer> vertex_buffer_; |
82 | 82 |
83 DISALLOW_COPY_AND_ASSIGN(ViewTexture); | 83 DISALLOW_COPY_AND_ASSIGN(ViewTexture); |
84 }; | 84 }; |
85 | 85 |
86 // D3D 10 Compositor implementation. | 86 // D3D 10 Compositor implementation. |
87 class CompositorWin : public Compositor { | 87 class CompositorWin : public Compositor { |
88 public: | 88 public: |
89 CompositorWin(gfx::AcceleratedWidget widget, | 89 CompositorWin(CompositorDelegate* delegate, |
90 gfx::AcceleratedWidget widget, | |
90 const gfx::Size& size); | 91 const gfx::Size& size); |
91 | 92 |
92 void Init(); | 93 void Init(); |
93 | 94 |
94 // Invoked to update the perspective needed by this texture. |transform| is | 95 // Invoked to update the perspective needed by this texture. |transform| is |
95 // 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. |
96 void UpdatePerspective(const ui::Transform& transform, | 97 void UpdatePerspective(const ui::Transform& transform, |
97 const gfx::Size& view_size); | 98 const gfx::Size& view_size); |
98 | 99 |
99 // Returns the index buffer used for drawing a texture. | 100 // Returns the index buffer used for drawing a texture. |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 buffer_desc.ByteWidth = sizeof(Vertex) * ARRAYSIZE_UNSAFE(vertices); | 315 buffer_desc.ByteWidth = sizeof(Vertex) * ARRAYSIZE_UNSAFE(vertices); |
315 buffer_desc.BindFlags = D3D10_BIND_VERTEX_BUFFER; | 316 buffer_desc.BindFlags = D3D10_BIND_VERTEX_BUFFER; |
316 buffer_desc.CPUAccessFlags = 0; | 317 buffer_desc.CPUAccessFlags = 0; |
317 buffer_desc.MiscFlags = 0; | 318 buffer_desc.MiscFlags = 0; |
318 D3D10_SUBRESOURCE_DATA init_data; | 319 D3D10_SUBRESOURCE_DATA init_data; |
319 init_data.pSysMem = vertices; | 320 init_data.pSysMem = vertices; |
320 RETURN_IF_FAILED(device_->CreateBuffer(&buffer_desc, &init_data, | 321 RETURN_IF_FAILED(device_->CreateBuffer(&buffer_desc, &init_data, |
321 vertex_buffer_.Receive())); | 322 vertex_buffer_.Receive())); |
322 } | 323 } |
323 | 324 |
324 CompositorWin::CompositorWin(gfx::AcceleratedWidget widget, | 325 CompositorWin::CompositorWin(CompositorDelegate* delegate, |
326 gfx::AcceleratedWidget widget, | |
325 const gfx::Size& size) | 327 const gfx::Size& size) |
326 : Compositor(size), | 328 : Compositor(delegate, size), |
327 host_(widget), | 329 host_(widget), |
328 technique_(NULL) { | 330 technique_(NULL) { |
329 } | 331 } |
330 | 332 |
331 void CompositorWin::Init() { | 333 void CompositorWin::Init() { |
332 CreateDevice(); | 334 CreateDevice(); |
333 LoadEffects(); | 335 LoadEffects(); |
334 OnWidgetSizeChanged(); | 336 OnWidgetSizeChanged(); |
335 InitVertexLayout(); | 337 InitVertexLayout(); |
336 CreateVertexBuffer(); | 338 CreateVertexBuffer(); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
493 // A warning is generated if a bound vertexbuffer is deleted. To avoid that | 495 // A warning is generated if a bound vertexbuffer is deleted. To avoid that |
494 // warning we reset the buffer here. We only do it for debug builds as it's | 496 // warning we reset the buffer here. We only do it for debug builds as it's |
495 // ok to effectively unbind the vertex buffer. | 497 // ok to effectively unbind the vertex buffer. |
496 vertex_buffer = vertex_buffer_.get(); | 498 vertex_buffer = vertex_buffer_.get(); |
497 device_->IASetVertexBuffers(0, 1, &vertex_buffer, &stride, &offset); | 499 device_->IASetVertexBuffers(0, 1, &vertex_buffer, &stride, &offset); |
498 device_->IASetIndexBuffer(index_buffer_.get(), DXGI_FORMAT_R32_UINT, 0); | 500 device_->IASetIndexBuffer(index_buffer_.get(), DXGI_FORMAT_R32_UINT, 0); |
499 #endif | 501 #endif |
500 } | 502 } |
501 | 503 |
502 void CompositorWin::SchedulePaint() { | 504 void CompositorWin::SchedulePaint() { |
503 RECT bounds; | 505 delegate()->ScheduleCompositorPaint(); |
sky
2011/09/06 20:12:36
Both implementations are the same. Promote it to C
sadrul
2011/09/06 21:50:11
Done. (I added the implementation in compositor.h
| |
504 GetClientRect(host_, &bounds); | |
505 InvalidateRect(host_, &bounds, FALSE); | |
506 } | 506 } |
507 | 507 |
508 void CompositorWin::OnWidgetSizeChanged() { | 508 void CompositorWin::OnWidgetSizeChanged() { |
509 dest_render_target_view_ = NULL; | 509 dest_render_target_view_ = NULL; |
510 depth_stencil_buffer_ = NULL; | 510 depth_stencil_buffer_ = NULL; |
511 depth_stencil_view_ = NULL; | 511 depth_stencil_view_ = NULL; |
512 | 512 |
513 main_render_target_view_ = NULL; | 513 main_render_target_view_ = NULL; |
514 main_texture_ = NULL; | 514 main_texture_ = NULL; |
515 main_texture_shader_view_ = NULL; | 515 main_texture_shader_view_ = NULL; |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
789 if (error_code != S_OK) { | 789 if (error_code != S_OK) { |
790 Errored(error_code); | 790 Errored(error_code); |
791 return NULL; | 791 return NULL; |
792 } | 792 } |
793 return vertex_buffer; | 793 return vertex_buffer; |
794 } | 794 } |
795 | 795 |
796 } // namespace | 796 } // namespace |
797 | 797 |
798 // static | 798 // static |
799 Compositor* Compositor::Create(gfx::AcceleratedWidget widget, | 799 Compositor* Compositor::Create(CompositorDelegate* delegate, |
800 gfx::AcceleratedWidget widget, | |
800 const gfx::Size& size) { | 801 const gfx::Size& size) { |
801 CompositorWin* compositor = new CompositorWin(widget, size); | 802 CompositorWin* compositor = new CompositorWin(delegate, widget, size); |
802 compositor->Init(); | 803 compositor->Init(); |
803 return compositor; | 804 return compositor; |
804 } | 805 } |
805 | 806 |
806 } // namespace ui | 807 } // namespace ui |
OLD | NEW |