summaryrefslogtreecommitdiffstats
path: root/ui/gfx
diff options
context:
space:
mode:
authorbacker@chromium.org <backer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-22 18:09:31 +0000
committerbacker@chromium.org <backer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-22 18:09:31 +0000
commit638b1808f8c609dbf58c319837a78f1c316f82cd (patch)
treea14609c3e7ac594c104feb46a131b5c82c0f4843 /ui/gfx
parent4ac107e6d3aec2a6cf51834b80bd2c98747cd72f (diff)
downloadchromium_src-638b1808f8c609dbf58c319837a78f1c316f82cd.zip
chromium_src-638b1808f8c609dbf58c319837a78f1c316f82cd.tar.gz
chromium_src-638b1808f8c609dbf58c319837a78f1c316f82cd.tar.bz2
Always write alpha. Turn of blending for root layers. Also, don't clear the background before drawing.
BUG=5001880 TEST=none Review URL: http://codereview.chromium.org/7473007 Patch from Ian Vollick <vollick@chromium.org>. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@93675 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx')
-rw-r--r--ui/gfx/compositor/compositor.h17
-rw-r--r--ui/gfx/compositor/compositor_gl.cc24
-rw-r--r--ui/gfx/compositor/compositor_gl.h4
-rw-r--r--ui/gfx/compositor/compositor_win.cc6
-rw-r--r--ui/gfx/compositor/layer.cc13
5 files changed, 40 insertions, 24 deletions
diff --git a/ui/gfx/compositor/compositor.h b/ui/gfx/compositor/compositor.h
index 08b8b38..7ca9dd1 100644
--- a/ui/gfx/compositor/compositor.h
+++ b/ui/gfx/compositor/compositor.h
@@ -7,6 +7,7 @@
#pragma once
#include "base/memory/ref_counted.h"
+#include "ui/gfx/transform.h"
#include "ui/gfx/native_widget_types.h"
class SkBitmap;
@@ -17,7 +18,19 @@ class Size;
}
namespace ui {
-class Transform;
+
+struct TextureDrawParams {
+ TextureDrawParams() : transform(), blend(false) {}
+
+ // The transform to be applied to the texture.
+ ui::Transform transform;
+
+ // If this is true, then the texture is blended with the pixels behind it.
+ // Otherwise, the drawn pixels clobber the old pixels.
+ bool blend;
+
+ // Copy and assignment are allowed.
+};
// 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().
@@ -36,7 +49,7 @@ class Texture : public base::RefCounted<Texture> {
const gfx::Size& overall_size) = 0;
// Draws the texture.
- virtual void Draw(const ui::Transform& transform) = 0;
+ virtual void Draw(const ui::TextureDrawParams& params) = 0;
protected:
virtual ~Texture() {}
diff --git a/ui/gfx/compositor/compositor_gl.cc b/ui/gfx/compositor/compositor_gl.cc
index 881c697..ddd2ad8 100644
--- a/ui/gfx/compositor/compositor_gl.cc
+++ b/ui/gfx/compositor/compositor_gl.cc
@@ -328,13 +328,18 @@ void TextureGL::SetBitmap(const SkBitmap& bitmap,
}
}
-void TextureGL::Draw(const ui::Transform& transform) {
+void TextureGL::Draw(const ui::TextureDrawParams& params) {
DCHECK(compositor_->program_swizzle());
- DrawInternal(*compositor_->program_swizzle(), transform);
+ DrawInternal(*compositor_->program_swizzle(), params);
}
void TextureGL::DrawInternal(const ui::TextureProgramGL& program,
- const ui::Transform& transform) {
+ const ui::TextureDrawParams& params) {
+ if (params.blend)
+ glEnable(GL_BLEND);
+ else
+ glDisable(GL_BLEND);
+
program.Use();
glActiveTexture(GL_TEXTURE0);
@@ -349,7 +354,7 @@ void TextureGL::DrawInternal(const ui::TextureProgramGL& program,
t.ConcatTranslate(0, -size_.height());
t.ConcatScale(1, -1);
- t.ConcatTransform(transform); // Add view transform.
+ t.ConcatTransform(params.transform); // Add view transform.
t.ConcatTranslate(0, -window_size.height());
t.ConcatScale(1, -1);
@@ -385,7 +390,6 @@ CompositorGL::CompositorGL(gfx::AcceleratedWidget widget,
CreateContext(gl_surface_.get());
gl_context_->MakeCurrent(gl_surface_.get());
glColorMask(true, true, true, true);
- glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
@@ -419,18 +423,14 @@ void CompositorGL::NotifyStart() {
started_ = true;
gl_context_->MakeCurrent(gl_surface_.get());
glViewport(0, 0, size_.width(), size_.height());
+ glColorMask(true, true, true, true);
#if defined(DEBUG)
// Clear to 'psychedelic' purple to make it easy to spot un-rendered regions.
glClearColor(223.0 / 255, 0, 1, 1);
-#else
- // Clear to transparent black.
- glClearColor(0, 0, 0, 0);
-#endif
- glColorMask(true, true, true, true);
glClear(GL_COLOR_BUFFER_BIT);
- // Disable alpha writes, since we're using blending anyways.
- glColorMask(true, true, true, false);
+#endif
+ // Do not clear in release: root layer is responsible for drawing every pixel.
}
void CompositorGL::NotifyEnd() {
diff --git a/ui/gfx/compositor/compositor_gl.h b/ui/gfx/compositor/compositor_gl.h
index ba8d24f..dc7f187 100644
--- a/ui/gfx/compositor/compositor_gl.h
+++ b/ui/gfx/compositor/compositor_gl.h
@@ -30,7 +30,7 @@ class TextureGL : public Texture {
const gfx::Size& overall_size) OVERRIDE;
// Draws the texture.
- virtual void Draw(const ui::Transform& transform) OVERRIDE;
+ virtual void Draw(const ui::TextureDrawParams& params) OVERRIDE;
protected:
TextureGL(CompositorGL* compositor, const gfx::Size& size);
@@ -38,7 +38,7 @@ class TextureGL : public Texture {
// Actually draws the texture.
void DrawInternal(const TextureProgramGL& program,
- const ui::Transform& transform);
+ const ui::TextureDrawParams& params);
unsigned int texture_id_;
gfx::Size size_;
diff --git a/ui/gfx/compositor/compositor_win.cc b/ui/gfx/compositor/compositor_win.cc
index 9a9666c..0019dae 100644
--- a/ui/gfx/compositor/compositor_win.cc
+++ b/ui/gfx/compositor/compositor_win.cc
@@ -55,7 +55,7 @@ class ViewTexture : public Texture {
virtual void SetBitmap(const SkBitmap& bitmap,
const gfx::Point& origin,
const gfx::Size& overall_size) OVERRIDE;
- virtual void Draw(const ui::Transform& transform) OVERRIDE;
+ virtual void Draw(const ui::TextureDrawParams& params) OVERRIDE;
private:
~ViewTexture();
@@ -244,8 +244,8 @@ void ViewTexture::SetBitmap(const SkBitmap& bitmap,
}
}
-void ViewTexture::Draw(const ui::Transform& transform) {
- compositor_->UpdatePerspective(transform, view_size_);
+void ViewTexture::Draw(const ui::TextureDrawParams& params) {
+ compositor_->UpdatePerspective(params.transform, view_size_);
// Make texture active.
RETURN_IF_FAILED(
diff --git a/ui/gfx/compositor/layer.cc b/ui/gfx/compositor/layer.cc
index 5779e52..ddcfb5a 100644
--- a/ui/gfx/compositor/layer.cc
+++ b/ui/gfx/compositor/layer.cc
@@ -51,13 +51,16 @@ void Layer::SetBitmap(const SkBitmap& bitmap, const gfx::Point& origin) {
}
void Layer::Draw() {
- ui::Transform transform;
+ ui::TextureDrawParams texture_draw_params;
for (Layer* layer = this; layer; layer = layer->parent_) {
- transform.ConcatTransform(layer->transform_);
- transform.ConcatTranslate(static_cast<float>(layer->bounds_.x()),
- static_cast<float>(layer->bounds_.y()));
+ texture_draw_params.transform.ConcatTransform(layer->transform_);
+ texture_draw_params.transform.ConcatTranslate(
+ static_cast<float>(layer->bounds_.x()),
+ static_cast<float>(layer->bounds_.y()));
}
- texture_->Draw(transform);
+ // Only blend for child layers. The root layer will clobber the cleared bg.
+ texture_draw_params.blend = parent_ != NULL;
+ texture_->Draw(texture_draw_params);
}
} // namespace ui