2 * OpenGL ES 2.0 memory performance estimator
3 * Copyright (C) 2009 Nokia
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 * \author Sami Kyöstilä <sami.kyostila@nokia.com>
21 * X11 pixmap surface test using shared memory and eglBindTexImage
23 #include "pixmapblittest.h"
28 #include <X11/Xutil.h>
30 template <typename TYPE>
31 void fillImage(XImage& img)
33 TYPE* d = reinterpret_cast<TYPE*>(img.data);
35 for (int y = 0; y < img.height; y++)
37 for (int x = 0; x < img.width; x++)
41 d += img.bytes_per_line / sizeof(TYPE);
45 PixmapBlitTest::PixmapBlitTest(int width, int height, EGLConfig config,
46 bool rotate, float texW, float texH):
47 BlitTest(width, height, rotate, texW, texH),
50 eglGetConfigAttrib(ctx.dpy, m_config, EGL_BUFFER_SIZE, &m_depth);
53 void PixmapBlitTest::prepare()
55 if (!isEGLExtensionSupported("EGL_NOKIA_texture_from_pixmap"))
57 fail("EGL_NOKIA_texture_from_pixmap not supported");
65 success = nativeCreatePixmap(ctx.nativeDisplay, ctx.dpy, m_config, m_width,
69 success = fillPixmap();
72 const EGLint surfAttrs[] =
74 EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGB,
75 EGL_TEXTURE_TARGET, EGL_TEXTURE_2D,
76 EGL_MIPMAP_TEXTURE, EGL_FALSE,
80 m_surface = eglCreatePixmapSurface(ctx.dpy, m_config, m_pixmap, surfAttrs);
81 assert(m_surface != EGL_NO_SURFACE);
83 success = eglBindTexImage(ctx.dpy, m_surface, EGL_BACK_BUFFER);
89 bool PixmapBlitTest::fillPixmap()
91 XImage* img = XGetImage(ctx.nativeDisplay, m_pixmap, 0, 0, m_width, m_height, ~0, ZPixmap);
102 fillImage<uint16_t>(*img);
105 fillImage<uint32_t>(*img);
108 assert(!"Unknown pixmap depth");
113 GC gc = XCreateGC(ctx.nativeDisplay, m_pixmap, 0, &gcValues);
114 XPutImage(ctx.nativeDisplay, m_pixmap, gc, img, 0, 0, 0, 0, m_width, m_height);
115 XFreeGC(ctx.nativeDisplay, gc);
121 void PixmapBlitTest::teardown()
123 eglReleaseTexImage(ctx.dpy, m_surface, EGL_BACK_BUFFER);
124 eglDestroySurface(ctx.dpy, m_surface);
125 nativeDestroyPixmap(ctx.nativeDisplay, m_pixmap);
126 BlitTest::teardown();
129 std::string PixmapBlitTest::name() const
135 s << "blit_pixmap_rot90_";
152 s << "_" << m_width << "x" << m_height;