This source file includes following definitions.
- GetVSyncParameters
- InitializeOneOffInternal
- device_context_
- Initialize
- Destroy
- IsOffscreen
- SwapBuffers
- SupportsPostSubBuffer
- PostSubBuffer
- CreateViewGLSurface
- CreateOffscreenGLSurface
- GetPlatformDefaultEGLNativeDisplay
#include "ui/gl/gl_surface.h"
#include <dwmapi.h>
#include "base/command_line.h"
#include "base/debug/trace_event.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/win/windows_version.h"
#include "third_party/mesa/src/include/GL/osmesa.h"
#include "ui/gfx/frame_time.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_surface_egl.h"
#include "ui/gl/gl_surface_osmesa.h"
#include "ui/gl/gl_surface_stub.h"
#include "ui/gl/gl_surface_wgl.h"
#if !defined(EGL_D3D11_ELSE_D3D9_DISPLAY_ANGLE)
#define EGL_D3D11_ELSE_D3D9_DISPLAY_ANGLE \
reinterpret_cast<EGLNativeDisplayType>(-2)
#endif
namespace gfx {
class NativeViewGLSurfaceOSMesa : public GLSurfaceOSMesa {
public:
explicit NativeViewGLSurfaceOSMesa(gfx::AcceleratedWidget window);
virtual ~NativeViewGLSurfaceOSMesa();
virtual bool Initialize() OVERRIDE;
virtual void Destroy() OVERRIDE;
virtual bool IsOffscreen() OVERRIDE;
virtual bool SwapBuffers() OVERRIDE;
virtual bool SupportsPostSubBuffer() OVERRIDE;
virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE;
private:
gfx::AcceleratedWidget window_;
HDC device_context_;
DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceOSMesa);
};
class DWMVSyncProvider : public VSyncProvider {
public:
explicit DWMVSyncProvider() {}
virtual ~DWMVSyncProvider() {}
virtual void GetVSyncParameters(const UpdateVSyncCallback& callback) {
TRACE_EVENT0("gpu", "DWMVSyncProvider::GetVSyncParameters");
DWM_TIMING_INFO timing_info;
timing_info.cbSize = sizeof(timing_info);
HRESULT result = DwmGetCompositionTimingInfo(NULL, &timing_info);
if (result != S_OK)
return;
base::TimeTicks timebase;
if (gfx::FrameTime::TimestampsAreHighRes()) {
timebase = gfx::FrameTime::FromQPCValue(
static_cast<LONGLONG>(timing_info.qpcVBlank));
}
if (timing_info.rateRefresh.uiDenominator > 0 &&
timing_info.rateRefresh.uiNumerator > 0) {
base::TimeDelta interval = base::TimeDelta::FromMicroseconds(
timing_info.rateRefresh.uiDenominator *
base::Time::kMicrosecondsPerSecond /
timing_info.rateRefresh.uiNumerator);
callback.Run(timebase, interval);
}
}
private:
DISALLOW_COPY_AND_ASSIGN(DWMVSyncProvider);
};
bool GLSurface::InitializeOneOffInternal() {
switch (GetGLImplementation()) {
case kGLImplementationDesktopGL:
if (!GLSurfaceWGL::InitializeOneOff()) {
LOG(ERROR) << "GLSurfaceWGL::InitializeOneOff failed.";
return false;
}
break;
case kGLImplementationEGLGLES2:
if (!GLSurfaceEGL::InitializeOneOff()) {
LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed.";
return false;
}
break;
}
return true;
}
NativeViewGLSurfaceOSMesa::NativeViewGLSurfaceOSMesa(
gfx::AcceleratedWidget window)
: GLSurfaceOSMesa(OSMESA_RGBA, gfx::Size(1, 1)),
window_(window),
device_context_(NULL) {
DCHECK(window);
}
NativeViewGLSurfaceOSMesa::~NativeViewGLSurfaceOSMesa() {
Destroy();
}
bool NativeViewGLSurfaceOSMesa::Initialize() {
if (!GLSurfaceOSMesa::Initialize())
return false;
device_context_ = GetDC(window_);
return true;
}
void NativeViewGLSurfaceOSMesa::Destroy() {
if (window_ && device_context_)
ReleaseDC(window_, device_context_);
device_context_ = NULL;
GLSurfaceOSMesa::Destroy();
}
bool NativeViewGLSurfaceOSMesa::IsOffscreen() {
return false;
}
bool NativeViewGLSurfaceOSMesa::SwapBuffers() {
DCHECK(device_context_);
gfx::Size size = GetSize();
BITMAPV4HEADER info = { sizeof(BITMAPV4HEADER) };
info.bV4Width = size.width();
info.bV4Height = -size.height();
info.bV4Planes = 1;
info.bV4BitCount = 32;
info.bV4V4Compression = BI_BITFIELDS;
info.bV4RedMask = 0x000000FF;
info.bV4GreenMask = 0x0000FF00;
info.bV4BlueMask = 0x00FF0000;
info.bV4AlphaMask = 0xFF000000;
StretchDIBits(device_context_,
0, 0, size.width(), size.height(),
0, 0, size.width(), size.height(),
GetHandle(),
reinterpret_cast<BITMAPINFO*>(&info),
DIB_RGB_COLORS,
SRCCOPY);
return true;
}
bool NativeViewGLSurfaceOSMesa::SupportsPostSubBuffer() {
return true;
}
bool NativeViewGLSurfaceOSMesa::PostSubBuffer(
int x, int y, int width, int height) {
DCHECK(device_context_);
gfx::Size size = GetSize();
BITMAPV4HEADER info = { sizeof(BITMAPV4HEADER) };
info.bV4Width = size.width();
info.bV4Height = -size.height();
info.bV4Planes = 1;
info.bV4BitCount = 32;
info.bV4V4Compression = BI_BITFIELDS;
info.bV4RedMask = 0x000000FF;
info.bV4GreenMask = 0x0000FF00;
info.bV4BlueMask = 0x00FF0000;
info.bV4AlphaMask = 0xFF000000;
StretchDIBits(device_context_,
x, size.height() - y - height, width, height,
x, y, width, height,
GetHandle(),
reinterpret_cast<BITMAPINFO*>(&info),
DIB_RGB_COLORS,
SRCCOPY);
return true;
}
scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface(
gfx::AcceleratedWidget window) {
TRACE_EVENT0("gpu", "GLSurface::CreateViewGLSurface");
switch (GetGLImplementation()) {
case kGLImplementationOSMesaGL: {
scoped_refptr<GLSurface> surface(
new NativeViewGLSurfaceOSMesa(window));
if (!surface->Initialize())
return NULL;
return surface;
}
case kGLImplementationEGLGLES2: {
DCHECK(window != gfx::kNullAcceleratedWidget);
scoped_refptr<NativeViewGLSurfaceEGL> surface(
new NativeViewGLSurfaceEGL(window));
scoped_ptr<VSyncProvider> sync_provider;
if (base::win::GetVersion() >= base::win::VERSION_VISTA)
sync_provider.reset(new DWMVSyncProvider);
if (!surface->Initialize(sync_provider.Pass()))
return NULL;
return surface;
}
case kGLImplementationDesktopGL: {
scoped_refptr<GLSurface> surface(new NativeViewGLSurfaceWGL(
window));
if (!surface->Initialize())
return NULL;
return surface;
}
case kGLImplementationMockGL:
return new GLSurfaceStub;
default:
NOTREACHED();
return NULL;
}
}
scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface(
const gfx::Size& size) {
TRACE_EVENT0("gpu", "GLSurface::CreateOffscreenGLSurface");
switch (GetGLImplementation()) {
case kGLImplementationOSMesaGL: {
scoped_refptr<GLSurface> surface(new GLSurfaceOSMesa(OSMESA_RGBA,
size));
if (!surface->Initialize())
return NULL;
return surface;
}
case kGLImplementationEGLGLES2: {
scoped_refptr<GLSurface> surface(new PbufferGLSurfaceEGL(size));
if (!surface->Initialize())
return NULL;
return surface;
}
case kGLImplementationDesktopGL: {
scoped_refptr<GLSurface> surface(new PbufferGLSurfaceWGL(size));
if (!surface->Initialize())
return NULL;
return surface;
}
case kGLImplementationMockGL:
return new GLSurfaceStub;
default:
NOTREACHED();
return NULL;
}
}
EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() {
if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableD3D11))
return EGL_D3D11_ELSE_D3D9_DISPLAY_ANGLE;
return EGL_DEFAULT_DISPLAY;
}
}