summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorbacker@chromium.org <backer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-23 16:52:12 +0000
committerbacker@chromium.org <backer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-23 16:52:12 +0000
commit51f1b4848440040ef8e41b26dd92d176ca803b1a (patch)
treee06e9c9e114b5615feeb27f4f4927a1fd09fdc80 /ui
parenta7488a134b0b011c8724ccca6d6f16a549a561e0 (diff)
downloadchromium_src-51f1b4848440040ef8e41b26dd92d176ca803b1a.zip
chromium_src-51f1b4848440040ef8e41b26dd92d176ca803b1a.tar.gz
chromium_src-51f1b4848440040ef8e41b26dd92d176ca803b1a.tar.bz2
Ref count the browser compositor textures.
This is in preparation of having the browser compositor display textures generated by the GPU process. BUG=none TEST=none Review URL: http://codereview.chromium.org/7232016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@90222 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/gfx/compositor/compositor.h10
-rw-r--r--ui/gfx/compositor/compositor_gl.cc6
-rw-r--r--ui/gfx/compositor/compositor_win.cc247
-rw-r--r--ui/gfx/compositor/layer.h4
4 files changed, 130 insertions, 137 deletions
diff --git a/ui/gfx/compositor/compositor.h b/ui/gfx/compositor/compositor.h
index 749d272..bc7b1e1 100644
--- a/ui/gfx/compositor/compositor.h
+++ b/ui/gfx/compositor/compositor.h
@@ -27,10 +27,8 @@ class Transform;
// the bitmap.
//
// Views own the Texture.
-class Texture {
+class Texture : public base::RefCounted<Texture> {
public:
- virtual ~Texture() {}
-
// Sets the bitmap of this texture. The bitmaps origin is at |origin|.
// |overall_size| gives the total size of texture.
virtual void SetBitmap(const SkBitmap& bitmap,
@@ -39,6 +37,12 @@ class Texture {
// Draws the texture.
virtual void Draw(const ui::Transform& transform) = 0;
+
+ protected:
+ virtual ~Texture() {}
+
+ private:
+ friend class base::RefCounted<Texture>;
};
// Compositor object to take care of GPU painting.
diff --git a/ui/gfx/compositor/compositor_gl.cc b/ui/gfx/compositor/compositor_gl.cc
index 00895bc..ce45efe 100644
--- a/ui/gfx/compositor/compositor_gl.cc
+++ b/ui/gfx/compositor/compositor_gl.cc
@@ -31,7 +31,6 @@ class CompositorGL;
class TextureGL : public Texture {
public:
TextureGL(CompositorGL* compositor);
- virtual ~TextureGL();
virtual void SetBitmap(const SkBitmap& bitmap,
const gfx::Point& origin,
@@ -40,10 +39,13 @@ class TextureGL : public Texture {
// Draws the texture.
virtual void Draw(const ui::Transform& transform) OVERRIDE;
+ protected:
+ virtual ~TextureGL();
+
private:
unsigned int texture_id_;
gfx::Size size_;
- CompositorGL* compositor_;
+ scoped_refptr <CompositorGL> compositor_;
DISALLOW_COPY_AND_ASSIGN(TextureGL);
};
diff --git a/ui/gfx/compositor/compositor_win.cc b/ui/gfx/compositor/compositor_win.cc
index 90a4680..e3ca2a2 100644
--- a/ui/gfx/compositor/compositor_win.cc
+++ b/ui/gfx/compositor/compositor_win.cc
@@ -34,25 +34,7 @@ namespace ui {
namespace {
-class ViewTexture;
-
-// ViewTexture talks to its host by way of this interface.
-class ViewTextureHost {
- public:
- // Invoked to update the perspective needed by this texture. |transform| is
- // the transform for the texture, and |size| the size of the texture.
- virtual void UpdatePerspective(const ui::Transform& transform,
- const gfx::Size& size) = 0;
-
- // Returns the overall size of the compositor.
- virtual const gfx::Size& GetHostSize() = 0;
-
- // Returns the index buffer used for drawing a texture.
- virtual ID3D10Buffer* GetTextureIndexBuffer() = 0;
-
- protected:
- virtual ~ViewTextureHost() {}
-};
+class CompositorWin;
// Vertex structure used by the compositor.
struct Vertex {
@@ -65,12 +47,10 @@ struct Vertex {
// matching that of |SetBitmap|.
class ViewTexture : public Texture {
public:
- ViewTexture(ViewTextureHost* host,
+ ViewTexture(CompositorWin* compositor,
ID3D10Device* device,
ID3D10Effect* effect);
- ~ViewTexture();
-
// Texture:
virtual void SetBitmap(const SkBitmap& bitmap,
const gfx::Point& origin,
@@ -78,6 +58,8 @@ class ViewTexture : public Texture {
virtual void Draw(const ui::Transform& transform) OVERRIDE;
private:
+ ~ViewTexture();
+
void Errored(HRESULT result);
void ConvertBitmapToD3DData(const SkBitmap& bitmap,
@@ -85,7 +67,7 @@ class ViewTexture : public Texture {
void CreateVertexBuffer(const gfx::Size& size);
- ViewTextureHost* host_;
+ scoped_refptr<CompositorWin> compositor_;
// Size of the corresponding View.
gfx::Size view_size_;
@@ -99,10 +81,117 @@ class ViewTexture : public Texture {
DISALLOW_COPY_AND_ASSIGN(ViewTexture);
};
-ViewTexture::ViewTexture(ViewTextureHost* host,
+// D3D 10 Compositor implementation.
+class CompositorWin : public Compositor {
+ public:
+ explicit CompositorWin(gfx::AcceleratedWidget widget);
+
+ void Init();
+
+ // Invoked to update the perspective needed by this texture. |transform| is
+ // the transform for the texture, and |size| the size of the texture.
+ 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();
+
+ // Compositor:
+ virtual Texture* CreateTexture() OVERRIDE;
+ virtual void NotifyStart() OVERRIDE;
+ virtual void NotifyEnd() OVERRIDE;
+ virtual void Blur(const gfx::Rect& bounds) OVERRIDE;
+ virtual void SchedulePaint() OVERRIDE;
+
+ private:
+ enum Direction {
+ HORIZONTAL,
+ VERTICAL
+ };
+
+ ~CompositorWin();
+
+ void Errored(HRESULT error_code);
+
+ // Returns the bounds of the hosting window.
+ gfx::Rect HostBounds();
+
+ void CreateDevice();
+
+ void LoadEffects();
+
+ void InitVertexLayout();
+
+ void Resize(const gfx::Rect& bounds);
+
+ // 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);
+
+ // Creates a texture, render target view and shader.
+ void CreateTexture(const gfx::Size& size,
+ ID3D10Texture2D** texture,
+ ID3D10RenderTargetView** render_target_view,
+ ID3D10ShaderResourceView** shader_resource_view);
+
+ // Creates |vertex_buffer_|.
+ void CreateVertexBuffer();
+
+ // Creates |index_buffer_|.
+ void CreateIndexBuffer();
+
+ // Creates a vertex buffer for the specified region. The caller owns the
+ // return value.
+ ID3D10Buffer* CreateVertexBufferForRegion(const gfx::Rect& bounds);
+
+ gfx::AcceleratedWidget host_;
+
+ // Bounds the device was last created at.
+ gfx::Rect last_bounds_;
+
+ ScopedComPtr<ID3D10Device> device_;
+ ScopedComPtr<IDXGISwapChain> swap_chain_;
+ ScopedComPtr<ID3D10RenderTargetView> dest_render_target_view_;
+ ScopedComPtr<ID3D10Texture2D> depth_stencil_buffer_;
+ ScopedComPtr<ID3D10DepthStencilView> depth_stencil_view_;
+ ScopedComPtr<ID3D10Effect, NULL> fx_;
+ ID3D10EffectTechnique* technique_;
+
+ // Layout for Vertex.
+ ScopedComPtr<ID3D10InputLayout> vertex_layout_;
+
+ // Identity vertext buffer. Used when copying from main back to dest.
+ ScopedComPtr<ID3D10Buffer> vertex_buffer_;
+
+ // Index buffer used for drawing a rectangle.
+ ScopedComPtr<ID3D10Buffer> index_buffer_;
+
+ // Used for bluring.
+ ScopedComPtr<ID3D10Effect, NULL> blur_fx_;
+ ID3D10EffectTechnique* blur_technique_;
+
+ // All rendering is done to the main_texture. Effects (such as bloom) render
+ // into the blur texture, and are then copied back to the main texture. When
+ // rendering is done |main_texture_| is drawn back to
+ // |dest_render_target_view_|.
+ ScopedComPtr<ID3D10Texture2D> main_texture_;
+ ScopedComPtr<ID3D10RenderTargetView> main_render_target_view_;
+ ScopedComPtr<ID3D10ShaderResourceView> main_texture_shader_view_;
+
+ ScopedComPtr<ID3D10Texture2D> blur_texture_;
+ ScopedComPtr<ID3D10RenderTargetView> blur_render_target_view_;
+ ScopedComPtr<ID3D10ShaderResourceView> blur_texture_shader_view_;
+
+ DISALLOW_COPY_AND_ASSIGN(CompositorWin);
+};
+
+ViewTexture::ViewTexture(CompositorWin* compositor,
ID3D10Device* device,
ID3D10Effect* effect)
- : host_(host),
+ : compositor_(compositor),
device_(device),
effect_(effect) {
}
@@ -157,7 +246,7 @@ void ViewTexture::SetBitmap(const SkBitmap& bitmap,
}
void ViewTexture::Draw(const ui::Transform& transform) {
- host_->UpdatePerspective(transform, view_size_);
+ compositor_->UpdatePerspective(transform, view_size_);
// Make texture active.
RETURN_IF_FAILED(
@@ -175,7 +264,7 @@ void ViewTexture::Draw(const ui::Transform& transform) {
UINT offset = 0;
ID3D10Buffer* vertex_buffer = vertex_buffer_.get();
device_->IASetVertexBuffers(0, 1, &vertex_buffer, &stride, &offset);
- device_->IASetIndexBuffer(host_->GetTextureIndexBuffer(),
+ device_->IASetIndexBuffer(compositor_->GetTextureIndexBuffer(),
DXGI_FORMAT_R32_UINT, 0);
device_->DrawIndexed(6, 0, 0);
}
@@ -208,7 +297,7 @@ void ViewTexture::ConvertBitmapToD3DData(
void ViewTexture::CreateVertexBuffer(const gfx::Size& size) {
vertex_buffer_.Release();
- const gfx::Size& host_size = host_->GetHostSize();
+ const gfx::Size& host_size = compositor_->GetHostSize();
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());
@@ -233,108 +322,6 @@ void ViewTexture::CreateVertexBuffer(const gfx::Size& size) {
vertex_buffer_.Receive()));
}
-// D3D 10 Compositor implementation.
-class CompositorWin : public Compositor, public ViewTextureHost {
- public:
- explicit CompositorWin(gfx::AcceleratedWidget widget);
-
- void Init();
-
- // ViewTextureHost.
- virtual void UpdatePerspective(const ui::Transform& transform,
- const gfx::Size& view_size) OVERRIDE;
- virtual const gfx::Size& GetHostSize() OVERRIDE;
- virtual ID3D10Buffer* GetTextureIndexBuffer() OVERRIDE;
-
- // Compositor:
- virtual Texture* CreateTexture() OVERRIDE;
- virtual void NotifyStart() OVERRIDE;
- virtual void NotifyEnd() OVERRIDE;
- virtual void Blur(const gfx::Rect& bounds) OVERRIDE;
- virtual void SchedulePaint() OVERRIDE;
-
- private:
- enum Direction {
- HORIZONTAL,
- VERTICAL
- };
-
- ~CompositorWin();
-
- void Errored(HRESULT error_code);
-
- // Returns the bounds of the hosting window.
- gfx::Rect HostBounds();
-
- void CreateDevice();
-
- void LoadEffects();
-
- void InitVertexLayout();
-
- void Resize(const gfx::Rect& bounds);
-
- // 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);
-
- // Creates a texture, render target view and shader.
- void CreateTexture(const gfx::Size& size,
- ID3D10Texture2D** texture,
- ID3D10RenderTargetView** render_target_view,
- ID3D10ShaderResourceView** shader_resource_view);
-
- // Creates |vertex_buffer_|.
- void CreateVertexBuffer();
-
- // Creates |index_buffer_|.
- void CreateIndexBuffer();
-
- // Creates a vertex buffer for the specified region. The caller owns the
- // return value.
- ID3D10Buffer* CreateVertexBufferForRegion(const gfx::Rect& bounds);
-
- gfx::AcceleratedWidget host_;
-
- // Bounds the device was last created at.
- gfx::Rect last_bounds_;
-
- ScopedComPtr<ID3D10Device> device_;
- ScopedComPtr<IDXGISwapChain> swap_chain_;
- ScopedComPtr<ID3D10RenderTargetView> dest_render_target_view_;
- ScopedComPtr<ID3D10Texture2D> depth_stencil_buffer_;
- ScopedComPtr<ID3D10DepthStencilView> depth_stencil_view_;
- ScopedComPtr<ID3D10Effect, NULL> fx_;
- ID3D10EffectTechnique* technique_;
-
- // Layout for Vertex.
- ScopedComPtr<ID3D10InputLayout> vertex_layout_;
-
- // Identity vertext buffer. Used when copying from main back to dest.
- ScopedComPtr<ID3D10Buffer> vertex_buffer_;
-
- // Index buffer used for drawing a rectangle.
- ScopedComPtr<ID3D10Buffer> index_buffer_;
-
- // Used for bluring.
- ScopedComPtr<ID3D10Effect, NULL> blur_fx_;
- ID3D10EffectTechnique* blur_technique_;
-
- // All rendering is done to the main_texture. Effects (such as bloom) render
- // into the blur texture, and are then copied back to the main texture. When
- // rendering is done |main_texture_| is drawn back to
- // |dest_render_target_view_|.
- ScopedComPtr<ID3D10Texture2D> main_texture_;
- ScopedComPtr<ID3D10RenderTargetView> main_render_target_view_;
- ScopedComPtr<ID3D10ShaderResourceView> main_texture_shader_view_;
-
- ScopedComPtr<ID3D10Texture2D> blur_texture_;
- ScopedComPtr<ID3D10RenderTargetView> blur_render_target_view_;
- ScopedComPtr<ID3D10ShaderResourceView> blur_texture_shader_view_;
-
- DISALLOW_COPY_AND_ASSIGN(CompositorWin);
-};
-
CompositorWin::CompositorWin(gfx::AcceleratedWidget widget)
: host_(widget),
technique_(NULL) {
diff --git a/ui/gfx/compositor/layer.h b/ui/gfx/compositor/layer.h
index 9ef24b4..72faad1 100644
--- a/ui/gfx/compositor/layer.h
+++ b/ui/gfx/compositor/layer.h
@@ -8,7 +8,7 @@
#include <vector>
-#include "base/scoped_ptr.h"
+#include "base/memory/ref_counted.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/transform.h"
@@ -64,7 +64,7 @@ class Layer {
private:
Compositor* compositor_;
- scoped_ptr<ui::Texture> texture_;
+ scoped_refptr<ui::Texture> texture_;
Layer* parent_;