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. |
100 ID3D10Buffer* GetTextureIndexBuffer(); | 101 ID3D10Buffer* GetTextureIndexBuffer(); |
101 | 102 |
102 // Compositor: | 103 // Compositor: |
103 virtual Texture* CreateTexture() OVERRIDE; | 104 virtual Texture* CreateTexture() OVERRIDE; |
104 virtual void NotifyStart() OVERRIDE; | 105 virtual void NotifyStart() OVERRIDE; |
105 virtual void NotifyEnd() OVERRIDE; | 106 virtual void NotifyEnd() OVERRIDE; |
106 virtual void Blur(const gfx::Rect& bounds) OVERRIDE; | 107 virtual void Blur(const gfx::Rect& bounds) OVERRIDE; |
107 virtual void SchedulePaint() OVERRIDE; | |
108 | 108 |
109 protected: | 109 protected: |
110 virtual void OnWidgetSizeChanged() OVERRIDE; | 110 virtual void OnWidgetSizeChanged() OVERRIDE; |
111 | 111 |
112 private: | 112 private: |
113 enum Direction { | 113 enum Direction { |
114 HORIZONTAL, | 114 HORIZONTAL, |
115 VERTICAL | 115 VERTICAL |
116 }; | 116 }; |
117 | 117 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 buffer_desc.ByteWidth = sizeof(Vertex) * ARRAYSIZE_UNSAFE(vertices); | 314 buffer_desc.ByteWidth = sizeof(Vertex) * ARRAYSIZE_UNSAFE(vertices); |
315 buffer_desc.BindFlags = D3D10_BIND_VERTEX_BUFFER; | 315 buffer_desc.BindFlags = D3D10_BIND_VERTEX_BUFFER; |
316 buffer_desc.CPUAccessFlags = 0; | 316 buffer_desc.CPUAccessFlags = 0; |
317 buffer_desc.MiscFlags = 0; | 317 buffer_desc.MiscFlags = 0; |
318 D3D10_SUBRESOURCE_DATA init_data; | 318 D3D10_SUBRESOURCE_DATA init_data; |
319 init_data.pSysMem = vertices; | 319 init_data.pSysMem = vertices; |
320 RETURN_IF_FAILED(device_->CreateBuffer(&buffer_desc, &init_data, | 320 RETURN_IF_FAILED(device_->CreateBuffer(&buffer_desc, &init_data, |
321 vertex_buffer_.Receive())); | 321 vertex_buffer_.Receive())); |
322 } | 322 } |
323 | 323 |
324 CompositorWin::CompositorWin(gfx::AcceleratedWidget widget, | 324 CompositorWin::CompositorWin(CompositorDelegate* delegate, |
| 325 gfx::AcceleratedWidget widget, |
325 const gfx::Size& size) | 326 const gfx::Size& size) |
326 : Compositor(size), | 327 : Compositor(delegate, size), |
327 host_(widget), | 328 host_(widget), |
328 technique_(NULL) { | 329 technique_(NULL) { |
329 } | 330 } |
330 | 331 |
331 void CompositorWin::Init() { | 332 void CompositorWin::Init() { |
332 CreateDevice(); | 333 CreateDevice(); |
333 LoadEffects(); | 334 LoadEffects(); |
334 OnWidgetSizeChanged(); | 335 OnWidgetSizeChanged(); |
335 InitVertexLayout(); | 336 InitVertexLayout(); |
336 CreateVertexBuffer(); | 337 CreateVertexBuffer(); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 #if !defined(NDEBUG) | 493 #if !defined(NDEBUG) |
493 // A warning is generated if a bound vertexbuffer is deleted. To avoid that | 494 // 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 | 495 // warning we reset the buffer here. We only do it for debug builds as it's |
495 // ok to effectively unbind the vertex buffer. | 496 // ok to effectively unbind the vertex buffer. |
496 vertex_buffer = vertex_buffer_.get(); | 497 vertex_buffer = vertex_buffer_.get(); |
497 device_->IASetVertexBuffers(0, 1, &vertex_buffer, &stride, &offset); | 498 device_->IASetVertexBuffers(0, 1, &vertex_buffer, &stride, &offset); |
498 device_->IASetIndexBuffer(index_buffer_.get(), DXGI_FORMAT_R32_UINT, 0); | 499 device_->IASetIndexBuffer(index_buffer_.get(), DXGI_FORMAT_R32_UINT, 0); |
499 #endif | 500 #endif |
500 } | 501 } |
501 | 502 |
502 void CompositorWin::SchedulePaint() { | |
503 RECT bounds; | |
504 GetClientRect(host_, &bounds); | |
505 InvalidateRect(host_, &bounds, FALSE); | |
506 } | |
507 | |
508 void CompositorWin::OnWidgetSizeChanged() { | 503 void CompositorWin::OnWidgetSizeChanged() { |
509 dest_render_target_view_ = NULL; | 504 dest_render_target_view_ = NULL; |
510 depth_stencil_buffer_ = NULL; | 505 depth_stencil_buffer_ = NULL; |
511 depth_stencil_view_ = NULL; | 506 depth_stencil_view_ = NULL; |
512 | 507 |
513 main_render_target_view_ = NULL; | 508 main_render_target_view_ = NULL; |
514 main_texture_ = NULL; | 509 main_texture_ = NULL; |
515 main_texture_shader_view_ = NULL; | 510 main_texture_shader_view_ = NULL; |
516 | 511 |
517 blur_render_target_view_ = NULL; | 512 blur_render_target_view_ = NULL; |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 if (error_code != S_OK) { | 784 if (error_code != S_OK) { |
790 Errored(error_code); | 785 Errored(error_code); |
791 return NULL; | 786 return NULL; |
792 } | 787 } |
793 return vertex_buffer; | 788 return vertex_buffer; |
794 } | 789 } |
795 | 790 |
796 } // namespace | 791 } // namespace |
797 | 792 |
798 // static | 793 // static |
799 Compositor* Compositor::Create(gfx::AcceleratedWidget widget, | 794 Compositor* Compositor::Create(CompositorDelegate* delegate, |
| 795 gfx::AcceleratedWidget widget, |
800 const gfx::Size& size) { | 796 const gfx::Size& size) { |
801 CompositorWin* compositor = new CompositorWin(widget, size); | 797 CompositorWin* compositor = new CompositorWin(delegate, widget, size); |
802 compositor->Init(); | 798 compositor->Init(); |
803 return compositor; | 799 return compositor; |
804 } | 800 } |
805 | 801 |
806 } // namespace ui | 802 } // namespace ui |
OLD | NEW |