Commit 52445286 by Corentin Wallez

Add a OSPixmap class to have cross platform pixmaps

This will help make the deqp support code platform agnostic. BUG=angleproject:892 Change-Id: I6f8c738ed8125057db87afea2079583f8feac977 Reviewed-on: https://chromium-review.googlesource.com/276201Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Tested-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent ce991cf6
......@@ -28,6 +28,7 @@
#include "deThread.h"
#include "egluDefs.hpp"
#include "eglwLibrary.hpp"
#include "OSPixmap.h"
#include "OSWindow.h"
#include "tcuTexture.hpp"
#include "tcuWin32API.h"
......@@ -90,13 +91,13 @@ class NativePixmapFactory : public eglu::NativePixmapFactory
class NativePixmap : public eglu::NativePixmap
{
public:
NativePixmap(ANGLENativeDisplay* nativeDisplay, int width, int height, int bitDepth);
NativePixmap(EGLNativeDisplayType display, int width, int height, int bitDepth);
virtual ~NativePixmap();
eglw::EGLNativePixmapType getLegacyNative() override { return mBitmap; }
eglw::EGLNativePixmapType getLegacyNative() override;
private:
HBITMAP mBitmap;
OSPixmap *mPixmap;
};
class NativeWindowFactory : public eglu::NativeWindowFactory
......@@ -142,40 +143,29 @@ ANGLENativeDisplay::ANGLENativeDisplay(const std::vector<EGLAttrib> &attribs)
// NativePixmap
NativePixmap::NativePixmap(ANGLENativeDisplay *nativeDisplay, int width, int height, int bitDepth)
NativePixmap::NativePixmap(EGLNativeDisplayType display, int width, int height, int bitDepth)
: eglu::NativePixmap(BITMAP_CAPABILITIES),
mBitmap(DE_NULL)
mPixmap(CreateOSPixmap())
{
const HDC deviceCtx = nativeDisplay->getDeviceContext();
BITMAPINFO bitmapInfo;
memset(&bitmapInfo, 0, sizeof(bitmapInfo));
if (bitDepth != 24 && bitDepth != 32)
throw NotSupportedError("Unsupported pixmap bit depth", DE_NULL, __FILE__, __LINE__);
bitmapInfo.bmiHeader.biSize = sizeof(bitmapInfo);
bitmapInfo.bmiHeader.biWidth = width;
bitmapInfo.bmiHeader.biHeight = height;
bitmapInfo.bmiHeader.biPlanes = 1;
bitmapInfo.bmiHeader.biBitCount = bitDepth;
bitmapInfo.bmiHeader.biCompression = BI_RGB;
bitmapInfo.bmiHeader.biSizeImage = 0;
bitmapInfo.bmiHeader.biXPelsPerMeter = 1;
bitmapInfo.bmiHeader.biYPelsPerMeter = 1;
bitmapInfo.bmiHeader.biClrUsed = 0;
bitmapInfo.bmiHeader.biClrImportant = 0;
void* bitmapPtr = DE_NULL;
mBitmap = CreateDIBSection(deviceCtx, &bitmapInfo, DIB_RGB_COLORS, &bitmapPtr, NULL, 0);
if (!mBitmap)
throw ResourceError("Failed to create bitmap", DE_NULL, __FILE__, __LINE__);
if (!mPixmap)
{
throw ResourceError("Failed to create pixmap", DE_NULL, __FILE__, __LINE__);
}
if (!mPixmap->initialize(display, width, height, bitDepth))
{
throw ResourceError("Failed to initialize pixmap", DE_NULL, __FILE__, __LINE__);
}
}
NativePixmap::~NativePixmap()
{
DeleteObject(mBitmap);
delete mPixmap;
}
eglw::EGLNativePixmapType NativePixmap::getLegacyNative()
{
return mPixmap->getNativePixmap();
}
// NativePixmapFactory
......@@ -204,13 +194,13 @@ eglu::NativePixmap *NativePixmapFactory::createPixmap (eglu::NativeDisplay* nati
bitSum = redBits+greenBits+blueBits+alphaBits;
return new NativePixmap(dynamic_cast<ANGLENativeDisplay*>(nativeDisplay), width, height, bitSum);
return new NativePixmap(dynamic_cast<ANGLENativeDisplay*>(nativeDisplay)->getDeviceContext(), width, height, bitSum);
}
eglu::NativePixmap *NativePixmapFactory::createPixmap(eglu::NativeDisplay* nativeDisplay, int width, int height) const
{
const int defaultDepth = 32;
return new NativePixmap(dynamic_cast<ANGLENativeDisplay*>(nativeDisplay), width, height, defaultDepth);
return new NativePixmap(dynamic_cast<ANGLENativeDisplay*>(nativeDisplay)->getDeviceContext(), width, height, defaultDepth);
}
// NativeWindowFactory
......
//
// Copyright (c) 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// OSPixmap.h: Definition of an abstract pixmap class
#ifndef SAMPLE_UTIL_PIXMAP_H_
#define SAMPLE_UTIL_PIXMAP_H_
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include "Event.h"
class OSPixmap
{
public:
OSPixmap() {}
virtual ~OSPixmap() {}
virtual bool initialize(EGLNativeDisplayType display, size_t width, size_t height, int depth) = 0;
virtual EGLNativePixmapType getNativePixmap() const = 0;
};
OSPixmap *CreateOSPixmap();
#endif // SAMPLE_UTIL_PIXMAP_H_
......@@ -18,6 +18,7 @@
'Event.h',
'EGLWindow.cpp',
'EGLWindow.h',
'OSPixmap.h',
'OSWindow.cpp',
'OSWindow.h',
'Timer.h',
......@@ -25,6 +26,8 @@
'util_win32_sources':
[
'win32/Win32_system_utils.cpp',
'win32/Win32Pixmap.cpp',
'win32/Win32Pixmap.h',
'win32/Win32Timer.cpp',
'win32/Win32Timer.h',
'win32/Win32Window.cpp',
......@@ -39,6 +42,8 @@
],
'util_x11_sources':
[
'x11/X11Pixmap.cpp',
'x11/X11Pixmap.h',
'x11/X11Window.cpp',
'x11/X11Window.h',
],
......
//
// Copyright (c) 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Win32Pixmap.cpp: Implementation of OSPixmap for Windows
#include "win32/Win32Pixmap.h"
Win32Pixmap::Win32Pixmap()
: mBitmap(nullptr)
{
}
Win32Pixmap::~Win32Pixmap()
{
if (mBitmap)
{
DeleteObject(mBitmap);
}
}
bool Win32Pixmap::initialize(EGLNativeDisplayType display, size_t width, size_t height, int depth)
{
BITMAPINFO bitmapInfo;
memset(&bitmapInfo, 0, sizeof(bitmapInfo));
if (depth != 24 && depth != 32)
{
return false;
}
bitmapInfo.bmiHeader.biSize = sizeof(bitmapInfo);
bitmapInfo.bmiHeader.biWidth = width;
bitmapInfo.bmiHeader.biHeight = height;
bitmapInfo.bmiHeader.biPlanes = 1;
bitmapInfo.bmiHeader.biBitCount = static_cast<WORD>(depth);
bitmapInfo.bmiHeader.biCompression = BI_RGB;
bitmapInfo.bmiHeader.biSizeImage = 0;
bitmapInfo.bmiHeader.biXPelsPerMeter = 1;
bitmapInfo.bmiHeader.biYPelsPerMeter = 1;
bitmapInfo.bmiHeader.biClrUsed = 0;
bitmapInfo.bmiHeader.biClrImportant = 0;
void *bitmapPtr = nullptr;
mBitmap = CreateDIBSection(display, &bitmapInfo, DIB_RGB_COLORS, &bitmapPtr, nullptr, 0);
return mBitmap != nullptr;
}
EGLNativePixmapType Win32Pixmap::getNativePixmap() const
{
return mBitmap;
}
OSPixmap *CreateOSPixmap()
{
return new Win32Pixmap();
}
//
// Copyright (c) 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Win32Pixmap.h: Definition of the implementation of OSPixmap for Windows
#ifndef UTIL_WIN32_PIXMAP_H_
#define UTIL_WIN32_PIXMAP_H_
#include <windows.h>
#include "OSPixmap.h"
class Win32Pixmap : public OSPixmap
{
public:
Win32Pixmap();
~Win32Pixmap() override;
bool initialize(EGLNativeDisplayType display, size_t width, size_t height, int depth) override;
EGLNativePixmapType getNativePixmap() const override;
private:
HBITMAP mBitmap;
};
#endif // UTIL_WIN32_PIXMAP_H_
//
// Copyright (c) 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// X11Pixmap.cpp: Implementation of OSPixmap for X11
#include "x11/X11Pixmap.h"
X11Pixmap::X11Pixmap()
: mPixmap(0),
mDisplay(nullptr)
{
}
X11Pixmap::~X11Pixmap()
{
if (mPixmap)
{
XFreePixmap(mDisplay, mPixmap);
}
}
bool X11Pixmap::initialize(EGLNativeDisplayType display, size_t width, size_t height, int depth)
{
mDisplay = display;
int screen = DefaultScreen(mDisplay);
Window root = RootWindow(mDisplay, screen);
mPixmap = XCreatePixmap(mDisplay, root, width, height, depth);
return mPixmap != 0;
}
EGLNativePixmapType X11Pixmap::getNativePixmap() const
{
return mPixmap;
}
OSPixmap *CreateOSPixmap()
{
return new X11Pixmap();
}
//
// Copyright (c) 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// X11Pixmap.h: Definition of the implementation of OSPixmap for X11
#ifndef UTIL_X11_PIXMAP_H_
#define UTIL_X11_PIXMAP_H_
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "OSPixmap.h"
class X11Pixmap : public OSPixmap
{
public:
X11Pixmap();
~X11Pixmap() override;
bool initialize(EGLNativeDisplayType display, size_t width, size_t height, int depth) override;
EGLNativePixmapType getNativePixmap() const override;
private:
Pixmap mPixmap;
Display *mDisplay;
};
#endif // UTIL_WIN32_PIXMAP_H_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment