1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #include "Types.h"
8 
9 #include "nsPrintfCString.h"
10 
11 #include <ostream>
12 
13 namespace mozilla {
14 
operator <<(std::ostream & aOut,const Side & aSide)15 std::ostream& operator<<(std::ostream& aOut, const Side& aSide) {
16 #define Emit(x) \
17   case x:       \
18     aOut << #x; \
19     break
20 
21   switch (aSide) {
22     Emit(eSideTop);
23     Emit(eSideBottom);
24     Emit(eSideLeft);
25     Emit(eSideRight);
26     default:
27       NS_ERROR("unknown side");
28       aOut << int(aSide);
29       break;
30   }
31 
32 #undef Emit
33   return aOut;
34 }
35 
36 namespace gfx {
37 
operator <<(std::ostream & aOut,const SurfaceFormat & aFormat)38 std::ostream& operator<<(std::ostream& aOut, const SurfaceFormat& aFormat) {
39 #define Emit(x) \
40   case x:       \
41     aOut << #x; \
42     break
43 
44   switch (aFormat) {
45     Emit(SurfaceFormat::B8G8R8A8);
46     Emit(SurfaceFormat::B8G8R8X8);
47     Emit(SurfaceFormat::R8G8B8A8);
48     Emit(SurfaceFormat::R8G8B8X8);
49     Emit(SurfaceFormat::A8R8G8B8);
50     Emit(SurfaceFormat::X8R8G8B8);
51     Emit(SurfaceFormat::R8G8B8);
52     Emit(SurfaceFormat::B8G8R8);
53     Emit(SurfaceFormat::R5G6B5_UINT16);
54     Emit(SurfaceFormat::A8);
55     Emit(SurfaceFormat::A16);
56     Emit(SurfaceFormat::R8G8);
57     Emit(SurfaceFormat::R16G16);
58     Emit(SurfaceFormat::YUV);
59     Emit(SurfaceFormat::NV12);
60     Emit(SurfaceFormat::P016);
61     Emit(SurfaceFormat::P010);
62     Emit(SurfaceFormat::YUV422);
63     Emit(SurfaceFormat::HSV);
64     Emit(SurfaceFormat::Lab);
65     Emit(SurfaceFormat::Depth);
66     default:
67       NS_ERROR("unknown surface format");
68       aOut << "???";
69   }
70 
71 #undef Emit
72 
73   return aOut;
74 }
75 
operator <<(std::ostream & aOut,const DeviceColor & aColor)76 std::ostream& operator<<(std::ostream& aOut, const DeviceColor& aColor) {
77   aOut << nsPrintfCString("dev_rgba(%d, %d, %d, %f)", uint8_t(aColor.r * 255.f),
78                           uint8_t(aColor.g * 255.f), uint8_t(aColor.b * 255.f),
79                           aColor.a)
80               .get();
81   return aOut;
82 }
83 
operator <<(std::ostream & aOut,const SamplingFilter & aFilter)84 std::ostream& operator<<(std::ostream& aOut, const SamplingFilter& aFilter) {
85   switch (aFilter) {
86     case SamplingFilter::GOOD:
87       aOut << "SamplingFilter::GOOD";
88       break;
89     case SamplingFilter::LINEAR:
90       aOut << "SamplingFilter::LINEAR";
91       break;
92     case SamplingFilter::POINT:
93       aOut << "SamplingFilter::POINT";
94       break;
95     default:
96       aOut << "???";
97   }
98   return aOut;
99 }
100 
101 }  // namespace gfx
102 }  // namespace mozilla
103