| 1 |
#pragma once |
| 2 |
|
| 3 |
// This is a shim of several macros/functions/types |
| 4 |
// that is needed to compile stripped pdium code |
| 5 |
|
| 6 |
#include <cstring> |
| 7 |
#include <vector> |
| 8 |
#include <algorithm> |
| 9 |
#include <numerics/safe_math.h> |
| 10 |
|
| 11 |
#define DCHECK(cond) |
| 12 |
#define DCHECK_EQ(x, y) |
| 13 |
|
| 14 |
namespace fxcrt |
| 15 |
{ |
| 16 |
template <typename T> |
| 17 |
using DataVector = std::vector<T>; |
| 18 |
} |
| 19 |
|
| 20 |
using fxcrt::DataVector; |
| 21 |
|
| 22 |
// Round up to the power-of-two boundary N. |
| 23 |
template <int N, typename T> |
| 24 |
inline T FxAlignToBoundary(T size) { |
| 25 |
static_assert(N > 0 && (N & (N - 1)) == 0, "Not non-zero power of two"); |
| 26 |
return (size + (N - 1)) & ~(N - 1); |
| 27 |
} |
| 28 |
|
| 29 |
namespace pdfium |
| 30 |
{ |
| 31 |
template <typename T> |
| 32 |
constexpr const T& clamp(const T& v, const T& lo, const T& hi) |
| 33 |
{ |
| 34 |
return v < lo ? lo : hi < v ? hi : v; |
| 35 |
} |
| 36 |
|
| 37 |
namespace base = chromium::base; |
| 38 |
} |
| 39 |
|
| 40 |
using FX_SAFE_UINT32 = chromium::base::CheckedNumeric<uint32_t>; |
| 41 |
|
| 42 |
namespace fxge |
| 43 |
{ |
| 44 |
inline FX_SAFE_UINT32 CalculatePitch32Safely(int bpp, int width) |
| 45 |
{ |
| 46 |
FX_SAFE_UINT32 pitch = bpp; |
| 47 |
pitch *= width; |
| 48 |
pitch += 31; |
| 49 |
pitch /= 32; // quantized to number of 32-bit words. |
| 50 |
pitch *= 4; // and then back to bytes, (not just /8 in one step). |
| 51 |
return pitch; |
| 52 |
} |
| 53 |
|
| 54 |
inline uint32_t CalculatePitch32OrDie(int bpp, int width) { |
| 55 |
return CalculatePitch32Safely(bpp, width).ValueOrDie(); |
| 56 |
} |
| 57 |
} |