This source file includes following definitions.
- Destroy
- ReleaseCurrent
- IsCurrent
- GetHandle
- SetSwapInterval
- display_
- Initialize
- MakeCurrent
- GetExtensions
- CreateGLContext
- GetTotalGpuMemory
#include "ui/gl/gl_context.h"
#include "base/android/sys_utils.h"
#include "base/logging.h"
#include "base/memory/ref_counted.h"
#include "base/sys_info.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_context_egl.h"
#include "ui/gl/gl_context_osmesa.h"
#include "ui/gl/gl_context_stub.h"
#include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_surface.h"
namespace gfx {
namespace {
class GLNonOwnedContext : public GLContextReal {
public:
GLNonOwnedContext(GLShareGroup* share_group);
virtual bool Initialize(GLSurface* compatible_surface,
GpuPreference gpu_preference) OVERRIDE;
virtual void Destroy() OVERRIDE {}
virtual bool MakeCurrent(GLSurface* surface) OVERRIDE;
virtual void ReleaseCurrent(GLSurface* surface) OVERRIDE {}
virtual bool IsCurrent(GLSurface* surface) OVERRIDE { return true; }
virtual void* GetHandle() OVERRIDE { return NULL; }
virtual void SetSwapInterval(int interval) OVERRIDE {}
virtual std::string GetExtensions() OVERRIDE;
protected:
virtual ~GLNonOwnedContext() {}
private:
DISALLOW_COPY_AND_ASSIGN(GLNonOwnedContext);
EGLDisplay display_;
};
GLNonOwnedContext::GLNonOwnedContext(GLShareGroup* share_group)
: GLContextReal(share_group), display_(NULL) {}
bool GLNonOwnedContext::Initialize(GLSurface* compatible_surface,
GpuPreference gpu_preference) {
display_ = eglGetDisplay(EGL_DEFAULT_DISPLAY);
return true;
}
bool GLNonOwnedContext::MakeCurrent(GLSurface* surface) {
SetCurrent(surface);
SetRealGLApi();
return true;
}
std::string GLNonOwnedContext::GetExtensions() {
const char* extensions = eglQueryString(display_, EGL_EXTENSIONS);
if (!extensions)
return GLContext::GetExtensions();
return GLContext::GetExtensions() + " " + extensions;
}
}
scoped_refptr<GLContext> GLContext::CreateGLContext(
GLShareGroup* share_group,
GLSurface* compatible_surface,
GpuPreference gpu_preference) {
scoped_refptr<GLContext> context;
switch (GetGLImplementation()) {
case kGLImplementationMockGL:
return scoped_refptr<GLContext>(new GLContextStub());
case kGLImplementationOSMesaGL:
context = new GLContextOSMesa(share_group);
break;
default:
if (compatible_surface->GetHandle())
context = new GLContextEGL(share_group);
else
context = new GLNonOwnedContext(share_group);
break;
}
if (!context->Initialize(compatible_surface, gpu_preference))
return NULL;
return context;
}
bool GLContextEGL::GetTotalGpuMemory(size_t* bytes) {
DCHECK(bytes);
*bytes = 0;
size_t dalvik_mb = base::SysInfo::DalvikHeapSizeMB();
size_t physical_mb = base::SysInfo::AmountOfPhysicalMemoryMB();
size_t physical_memory_mb = 0;
if (dalvik_mb >= 256)
physical_memory_mb = dalvik_mb * 4;
else
physical_memory_mb = std::max(dalvik_mb * 4,
(physical_mb * 4) / 3);
static size_t limit_bytes = 0;
if (limit_bytes == 0) {
if (!base::android::SysUtils::IsLowEndDevice()) {
if (physical_memory_mb >= 1536)
limit_bytes = physical_memory_mb / 8;
else if (physical_memory_mb >= 1152)
limit_bytes = physical_memory_mb / 8;
else if (physical_memory_mb >= 768)
limit_bytes = physical_memory_mb / 10;
else
limit_bytes = physical_memory_mb / 12;
} else {
limit_bytes = 12;
}
limit_bytes = limit_bytes * 1024 * 1024;
}
*bytes = limit_bytes;
return true;
}
}