Index: ui/gfx/compositor/compositor_win.cc |
diff --git a/ui/gfx/compositor/compositor_win.cc b/ui/gfx/compositor/compositor_win.cc |
index 3afb3c4109a7e68508de45b35fb2bc4cee153f53..346fd13ce13f334ea6d0d1f92f5fdc2ab3da7558 100644 |
--- a/ui/gfx/compositor/compositor_win.cc |
+++ b/ui/gfx/compositor/compositor_win.cc |
@@ -56,7 +56,6 @@ class ViewTexture : public Texture { |
const gfx::Point& origin, |
const gfx::Size& overall_size) OVERRIDE; |
virtual void Draw(const ui::TextureDrawParams& params) OVERRIDE; |
- |
virtual void Draw(const ui::TextureDrawParams& params, |
const gfx::Rect& clip_bounds_in_texture) OVERRIDE; |
@@ -97,9 +96,6 @@ class CompositorWin : public Compositor { |
void UpdatePerspective(const ui::Transform& transform, |
const gfx::Size& view_size); |
- // Returns the overall size of the compositor. |
- const gfx::Size& GetHostSize(); |
- |
// Returns the index buffer used for drawing a texture. |
ID3D10Buffer* GetTextureIndexBuffer(); |
@@ -109,7 +105,9 @@ class CompositorWin : public Compositor { |
virtual void NotifyEnd() OVERRIDE; |
virtual void Blur(const gfx::Rect& bounds) OVERRIDE; |
virtual void SchedulePaint() OVERRIDE; |
- virtual void OnWidgetSizeChanged(const gfx::Size& size) OVERRIDE; |
+ |
+ protected: |
+ virtual void OnWidgetSizeChanged() OVERRIDE; |
private: |
enum Direction { |
@@ -127,8 +125,6 @@ class CompositorWin : public Compositor { |
void InitVertexLayout(); |
- void Resize(const gfx::Size& size); |
- |
// Updates the kernel used for blurring. Size is the size of the texture |
// being drawn to along the appropriate axis. |
void UpdateBlurKernel(Direction direction, int size); |
@@ -151,9 +147,6 @@ class CompositorWin : public Compositor { |
gfx::AcceleratedWidget host_; |
- // Size the device was last created at. |
- gfx::Size last_size_; |
- |
ScopedComPtr<ID3D10Device> device_; |
ScopedComPtr<IDXGISwapChain> swap_chain_; |
ScopedComPtr<ID3D10RenderTargetView> dest_render_target_view_; |
@@ -305,7 +298,7 @@ void ViewTexture::ConvertBitmapToD3DData( |
void ViewTexture::CreateVertexBuffer(const gfx::Size& size) { |
vertex_buffer_.Release(); |
- const gfx::Size& host_size = compositor_->GetHostSize(); |
+ const gfx::Size& host_size = compositor_->size(); |
float x = static_cast<float>(host_size.width()) / 2.0f; |
float y = static_cast<float>(host_size.height()) / 2.0f; |
float w = static_cast<float>(size.width()); |
@@ -332,15 +325,15 @@ void ViewTexture::CreateVertexBuffer(const gfx::Size& size) { |
CompositorWin::CompositorWin(gfx::AcceleratedWidget widget, |
const gfx::Size& size) |
- : host_(widget), |
- technique_(NULL), |
- last_size_(size) { |
+ : Compositor(size), |
+ host_(widget), |
+ technique_(NULL) { |
} |
void CompositorWin::Init() { |
CreateDevice(); |
LoadEffects(); |
- Resize(last_size_); |
+ OnWidgetSizeChanged(); |
InitVertexLayout(); |
CreateVertexBuffer(); |
CreateIndexBuffer(); |
@@ -362,8 +355,8 @@ void CompositorWin::UpdatePerspective(const ui::Transform& transform, |
D3DXMATRIX scale_matrix; |
D3DXMatrixScaling( |
&scale_matrix, |
- 2.0f / static_cast<float>(last_size_.width()), |
- 2.0f / static_cast<float>(last_size_.height()), |
+ 2.0f / static_cast<float>(size().width()), |
+ 2.0f / static_cast<float>(size().height()), |
1.0f); |
// Translate so x and y are from -1,-1 to 1,1. |
@@ -387,10 +380,6 @@ void CompositorWin::UpdatePerspective(const ui::Transform& transform, |
fx_->GetVariableByName("gWVP")->AsMatrix()->SetMatrix(wvp); |
} |
-const gfx::Size& CompositorWin::GetHostSize() { |
- return last_size_; |
-} |
- |
ID3D10Buffer* CompositorWin::GetTextureIndexBuffer() { |
return index_buffer_.get(); |
} |
@@ -469,7 +458,7 @@ void CompositorWin::Blur(const gfx::Rect& bounds) { |
D3DXMatrixIdentity(&identity_matrix); |
// Horizontal blur from the main texture to blur texture. |
- UpdateBlurKernel(HORIZONTAL, last_size_.width()); |
+ UpdateBlurKernel(HORIZONTAL, size().width()); |
ID3D10RenderTargetView* target_view = blur_render_target_view_.get(); |
device_->OMSetRenderTargets(1, &target_view, NULL); |
RETURN_IF_FAILED( |
@@ -495,7 +484,7 @@ void CompositorWin::Blur(const gfx::Rect& bounds) { |
RETURN_IF_FAILED( |
blur_fx_->GetVariableByName("textureMap")->AsShaderResource()-> |
SetResource(blur_texture_shader_view_.get())); |
- UpdateBlurKernel(VERTICAL, last_size_.height()); |
+ UpdateBlurKernel(VERTICAL, size().height()); |
target_view = main_render_target_view_.get(); |
device_->OMSetRenderTargets(1, &target_view, NULL); |
for(UINT p = 0; p < tech_desc.Passes; ++p) |
@@ -518,8 +507,69 @@ void CompositorWin::SchedulePaint() { |
InvalidateRect(host_, &bounds, FALSE); |
} |
-void CompositorWin::OnWidgetSizeChanged(const gfx::Size& size) { |
- Resize(size); |
+void CompositorWin::OnWidgetSizeChanged() { |
+ dest_render_target_view_ = NULL; |
+ depth_stencil_buffer_ = NULL; |
+ depth_stencil_view_ = NULL; |
+ |
+ main_render_target_view_ = NULL; |
+ main_texture_ = NULL; |
+ main_texture_shader_view_ = NULL; |
+ |
+ blur_render_target_view_ = NULL; |
+ blur_texture_ = NULL; |
+ blur_texture_shader_view_ = NULL; |
+ |
+ CreateTexture(size(), main_texture_.Receive(), |
+ main_render_target_view_.Receive(), |
+ main_texture_shader_view_.Receive()); |
+ |
+ CreateTexture(size(), blur_texture_.Receive(), |
+ blur_render_target_view_.Receive(), |
+ blur_texture_shader_view_.Receive()); |
+ |
+ // Resize the swap chain and recreate the render target view. |
+ RETURN_IF_FAILED(swap_chain_->ResizeBuffers( |
+ 1, size().width(), size().height(), DXGI_FORMAT_R8G8B8A8_UNORM, 0)); |
+ ScopedComPtr<ID3D10Texture2D> back_buffer; |
+ RETURN_IF_FAILED(swap_chain_->GetBuffer( |
+ 0, __uuidof(ID3D10Texture2D), |
+ reinterpret_cast<void**>(back_buffer.Receive()))); |
+ RETURN_IF_FAILED(device_->CreateRenderTargetView( |
+ back_buffer.get(), 0, |
+ dest_render_target_view_.Receive())); |
+ |
+ // Create the depth/stencil buffer and view. |
+ D3D10_TEXTURE2D_DESC depth_stencil_desc; |
+ depth_stencil_desc.Width = size().width(); |
+ depth_stencil_desc.Height = size().height(); |
+ depth_stencil_desc.MipLevels = 1; |
+ depth_stencil_desc.ArraySize = 1; |
+ depth_stencil_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; |
+ depth_stencil_desc.SampleDesc.Count = 1; // multisampling must match |
+ depth_stencil_desc.SampleDesc.Quality = 0; // swap chain values. |
+ depth_stencil_desc.Usage = D3D10_USAGE_DEFAULT; |
+ depth_stencil_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL; |
+ depth_stencil_desc.CPUAccessFlags = 0; |
+ depth_stencil_desc.MiscFlags = 0; |
+ |
+ RETURN_IF_FAILED(device_->CreateTexture2D(&depth_stencil_desc, 0, |
+ depth_stencil_buffer_.Receive())); |
+ RETURN_IF_FAILED(device_->CreateDepthStencilView( |
+ depth_stencil_buffer_.get(), 0, |
+ depth_stencil_view_.Receive())); |
+ |
+ |
+ // Set the viewport transform. |
+ D3D10_VIEWPORT vp; |
+ vp.TopLeftX = 0; |
+ vp.TopLeftY = 0; |
+ vp.Width = size().width(); |
+ vp.Height = size().height(); |
+ vp.MinDepth = 0.0f; |
+ vp.MaxDepth = 1.0f; |
+ |
+ device_->RSSetViewports(1, &vp); |
} |
CompositorWin::~CompositorWin() { |
@@ -532,8 +582,8 @@ void CompositorWin::Errored(HRESULT error_code) { |
void CompositorWin::CreateDevice() { |
DXGI_SWAP_CHAIN_DESC sd; |
- sd.BufferDesc.Width = last_size_.width(); |
- sd.BufferDesc.Height = last_size_.height(); |
+ sd.BufferDesc.Width = size().width(); |
+ sd.BufferDesc.Height = size().height(); |
sd.BufferDesc.RefreshRate.Numerator = 60; |
sd.BufferDesc.RefreshRate.Denominator = 1; |
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; |
@@ -616,73 +666,6 @@ void CompositorWin::InitVertexLayout() { |
vertex_layout_.Receive())); |
} |
-void CompositorWin::Resize(const gfx::Size& size) { |
- last_size_ = size; |
- |
- dest_render_target_view_ = NULL; |
- depth_stencil_buffer_ = NULL; |
- depth_stencil_view_ = NULL; |
- |
- main_render_target_view_ = NULL; |
- main_texture_ = NULL; |
- main_texture_shader_view_ = NULL; |
- |
- blur_render_target_view_ = NULL; |
- blur_texture_ = NULL; |
- blur_texture_shader_view_ = NULL; |
- |
- CreateTexture(size, main_texture_.Receive(), |
- main_render_target_view_.Receive(), |
- main_texture_shader_view_.Receive()); |
- |
- CreateTexture(size, blur_texture_.Receive(), |
- blur_render_target_view_.Receive(), |
- blur_texture_shader_view_.Receive()); |
- |
- // Resize the swap chain and recreate the render target view. |
- RETURN_IF_FAILED(swap_chain_->ResizeBuffers( |
- 1, size.width(), size.height(), DXGI_FORMAT_R8G8B8A8_UNORM, 0)); |
- ScopedComPtr<ID3D10Texture2D> back_buffer; |
- RETURN_IF_FAILED(swap_chain_->GetBuffer( |
- 0, __uuidof(ID3D10Texture2D), |
- reinterpret_cast<void**>(back_buffer.Receive()))); |
- RETURN_IF_FAILED(device_->CreateRenderTargetView( |
- back_buffer.get(), 0, |
- dest_render_target_view_.Receive())); |
- |
- // Create the depth/stencil buffer and view. |
- D3D10_TEXTURE2D_DESC depth_stencil_desc; |
- depth_stencil_desc.Width = size.width(); |
- depth_stencil_desc.Height = size.height(); |
- depth_stencil_desc.MipLevels = 1; |
- depth_stencil_desc.ArraySize = 1; |
- depth_stencil_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; |
- depth_stencil_desc.SampleDesc.Count = 1; // multisampling must match |
- depth_stencil_desc.SampleDesc.Quality = 0; // swap chain values. |
- depth_stencil_desc.Usage = D3D10_USAGE_DEFAULT; |
- depth_stencil_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL; |
- depth_stencil_desc.CPUAccessFlags = 0; |
- depth_stencil_desc.MiscFlags = 0; |
- |
- RETURN_IF_FAILED(device_->CreateTexture2D(&depth_stencil_desc, 0, |
- depth_stencil_buffer_.Receive())); |
- RETURN_IF_FAILED(device_->CreateDepthStencilView( |
- depth_stencil_buffer_.get(), 0, |
- depth_stencil_view_.Receive())); |
- |
- |
- // Set the viewport transform. |
- D3D10_VIEWPORT vp; |
- vp.TopLeftX = 0; |
- vp.TopLeftY = 0; |
- vp.Width = size.width(); |
- vp.Height = size.height(); |
- vp.MinDepth = 0.0f; |
- vp.MaxDepth = 1.0f; |
- |
- device_->RSSetViewports(1, &vp); |
-} |
- |
void CompositorWin::UpdateBlurKernel(Direction direction, int size) { |
// Update the blur data. |
const int kSize = 13; |
@@ -773,14 +756,14 @@ void CompositorWin::CreateIndexBuffer() { |
ID3D10Buffer* CompositorWin::CreateVertexBufferForRegion( |
const gfx::Rect& bounds) { |
float x = static_cast<float>(bounds.x()) / |
- static_cast<float>(last_size_.width()) * 2.0f - 1.0f; |
+ static_cast<float>(size().width()) * 2.0f - 1.0f; |
float max_x = |
- x + bounds.width() / static_cast<float>(last_size_.width()) * 2.0f; |
+ x + bounds.width() / static_cast<float>(size().width()) * 2.0f; |
float y = |
- static_cast<float>(last_size_.height() - bounds.y() - bounds.height()) / |
- static_cast<float>(last_size_.height()) * 2.0f - 1.0f; |
+ static_cast<float>(size().height() - bounds.y() - bounds.height()) / |
+ static_cast<float>(size().height()) * 2.0f - 1.0f; |
float max_y = |
- y + bounds.height() / static_cast<float>(last_size_.height()) * 2.0f; |
+ y + bounds.height() / static_cast<float>(size().height()) * 2.0f; |
float tex_x = x / 2.0f + .5f; |
float max_tex_x = max_x / 2.0f + .5f; |
float tex_y = 1.0f - (max_y + 1.0f) / 2.0f; |