summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-10 18:26:25 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-10 18:26:25 +0000
commitc36b0bfba80a88ce3776739575a1103235c409d1 (patch)
treed37790e560bff4136f3c723c95c645abec7caf76 /ui
parent5b37cb72a5bfbcc1daa57249319a8235d0d4874a (diff)
downloadchromium_src-c36b0bfba80a88ce3776739575a1103235c409d1.zip
chromium_src-c36b0bfba80a88ce3776739575a1103235c409d1.tar.gz
chromium_src-c36b0bfba80a88ce3776739575a1103235c409d1.tar.bz2
Tweaks Compositor API. To make it possible to land this I've ifdef'd
the code in a couple of places. BUG=none TEST=none R=ben@chromium.org,wjmaclean@chromium.org,rjkroege@chromium.org Review URL: http://codereview.chromium.org/6999005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@84823 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/gfx/compositor/compositor.gyp22
-rw-r--r--ui/gfx/compositor/compositor.h57
-rw-r--r--ui/gfx/compositor/compositor_gl.cc53
3 files changed, 125 insertions, 7 deletions
diff --git a/ui/gfx/compositor/compositor.gyp b/ui/gfx/compositor/compositor.gyp
index f739b93..98adcf8 100644
--- a/ui/gfx/compositor/compositor.gyp
+++ b/ui/gfx/compositor/compositor.gyp
@@ -3,6 +3,19 @@
# found in the LICENSE file.
{
+ 'target_defaults': {
+ 'sources/': [
+ ['exclude', '_(gl|win)\\.(cc?)$'],
+ ],
+ 'conditions': [
+ ['OS=="linux" or OS=="freebsd" or OS=="openbsd"', {'sources/': [
+ ['include', '_(gl)\\.cc$'],
+ ]}],
+ ['OS=="win"', {'sources/': [
+ ['include', '_(win)\\.cc$'],
+ ]}],
+ ],
+ },
'targets': [
{
'target_name': 'compositor',
@@ -10,25 +23,22 @@
'msvs_guid': '21CEE0E3-6F4E-4F01-B8C9-F7751CC21AA9',
'dependencies': [
'<(DEPTH)/base/base.gyp:base',
+ '<(DEPTH)/skia/skia.gyp:skia',
'<(DEPTH)/ui/gfx/gl/gl.gyp:gl',
'<(DEPTH)/ui/ui.gyp:ui_gfx',
],
'sources': [
'compositor.cc',
- 'compositor_gl.cc',
'compositor.h',
+ 'compositor_gl.cc',
],
'conditions': [
['OS=="linux" or OS=="freebsd" or OS=="openbsd"', {
'sources!': [
'compositor.cc',
],
- }, {
- 'sources!': [
- 'compositor_gl.cc',
- ]
}],
],
},
],
-} \ No newline at end of file
+}
diff --git a/ui/gfx/compositor/compositor.h b/ui/gfx/compositor/compositor.h
index 7d19598..9b35eb1 100644
--- a/ui/gfx/compositor/compositor.h
+++ b/ui/gfx/compositor/compositor.h
@@ -9,9 +9,16 @@
#include "base/memory/ref_counted.h"
#include "ui/gfx/native_widget_types.h"
+class SkBitmap;
+namespace gfx {
+class Point;
+class Size;
+}
+
namespace ui {
class Transform;
+#if !defined(COMPOSITOR_2)
typedef unsigned int TextureID;
// Compositor object to take care of GPU painting.
@@ -48,6 +55,56 @@ class Compositor : public base::RefCounted<Compositor> {
friend class base::RefCounted<Compositor>;
};
+#else
+// Textures are created by a Compositor for managing an accelerated view.
+// Any time a View with a texture needs to redraw itself it invokes SetBitmap().
+// When the view is ready to be drawn Draw() is invoked.
+//
+// Texture is really a proxy to the gpu. Texture does not itself keep a copy of
+// the bitmap.
+//
+// Views own the Texture.
+class 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,
+ const gfx::Point& origin,
+ const gfx::Size& overall_size) = 0;
+
+ // Draws the texture.
+ virtual void Draw(const ui::Transform& transform) = 0;
+};
+
+// Compositor object to take care of GPU painting.
+// A Browser compositor object is responsible for generating the final
+// displayable form of pixels comprising a single widget's contents. It draws an
+// appropriately transformed texture for each transformed view in the widget's
+// view hierarchy.
+class Compositor : public base::RefCounted<Compositor> {
+ public:
+ // Create a compositor from the provided handle.
+ static Compositor* Create(gfx::AcceleratedWidget widget);
+
+ // Creates a new texture. The caller owns the returned object.
+ virtual Texture* CreateTexture() = 0;
+
+ // Notifies the compositor that compositing is about to start.
+ virtual void NotifyStart() = 0;
+
+ // Notifies the compositor that compositing is complete.
+ virtual void NotifyEnd() = 0;
+
+ protected:
+ virtual ~Compositor() {}
+
+ private:
+ friend class base::RefCounted<Compositor>;
+};
+
+#endif // COMPOSITOR_2
} // namespace ui
#endif // UI_GFX_COMPOSITOR_COMPOSITOR_H_
diff --git a/ui/gfx/compositor/compositor_gl.cc b/ui/gfx/compositor/compositor_gl.cc
index f152ffc..4beb65c 100644
--- a/ui/gfx/compositor/compositor_gl.cc
+++ b/ui/gfx/compositor/compositor_gl.cc
@@ -15,6 +15,57 @@
namespace ui {
+#if defined COMPOSITOR_2
+namespace {
+
+class CompositorGL : public Compositor {
+ public:
+ explicit CompositorGL(gfx::AcceleratedWidget widget);
+
+ private:
+ // Overridden from Compositor.
+ virtual Texture* CreateTexture() OVERRIDE;
+ virtual void NotifyStart() OVERRIDE;
+ virtual void NotifyEnd() OVERRIDE;
+
+ // The GL context used for compositing.
+ scoped_ptr<gfx::GLContext> gl_context_;
+
+ // Keep track of whether compositing has started or not.
+ bool started_;
+
+ DISALLOW_COPY_AND_ASSIGN(CompositorGL);
+};
+
+CompositorGL::CompositorGL(gfx::AcceleratedWidget widget)
+ : gl_context_(gfx::GLContext::CreateViewGLContext(widget, false)),
+ started_(false) {
+}
+
+Texture* CompositorGL::CreateTexture() {
+ return NULL;
+}
+
+void CompositorGL::NotifyStart() {
+ started_ = true;
+ gl_context_->MakeCurrent();
+}
+
+void CompositorGL::NotifyEnd() {
+ DCHECK(started_);
+ gl_context_->SwapBuffers();
+ started_ = false;
+}
+
+} // namespace
+
+// static
+Compositor* Compositor::Create(gfx::AcceleratedWidget widget) {
+ if (gfx::GetGLImplementation() != gfx::kGLImplementationNone)
+ return new CompositorGL(widget);
+ return NULL;
+}
+#else
class CompositorGL : public Compositor {
public:
explicit CompositorGL(gfx::AcceleratedWidget widget);
@@ -77,5 +128,5 @@ Compositor* Compositor::Create(gfx::AcceleratedWidget widget) {
return new CompositorGL(widget);
return NULL;
}
-
+#endif
} // namespace ui