gfx/angle/src/libGLESv2/renderer/vertexconversion.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 //
michael@0 2 // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
michael@0 3 // Use of this source code is governed by a BSD-style license that can be
michael@0 4 // found in the LICENSE file.
michael@0 5 //
michael@0 6
michael@0 7 // vertexconversion.h: A library of vertex conversion classes that can be used to build
michael@0 8 // the FormatConverter objects used by the buffer conversion system.
michael@0 9
michael@0 10 #ifndef LIBGLESV2_VERTEXCONVERSION_H_
michael@0 11 #define LIBGLESV2_VERTEXCONVERSION_H_
michael@0 12
michael@0 13 namespace rx
michael@0 14 {
michael@0 15
michael@0 16 // Conversion types:
michael@0 17 // static const bool identity: true if this is an identity transform, false otherwise
michael@0 18 // static U convert(T): convert a single element from the input type to the output type
michael@0 19 // typedef ... OutputType: the type produced by this conversion
michael@0 20
michael@0 21 template <class T>
michael@0 22 struct Identity
michael@0 23 {
michael@0 24 static const bool identity = true;
michael@0 25
michael@0 26 typedef T OutputType;
michael@0 27
michael@0 28 static T convert(T x)
michael@0 29 {
michael@0 30 return x;
michael@0 31 }
michael@0 32 };
michael@0 33
michael@0 34 template <class FromT, class ToT>
michael@0 35 struct Cast
michael@0 36 {
michael@0 37 static const bool identity = false;
michael@0 38
michael@0 39 typedef ToT OutputType;
michael@0 40
michael@0 41 static ToT convert(FromT x)
michael@0 42 {
michael@0 43 return static_cast<ToT>(x);
michael@0 44 }
michael@0 45 };
michael@0 46
michael@0 47 template <class T>
michael@0 48 struct Cast<T, T>
michael@0 49 {
michael@0 50 static const bool identity = true;
michael@0 51
michael@0 52 typedef T OutputType;
michael@0 53
michael@0 54 static T convert(T x)
michael@0 55 {
michael@0 56 return static_cast<T>(x);
michael@0 57 }
michael@0 58 };
michael@0 59
michael@0 60 template <class T>
michael@0 61 struct Normalize
michael@0 62 {
michael@0 63 static const bool identity = false;
michael@0 64
michael@0 65 typedef float OutputType;
michael@0 66
michael@0 67 static float convert(T x)
michael@0 68 {
michael@0 69 typedef std::numeric_limits<T> NL;
michael@0 70 float f = static_cast<float>(x);
michael@0 71
michael@0 72 if (NL::is_signed)
michael@0 73 {
michael@0 74 // const float => VC2008 computes it at compile time
michael@0 75 // static const float => VC2008 computes it the first time we get here, stores it to memory with static guard and all that.
michael@0 76 const float divisor = 1.0f/(2*static_cast<float>(NL::max())+1);
michael@0 77 return (2*f+1)*divisor;
michael@0 78 }
michael@0 79 else
michael@0 80 {
michael@0 81 return f/NL::max();
michael@0 82 }
michael@0 83 }
michael@0 84 };
michael@0 85
michael@0 86 template <class FromType, std::size_t ScaleBits>
michael@0 87 struct FixedToFloat
michael@0 88 {
michael@0 89 static const bool identity = false;
michael@0 90
michael@0 91 typedef float OutputType;
michael@0 92
michael@0 93 static float convert(FromType x)
michael@0 94 {
michael@0 95 const float divisor = 1.0f / static_cast<float>(static_cast<FromType>(1) << ScaleBits);
michael@0 96 return static_cast<float>(x) * divisor;
michael@0 97 }
michael@0 98 };
michael@0 99
michael@0 100 // Widen types:
michael@0 101 // static const unsigned int initialWidth: number of components before conversion
michael@0 102 // static const unsigned int finalWidth: number of components after conversion
michael@0 103
michael@0 104 // Float is supported at any size.
michael@0 105 template <std::size_t N>
michael@0 106 struct NoWiden
michael@0 107 {
michael@0 108 static const std::size_t initialWidth = N;
michael@0 109 static const std::size_t finalWidth = N;
michael@0 110 };
michael@0 111
michael@0 112 // SHORT, norm-SHORT, norm-UNSIGNED_SHORT are supported but only with 2 or 4 components
michael@0 113 template <std::size_t N>
michael@0 114 struct WidenToEven
michael@0 115 {
michael@0 116 static const std::size_t initialWidth = N;
michael@0 117 static const std::size_t finalWidth = N+(N&1);
michael@0 118 };
michael@0 119
michael@0 120 template <std::size_t N>
michael@0 121 struct WidenToFour
michael@0 122 {
michael@0 123 static const std::size_t initialWidth = N;
michael@0 124 static const std::size_t finalWidth = 4;
michael@0 125 };
michael@0 126
michael@0 127 // Most types have 0 and 1 that are just that.
michael@0 128 template <class T>
michael@0 129 struct SimpleDefaultValues
michael@0 130 {
michael@0 131 static T zero() { return static_cast<T>(0); }
michael@0 132 static T one() { return static_cast<T>(1); }
michael@0 133 };
michael@0 134
michael@0 135 // But normalised types only store [0,1] or [-1,1] so 1.0 is represented by the max value.
michael@0 136 template <class T>
michael@0 137 struct NormalizedDefaultValues
michael@0 138 {
michael@0 139 static T zero() { return static_cast<T>(0); }
michael@0 140 static T one() { return std::numeric_limits<T>::max(); }
michael@0 141 };
michael@0 142
michael@0 143 // Converter:
michael@0 144 // static const bool identity: true if this is an identity transform (with no widening)
michael@0 145 // static const std::size_t finalSize: number of bytes per output vertex
michael@0 146 // static void convertArray(const void *in, std::size_t stride, std::size_t n, void *out): convert an array of vertices. Input may be strided, but output will be unstrided.
michael@0 147
michael@0 148 template <class InT, class WidenRule, class Converter, class DefaultValueRule = SimpleDefaultValues<InT> >
michael@0 149 struct VertexDataConverter
michael@0 150 {
michael@0 151 typedef typename Converter::OutputType OutputType;
michael@0 152 typedef InT InputType;
michael@0 153
michael@0 154 static const bool identity = (WidenRule::initialWidth == WidenRule::finalWidth) && Converter::identity;
michael@0 155 static const std::size_t finalSize = WidenRule::finalWidth * sizeof(OutputType);
michael@0 156
michael@0 157 static void convertArray(const InputType *in, std::size_t stride, std::size_t n, OutputType *out)
michael@0 158 {
michael@0 159 for (std::size_t i = 0; i < n; i++)
michael@0 160 {
michael@0 161 const InputType *ein = pointerAddBytes(in, i * stride);
michael@0 162
michael@0 163 copyComponent(out, ein, 0, static_cast<OutputType>(DefaultValueRule::zero()));
michael@0 164 copyComponent(out, ein, 1, static_cast<OutputType>(DefaultValueRule::zero()));
michael@0 165 copyComponent(out, ein, 2, static_cast<OutputType>(DefaultValueRule::zero()));
michael@0 166 copyComponent(out, ein, 3, static_cast<OutputType>(DefaultValueRule::one()));
michael@0 167
michael@0 168 out += WidenRule::finalWidth;
michael@0 169 }
michael@0 170 }
michael@0 171
michael@0 172 static void convertArray(const void *in, std::size_t stride, std::size_t n, void *out)
michael@0 173 {
michael@0 174 return convertArray(static_cast<const InputType*>(in), stride, n, static_cast<OutputType*>(out));
michael@0 175 }
michael@0 176
michael@0 177 private:
michael@0 178 // Advance the given pointer by a number of bytes (not pointed-to elements).
michael@0 179 template <class T>
michael@0 180 static T *pointerAddBytes(T *basePtr, std::size_t numBytes)
michael@0 181 {
michael@0 182 return reinterpret_cast<T *>(reinterpret_cast<uintptr_t>(basePtr) + numBytes);
michael@0 183 }
michael@0 184
michael@0 185 static void copyComponent(OutputType *out, const InputType *in, std::size_t elementindex, OutputType defaultvalue)
michael@0 186 {
michael@0 187 if (WidenRule::finalWidth > elementindex)
michael@0 188 {
michael@0 189 if (WidenRule::initialWidth > elementindex)
michael@0 190 {
michael@0 191 out[elementindex] = Converter::convert(in[elementindex]);
michael@0 192 }
michael@0 193 else
michael@0 194 {
michael@0 195 out[elementindex] = defaultvalue;
michael@0 196 }
michael@0 197 }
michael@0 198 }
michael@0 199 };
michael@0 200
michael@0 201 }
michael@0 202
michael@0 203 #endif // LIBGLESV2_VERTEXCONVERSION_H_

mercurial