1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
// Copyright (c) 2011 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.
#include "ui/gfx/surface/accelerated_surface_linux.h"
#include <X11/Xlib.h>
#include "third_party/angle/include/EGL/egl.h"
#include "third_party/angle/include/EGL/eglext.h"
#include "ui/gfx/gl/gl_surface_egl.h"
#include "ui/gfx/gl/gl_bindings.h"
AcceleratedSurface::AcceleratedSurface(const gfx::Size& size)
: size_(size) {
Display* dpy = gfx::GLSurfaceEGL::GetNativeDisplay();
EGLDisplay edpy = gfx::GLSurfaceEGL::GetHardwareDisplay();
XID window = XDefaultRootWindow(dpy);
XWindowAttributes gwa;
XGetWindowAttributes(dpy, window, &gwa);
pixmap_ = XCreatePixmap(
dpy, window, size_.width(), size_.height(), gwa.depth);
image_ = eglCreateImageKHR(
edpy, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, (void*) pixmap_, NULL);
glGenTextures(1, &texture_);
GLint current_texture = 0;
glGetIntegerv(GL_TEXTURE_BINDING_2D, ¤t_texture);
glBindTexture(GL_TEXTURE_2D, texture_);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image_);
glBindTexture(GL_TEXTURE_2D, current_texture);
}
AcceleratedSurface::~AcceleratedSurface() {
glDeleteTextures(1, &texture_);
eglDestroyImageKHR(gfx::GLSurfaceEGL::GetHardwareDisplay(), image_);
XFreePixmap(gfx::GLSurfaceEGL::GetNativeDisplay(), pixmap_);
}
|