summaryrefslogtreecommitdiffstats
path: root/ui/gfx
diff options
context:
space:
mode:
Diffstat (limited to 'ui/gfx')
-rw-r--r--ui/gfx/gl/gl_surface_linux.cc127
-rw-r--r--ui/gfx/gl/gl_surface_osmesa.cc42
-rw-r--r--ui/gfx/gl/gl_surface_osmesa.h9
-rw-r--r--ui/gfx/gl/gl_surface_win.cc42
4 files changed, 78 insertions, 142 deletions
diff --git a/ui/gfx/gl/gl_surface_linux.cc b/ui/gfx/gl/gl_surface_linux.cc
index 5f764fc..a6771d9 100644
--- a/ui/gfx/gl/gl_surface_linux.cc
+++ b/ui/gfx/gl/gl_surface_linux.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -36,19 +36,16 @@ class NativeViewGLSurfaceOSMesa : public GLSurfaceOSMesa {
static bool InitializeOneOff();
- // Initializes the GL context.
- bool Initialize();
-
// Implement a subset of GLSurface.
- virtual void Destroy();
- virtual bool IsOffscreen();
- virtual bool SwapBuffers();
- virtual std::string GetExtensions();
- virtual bool PostSubBuffer(int x, int y, int width, int height);
+ virtual bool Initialize() OVERRIDE;
+ virtual void Destroy() OVERRIDE;
+ virtual bool Resize(const gfx::Size& new_size) OVERRIDE;
+ virtual bool IsOffscreen() OVERRIDE;
+ virtual bool SwapBuffers() OVERRIDE;
+ virtual std::string GetExtensions() OVERRIDE;
+ virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE;
private:
- bool UpdateSize();
-
GC window_graphics_context_;
gfx::PluginWindowHandle window_;
GC pixmap_graphics_context_;
@@ -92,7 +89,7 @@ bool GLSurface::InitializeOneOffInternal() {
NativeViewGLSurfaceOSMesa::NativeViewGLSurfaceOSMesa(
gfx::PluginWindowHandle window)
- : GLSurfaceOSMesa(OSMESA_BGRA, gfx::Size()),
+ : GLSurfaceOSMesa(OSMESA_BGRA, gfx::Size(1, 1)),
window_graphics_context_(0),
window_(window),
pixmap_graphics_context_(0),
@@ -133,8 +130,6 @@ bool NativeViewGLSurfaceOSMesa::Initialize() {
return false;
}
- UpdateSize();
-
return true;
}
@@ -155,18 +150,52 @@ void NativeViewGLSurfaceOSMesa::Destroy() {
}
}
+bool NativeViewGLSurfaceOSMesa::Resize(const gfx::Size& new_size) {
+ if (!GLSurfaceOSMesa::Resize(new_size))
+ return false;
+
+ XWindowAttributes attributes;
+ if (!XGetWindowAttributes(g_osmesa_display, window_, &attributes)) {
+ LOG(ERROR) << "XGetWindowAttributes failed for window " << window_ << ".";
+ return false;
+ }
+
+ // Destroy the previous pixmap and graphics context.
+ if (pixmap_graphics_context_) {
+ XFreeGC(g_osmesa_display, pixmap_graphics_context_);
+ pixmap_graphics_context_ = NULL;
+ }
+ if (pixmap_) {
+ XFreePixmap(g_osmesa_display, pixmap_);
+ pixmap_ = 0;
+ }
+
+ // Recreate a pixmap to hold the frame.
+ pixmap_ = XCreatePixmap(g_osmesa_display,
+ window_,
+ new_size.width(),
+ new_size.height(),
+ attributes.depth);
+ if (!pixmap_) {
+ LOG(ERROR) << "XCreatePixmap failed.";
+ return false;
+ }
+
+ // Recreate a graphics context for the pixmap.
+ pixmap_graphics_context_ = XCreateGC(g_osmesa_display, pixmap_, 0, NULL);
+ if (!pixmap_graphics_context_) {
+ LOG(ERROR) << "XCreateGC failed";
+ return false;
+ }
+
+ return true;
+}
+
bool NativeViewGLSurfaceOSMesa::IsOffscreen() {
return false;
}
bool NativeViewGLSurfaceOSMesa::SwapBuffers() {
- // Update the size before blitting so that the blit size is exactly the same
- // as the window.
- if (!UpdateSize()) {
- LOG(ERROR) << "Failed to update size of GLContextOSMesa.";
- return false;
- }
-
gfx::Size size = GetSize();
XWindowAttributes attributes;
@@ -206,13 +235,6 @@ std::string NativeViewGLSurfaceOSMesa::GetExtensions() {
bool NativeViewGLSurfaceOSMesa::PostSubBuffer(
int x, int y, int width, int height) {
- // Update the size before blitting so that the blit size is exactly the same
- // as the window.
- if (!UpdateSize()) {
- LOG(ERROR) << "Failed to update size of GLContextOSMesa.";
- return false;
- }
-
gfx::Size size = GetSize();
// Move (0,0) from lower-left to upper-left
@@ -250,55 +272,6 @@ bool NativeViewGLSurfaceOSMesa::PostSubBuffer(
return true;
}
-bool NativeViewGLSurfaceOSMesa::UpdateSize() {
- // Get the window size.
- XWindowAttributes attributes;
- if (!XGetWindowAttributes(g_osmesa_display, window_, &attributes)) {
- LOG(ERROR) << "XGetWindowAttributes failed for window " << window_ << ".";
- return false;
- }
- gfx::Size window_size = gfx::Size(std::max(1, attributes.width),
- std::max(1, attributes.height));
-
- // Early out if the size has not changed.
- gfx::Size osmesa_size = GetSize();
- if (pixmap_graphics_context_ && pixmap_ && window_size == osmesa_size)
- return true;
-
- // Change osmesa surface size to that of window.
- Resize(window_size);
-
- // Destroy the previous pixmap and graphics context.
- if (pixmap_graphics_context_) {
- XFreeGC(g_osmesa_display, pixmap_graphics_context_);
- pixmap_graphics_context_ = NULL;
- }
- if (pixmap_) {
- XFreePixmap(g_osmesa_display, pixmap_);
- pixmap_ = 0;
- }
-
- // Recreate a pixmap to hold the frame.
- pixmap_ = XCreatePixmap(g_osmesa_display,
- window_,
- window_size.width(),
- window_size.height(),
- attributes.depth);
- if (!pixmap_) {
- LOG(ERROR) << "XCreatePixmap failed.";
- return false;
- }
-
- // Recreate a graphics context for the pixmap.
- pixmap_graphics_context_ = XCreateGC(g_osmesa_display, pixmap_, 0, NULL);
- if (!pixmap_graphics_context_) {
- LOG(ERROR) << "XCreateGC failed";
- return false;
- }
-
- return true;
-}
-
#endif // !USE_WAYLAND
scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface(
diff --git a/ui/gfx/gl/gl_surface_osmesa.cc b/ui/gfx/gl/gl_surface_osmesa.cc
index a6d4b4c..eea7ee4 100644
--- a/ui/gfx/gl/gl_surface_osmesa.cc
+++ b/ui/gfx/gl/gl_surface_osmesa.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -18,10 +18,15 @@ GLSurfaceOSMesa::~GLSurfaceOSMesa() {
Destroy();
}
-bool GLSurfaceOSMesa::Resize(const gfx::Size& new_size) {
- if (new_size == size_)
- return true;
+bool GLSurfaceOSMesa::Initialize() {
+ return Resize(size_);
+}
+void GLSurfaceOSMesa::Destroy() {
+ buffer_.reset();
+}
+
+bool GLSurfaceOSMesa::Resize(const gfx::Size& new_size) {
GLContext* current_context = GLContext::GetCurrent();
bool was_current = current_context && current_context->IsCurrent(this);
if (was_current)
@@ -31,14 +36,17 @@ bool GLSurfaceOSMesa::Resize(const gfx::Size& new_size) {
scoped_array<int32> old_buffer(buffer_.release());
// Allocate a new one.
- AllocateBuffer(new_size);
+ buffer_.reset(new int32[new_size.GetArea()]);
+ memset(buffer_.get(), 0, new_size.GetArea() * sizeof(buffer_[0]));
// Copy the old back buffer into the new buffer.
- int copy_width = std::min(size_.width(), new_size.width());
- int copy_height = std::min(size_.height(), new_size.height());
- for (int y = 0; y < copy_height; ++y) {
- for (int x = 0; x < copy_width; ++x) {
- buffer_[y * new_size.width() + x] = old_buffer[y * size_.width() + x];
+ if (old_buffer.get()) {
+ int copy_width = std::min(size_.width(), new_size.width());
+ int copy_height = std::min(size_.height(), new_size.height());
+ for (int y = 0; y < copy_height; ++y) {
+ for (int x = 0; x < copy_width; ++x) {
+ buffer_[y * new_size.width() + x] = old_buffer[y * size_.width() + x];
+ }
}
}
@@ -50,15 +58,6 @@ bool GLSurfaceOSMesa::Resize(const gfx::Size& new_size) {
return true;
}
-bool GLSurfaceOSMesa::Initialize() {
- AllocateBuffer(size_);
- return true;
-}
-
-void GLSurfaceOSMesa::Destroy() {
- buffer_.reset();
-}
-
bool GLSurfaceOSMesa::IsOffscreen() {
return true;
}
@@ -80,9 +79,4 @@ unsigned GLSurfaceOSMesa::GetFormat() {
return format_;
}
-void GLSurfaceOSMesa::AllocateBuffer(const Size& size) {
- buffer_.reset(new int32[size.GetArea()]);
- memset(buffer_.get(), 0, size.GetArea() * sizeof(buffer_[0]));
-}
-
} // namespace gfx
diff --git a/ui/gfx/gl/gl_surface_osmesa.h b/ui/gfx/gl/gl_surface_osmesa.h
index 2e0d384..9404050 100644
--- a/ui/gfx/gl/gl_surface_osmesa.h
+++ b/ui/gfx/gl/gl_surface_osmesa.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -20,13 +20,10 @@ class GL_EXPORT GLSurfaceOSMesa : public GLSurface {
GLSurfaceOSMesa(unsigned format, const gfx::Size& size);
virtual ~GLSurfaceOSMesa();
- // Resize the back buffer, preserving the old content. Does nothing if the
- // size is unchanged.
- virtual bool Resize(const gfx::Size& new_size) OVERRIDE;
-
// Implement GLSurface.
virtual bool Initialize() OVERRIDE;
virtual void Destroy() OVERRIDE;
+ virtual bool Resize(const gfx::Size& new_size) OVERRIDE;
virtual bool IsOffscreen() OVERRIDE;
virtual bool SwapBuffers() OVERRIDE;
virtual gfx::Size GetSize() OVERRIDE;
@@ -34,8 +31,6 @@ class GL_EXPORT GLSurfaceOSMesa : public GLSurface {
virtual unsigned GetFormat() OVERRIDE;
private:
- void AllocateBuffer(const Size& size);
-
unsigned format_;
gfx::Size size_;
scoped_array<int32> buffer_;
diff --git a/ui/gfx/gl/gl_surface_win.cc b/ui/gfx/gl/gl_surface_win.cc
index 08b3396..4df75a9 100644
--- a/ui/gfx/gl/gl_surface_win.cc
+++ b/ui/gfx/gl/gl_surface_win.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -23,19 +23,15 @@ class NativeViewGLSurfaceOSMesa : public GLSurfaceOSMesa {
explicit NativeViewGLSurfaceOSMesa(gfx::PluginWindowHandle window);
virtual ~NativeViewGLSurfaceOSMesa();
- // Initializes the GL context.
- bool Initialize();
-
// Implement subset of GLSurface.
- virtual void Destroy();
- virtual bool IsOffscreen();
- virtual bool SwapBuffers();
- virtual std::string GetExtensions();
- virtual bool PostSubBuffer(int x, int y, int width, int height);
+ virtual bool Initialize() OVERRIDE;
+ virtual void Destroy() OVERRIDE;
+ virtual bool IsOffscreen() OVERRIDE;
+ virtual bool SwapBuffers() OVERRIDE;
+ virtual std::string GetExtensions() OVERRIDE;
+ virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE;
private:
- void UpdateSize();
-
gfx::PluginWindowHandle window_;
HDC device_context_;
@@ -64,7 +60,7 @@ bool GLSurface::InitializeOneOffInternal() {
NativeViewGLSurfaceOSMesa::NativeViewGLSurfaceOSMesa(
gfx::PluginWindowHandle window)
- : GLSurfaceOSMesa(OSMESA_RGBA, gfx::Size()),
+ : GLSurfaceOSMesa(OSMESA_RGBA, gfx::Size(1, 1)),
window_(window),
device_context_(NULL) {
DCHECK(window);
@@ -79,7 +75,6 @@ bool NativeViewGLSurfaceOSMesa::Initialize() {
return false;
device_context_ = GetDC(window_);
- UpdateSize();
return true;
}
@@ -99,10 +94,6 @@ bool NativeViewGLSurfaceOSMesa::IsOffscreen() {
bool NativeViewGLSurfaceOSMesa::SwapBuffers() {
DCHECK(device_context_);
- // Update the size before blitting so that the blit size is exactly the same
- // as the window.
- UpdateSize();
-
gfx::Size size = GetSize();
// Note: negating the height below causes GDI to treat the bitmap data as row
@@ -147,10 +138,6 @@ bool NativeViewGLSurfaceOSMesa::PostSubBuffer(
int x, int y, int width, int height) {
DCHECK(device_context_);
- // Update the size before blitting so that the blit size is exactly the same
- // as the window.
- UpdateSize();
-
gfx::Size size = GetSize();
// Note: negating the height below causes GDI to treat the bitmap data as row
@@ -184,19 +171,6 @@ bool NativeViewGLSurfaceOSMesa::PostSubBuffer(
return true;
}
-void NativeViewGLSurfaceOSMesa::UpdateSize() {
- // Change back buffer size to that of window. If window handle is invalid, do
- // not change the back buffer size.
- RECT rect;
- if (!GetClientRect(window_, &rect))
- return;
-
- gfx::Size window_size = gfx::Size(
- std::max(1, static_cast<int>(rect.right - rect.left)),
- std::max(1, static_cast<int>(rect.bottom - rect.top)));
- Resize(window_size);
-}
-
scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface(
bool software,
gfx::PluginWindowHandle window) {