| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#ifndef ANDROID_HWUI_UV_MAPPER_H |
| 18 |
#define ANDROID_HWUI_UV_MAPPER_H |
| 19 |
|
| 20 |
#include "Rect.h" |
| 21 |
|
| 22 |
namespace android { |
| 23 |
namespace uirenderer { |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
class UvMapper { |
| 31 |
public: |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
UvMapper() : mIdentity(true), mMinU(0.0f), mMaxU(1.0f), mMinV(0.0f), mMaxV(1.0f) {} |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
UvMapper(float minU, float maxU, float minV, float maxV) |
| 43 |
: mMinU(minU), mMaxU(maxU), mMinV(minV), mMaxV(maxV) { |
| 44 |
checkIdentity(); |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
bool isIdentity() const { return mIdentity; } |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
void setMapping(float minU, float maxU, float minV, float maxV) { |
| 58 |
mMinU = minU; |
| 59 |
mMaxU = maxU; |
| 60 |
mMinV = minV; |
| 61 |
mMaxV = maxV; |
| 62 |
checkIdentity(); |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
void mapU(float& u) const { |
| 69 |
if (!mIdentity) u = lerp(mMinU, mMaxU, u); |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
void mapV(float& v) const { |
| 76 |
if (!mIdentity) v = lerp(mMinV, mMaxV, v); |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
void map(Rect& texCoords) const { |
| 87 |
if (!mIdentity) { |
| 88 |
texCoords.left = lerp(mMinU, mMaxU, texCoords.left); |
| 89 |
texCoords.right = lerp(mMinU, mMaxU, texCoords.right); |
| 90 |
texCoords.top = lerp(mMinV, mMaxV, texCoords.top); |
| 91 |
texCoords.bottom = lerp(mMinV, mMaxV, texCoords.bottom); |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
void map(float& u1, float& v1, float& u2, float& v2) const { |
| 99 |
if (!mIdentity) { |
| 100 |
u1 = lerp(mMinU, mMaxU, u1); |
| 101 |
u2 = lerp(mMinU, mMaxU, u2); |
| 102 |
v1 = lerp(mMinV, mMaxV, v1); |
| 103 |
v2 = lerp(mMinV, mMaxV, v2); |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
void dump() const { |
| 108 |
ALOGD("mapper[minU=%.2f maxU=%.2f minV=%.2f maxV=%.2f]", mMinU, mMaxU, mMinV, mMaxV); |
| 109 |
} |
| 110 |
|
| 111 |
private: |
| 112 |
static float lerp(float start, float stop, float amount) { |
| 113 |
return start + (stop - start) * amount; |
| 114 |
} |
| 115 |
|
| 116 |
void checkIdentity() { |
| 117 |
mIdentity = mMinU == 0.0f && mMaxU == 1.0f && mMinV == 0.0f && mMaxV == 1.0f; |
| 118 |
} |
| 119 |
|
| 120 |
bool mIdentity; |
| 121 |
float mMinU; |
| 122 |
float mMaxU; |
| 123 |
float mMinV; |
| 124 |
float mMaxV; |
| 125 |
}; |
| 126 |
|
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
#endif |