1e5c31af7Sopenharmony_ci#ifndef _TCUSURFACEACCESS_HPP
2e5c31af7Sopenharmony_ci#define _TCUSURFACEACCESS_HPP
3e5c31af7Sopenharmony_ci/*-------------------------------------------------------------------------
4e5c31af7Sopenharmony_ci * drawElements Quality Program Tester Core
5e5c31af7Sopenharmony_ci * ----------------------------------------
6e5c31af7Sopenharmony_ci *
7e5c31af7Sopenharmony_ci * Copyright 2014 The Android Open Source Project
8e5c31af7Sopenharmony_ci *
9e5c31af7Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
10e5c31af7Sopenharmony_ci * you may not use this file except in compliance with the License.
11e5c31af7Sopenharmony_ci * You may obtain a copy of the License at
12e5c31af7Sopenharmony_ci *
13e5c31af7Sopenharmony_ci *      http://www.apache.org/licenses/LICENSE-2.0
14e5c31af7Sopenharmony_ci *
15e5c31af7Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
16e5c31af7Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
17e5c31af7Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18e5c31af7Sopenharmony_ci * See the License for the specific language governing permissions and
19e5c31af7Sopenharmony_ci * limitations under the License.
20e5c31af7Sopenharmony_ci *
21e5c31af7Sopenharmony_ci *//*!
22e5c31af7Sopenharmony_ci * \file
23e5c31af7Sopenharmony_ci * \brief Surface access class.
24e5c31af7Sopenharmony_ci *//*--------------------------------------------------------------------*/
25e5c31af7Sopenharmony_ci
26e5c31af7Sopenharmony_ci#include "tcuDefs.hpp"
27e5c31af7Sopenharmony_ci#include "tcuTextureUtil.hpp"
28e5c31af7Sopenharmony_ci#include "tcuPixelFormat.hpp"
29e5c31af7Sopenharmony_ci#include "tcuSurface.hpp"
30e5c31af7Sopenharmony_ci
31e5c31af7Sopenharmony_cinamespace tcu
32e5c31af7Sopenharmony_ci{
33e5c31af7Sopenharmony_ci
34e5c31af7Sopenharmony_ciinline deUint8 getColorMask (const tcu::PixelFormat& format)
35e5c31af7Sopenharmony_ci{
36e5c31af7Sopenharmony_ci	return (deUint8)((format.redBits	? tcu::RGBA::RED_MASK	: 0) |
37e5c31af7Sopenharmony_ci					 (format.greenBits	? tcu::RGBA::GREEN_MASK	: 0) |
38e5c31af7Sopenharmony_ci					 (format.blueBits	? tcu::RGBA::BLUE_MASK	: 0) |
39e5c31af7Sopenharmony_ci					 (format.alphaBits	? tcu::RGBA::ALPHA_MASK	: 0));
40e5c31af7Sopenharmony_ci}
41e5c31af7Sopenharmony_ci
42e5c31af7Sopenharmony_ciinline tcu::RGBA toRGBAMasked (const tcu::Vec4& v, deUint8 mask)
43e5c31af7Sopenharmony_ci{
44e5c31af7Sopenharmony_ci	return tcu::RGBA((mask&tcu::RGBA::RED_MASK)		? tcu::floatToU8(v.x()) : 0,
45e5c31af7Sopenharmony_ci					 (mask&tcu::RGBA::GREEN_MASK)	? tcu::floatToU8(v.y()) : 0,
46e5c31af7Sopenharmony_ci					 (mask&tcu::RGBA::BLUE_MASK)	? tcu::floatToU8(v.z()) : 0,
47e5c31af7Sopenharmony_ci					 (mask&tcu::RGBA::ALPHA_MASK)	? tcu::floatToU8(v.w()) : 0xFF); //!< \note Alpha defaults to full saturation when reading masked format
48e5c31af7Sopenharmony_ci}
49e5c31af7Sopenharmony_ci
50e5c31af7Sopenharmony_ciclass SurfaceAccess
51e5c31af7Sopenharmony_ci{
52e5c31af7Sopenharmony_cipublic:
53e5c31af7Sopenharmony_ci							SurfaceAccess		(tcu::Surface& surface, const tcu::PixelFormat& colorFmt);
54e5c31af7Sopenharmony_ci							SurfaceAccess		(tcu::Surface& surface, const tcu::PixelFormat& colorFmt, int x, int y, int width, int height);
55e5c31af7Sopenharmony_ci							SurfaceAccess		(const SurfaceAccess& parent, int x, int y, int width, int height);
56e5c31af7Sopenharmony_ci
57e5c31af7Sopenharmony_ci	int						getWidth			(void) const	{ return m_width;	}
58e5c31af7Sopenharmony_ci	int						getHeight			(void) const	{ return m_height;	}
59e5c31af7Sopenharmony_ci
60e5c31af7Sopenharmony_ci	void					setPixel			(const tcu::Vec4& color, int x, int y) const;
61e5c31af7Sopenharmony_ci
62e5c31af7Sopenharmony_ciprivate:
63e5c31af7Sopenharmony_ci	mutable tcu::Surface*	m_surface;
64e5c31af7Sopenharmony_ci	deUint8					m_colorMask;
65e5c31af7Sopenharmony_ci	int						m_x;
66e5c31af7Sopenharmony_ci	int						m_y;
67e5c31af7Sopenharmony_ci	int						m_width;
68e5c31af7Sopenharmony_ci	int						m_height;
69e5c31af7Sopenharmony_ci};
70e5c31af7Sopenharmony_ci
71e5c31af7Sopenharmony_ciinline void SurfaceAccess::setPixel (const tcu::Vec4& color, int x, int y) const
72e5c31af7Sopenharmony_ci{
73e5c31af7Sopenharmony_ci	DE_ASSERT(de::inBounds(x, 0, m_width) && de::inBounds(y, 0, m_height));
74e5c31af7Sopenharmony_ci	m_surface->setPixel(m_x+x, m_y+y, toRGBAMasked(color, m_colorMask));
75e5c31af7Sopenharmony_ci}
76e5c31af7Sopenharmony_ci
77e5c31af7Sopenharmony_ci} // tcu
78e5c31af7Sopenharmony_ci
79e5c31af7Sopenharmony_ci#endif // _TCUSURFACEACCESS_HPP
80