Bug 1070018 - Log HRESULT error codes as hexadecimal values rather than signed integers. r=Bas
authorNicolas Silva <nsilva@mozilla.com>
Tue, 23 Sep 2014 11:35:39 -0400
changeset 231248 cad0abc497cf549f35a9e183f57f4d984d4e9082
parent 231247 1c34f6f342cd464961f8b08c0a23a4b4f2959ed3
child 231249 8abfd1252969ffb55aed837f696df79016d89fd0
push idunknown
push userunknown
push dateunknown
reviewersBas
bugs1070018
milestone35.0a1
Bug 1070018 - Log HRESULT error codes as hexadecimal values rather than signed integers. r=Bas
gfx/2d/DrawTargetD2D.cpp
gfx/2d/DrawTargetD2D1.cpp
gfx/2d/FilterNodeD2D1.cpp
gfx/2d/Logging.h
gfx/2d/PathD2D.cpp
gfx/2d/RadialGradientEffectD2D1.cpp
gfx/2d/SourceSurfaceD2D.cpp
gfx/2d/SourceSurfaceD2DTarget.cpp
gfx/layers/d3d11/TextureD3D11.cpp
--- a/gfx/2d/DrawTargetD2D.cpp
+++ b/gfx/2d/DrawTargetD2D.cpp
@@ -71,34 +71,34 @@ public:
     SurfaceFormat format = mDT->mFormat;
 
     CD3D10_TEXTURE2D_DESC desc(DXGIFormat(format), size.width, size.height,
                                1, 1);
     desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
 
     HRESULT hr = mDT->mDevice->CreateTexture2D(&desc, nullptr, byRef(tmpTexture));
     if (FAILED(hr)) {
-      gfxCriticalError() << "[D2D] CreateTexture2D failure " << size << " Code: " << hr;
+      gfxCriticalError() << "[D2D] CreateTexture2D failure " << size << " Code: " << hexa(hr);
       // Crash debug builds but try to recover in release builds.
       MOZ_ASSERT(false);
       return;
     }
     mDT->mDevice->CopyResource(tmpTexture, mDT->mTexture);
 
     D2D1_BITMAP_PROPERTIES props = D2D1::BitmapProperties(D2DPixelFormat(format));
 
     RefPtr<IDXGISurface> surf;
 
     tmpTexture->QueryInterface((IDXGISurface**)byRef(surf));
 
     hr = mDT->mRT->CreateSharedBitmap(IID_IDXGISurface, surf,
                                       &props, byRef(mOldSurfBitmap));
 
     if (FAILED(hr)) {
-      gfxCriticalError() << "[D2D] CreateSharedBitmap failure " << size << " Code: " << hr;
+      gfxCriticalError() << "[D2D] CreateSharedBitmap failure " << size << " Code: " << hexa(hr);
       // Crash debug builds but try to recover in release builds.
       MOZ_ASSERT(false);
       return;
     }
 
     IntRect clipBounds;
     mClippedArea = mDT->GetClippedGeometry(&clipBounds);
 
@@ -236,17 +236,17 @@ DrawTargetD2D::Snapshot()
 void
 DrawTargetD2D::Flush()
 {
   PopAllClips();
 
   HRESULT hr = mRT->Flush();
 
   if (FAILED(hr)) {
-    gfxWarning() << "Error reported when trying to flush D2D rendertarget. Code: " << hr;
+    gfxWarning() << "Error reported when trying to flush D2D rendertarget. Code: " << hexa(hr);
   }
 
   // We no longer depend on any target.
   for (TargetSet::iterator iter = mDependingOnTargets.begin();
        iter != mDependingOnTargets.end(); iter++) {
     (*iter)->mDependentTargets.erase(this);
   }
   mDependingOnTargets.clear();
@@ -466,17 +466,17 @@ DrawTargetD2D::DrawSurfaceWithShadow(Sou
 
   EnsureViews();
 
   if (!mTempRTView) {
     // This view is only needed in this path.
     HRESULT hr = mDevice->CreateRenderTargetView(mTempTexture, nullptr, byRef(mTempRTView));
 
     if (FAILED(hr)) {
-      gfxWarning() << "Failure to create RenderTargetView. Code: " << hr;
+      gfxWarning() << "Failure to create RenderTargetView. Code: " << hexa(hr);
       return;
     }
   }
 
 
   RefPtr<ID3D10RenderTargetView> destRTView = mRTView;
   RefPtr<ID3D10Texture2D> destTexture;
   HRESULT hr;
@@ -527,17 +527,17 @@ DrawTargetD2D::DrawSurfaceWithShadow(Sou
                                aSurface->GetSize().height);
     desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
     desc.MiscFlags = D3D10_RESOURCE_MISC_GENERATE_MIPS;
 
     RefPtr<ID3D10Texture2D> mipTexture;
     hr = mDevice->CreateTexture2D(&desc, nullptr, byRef(mipTexture));
 
     if (FAILED(hr)) {
-      gfxCriticalError() << "[D2D] CreateTexture2D failure " << aSurface->GetSize() << " Code: " << hr;
+      gfxCriticalError() << "[D2D] CreateTexture2D failure " << aSurface->GetSize() << " Code: " << hexa(hr);
       return;
     }
 
     IntSize dsSize = IntSize(int32_t(aSurface->GetSize().width * (1.7f / aSigma)),
                              int32_t(aSurface->GetSize().height * (1.7f / aSigma)));
 
     if (dsSize.width < 1) {
       dsSize.width = 1;
@@ -554,17 +554,17 @@ DrawTargetD2D::DrawSurfaceWithShadow(Sou
     desc = CD3D10_TEXTURE2D_DESC(DXGI_FORMAT_B8G8R8A8_UNORM,
                                  dsSize.width,
                                  dsSize.height, 1, 1);
     desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
     RefPtr<ID3D10Texture2D> tmpDSTexture;
     hr = mDevice->CreateTexture2D(&desc, nullptr, byRef(tmpDSTexture));
 
     if (FAILED(hr)) {
-      gfxCriticalError() << "[D2D] CreateTexture2D failure " << dsSize << " Code: " << hr;
+      gfxCriticalError() << "[D2D] CreateTexture2D failure " << dsSize << " Code: " << hexa(hr);
       return;
     }
 
     D3D10_BOX box;
     box.left = box.top = box.front = 0;
     box.back = 1;
     box.right = aSurface->GetSize().width;
     box.bottom = aSurface->GetSize().height;
@@ -1263,24 +1263,24 @@ DrawTargetD2D::CreateSimilarDrawTarget(c
 
 TemporaryRef<PathBuilder>
 DrawTargetD2D::CreatePathBuilder(FillRule aFillRule) const
 {
   RefPtr<ID2D1PathGeometry> path;
   HRESULT hr = factory()->CreatePathGeometry(byRef(path));
 
   if (FAILED(hr)) {
-    gfxWarning() << "Failed to create Direct2D Path Geometry. Code: " << hr;
+    gfxWarning() << "Failed to create Direct2D Path Geometry. Code: " << hexa(hr);
     return nullptr;
   }
 
   RefPtr<ID2D1GeometrySink> sink;
   hr = path->Open(byRef(sink));
   if (FAILED(hr)) {
-    gfxWarning() << "Failed to access Direct2D Path Geometry. Code: " << hr;
+    gfxWarning() << "Failed to access Direct2D Path Geometry. Code: " << hexa(hr);
     return nullptr;
   }
 
   if (aFillRule == FillRule::FILL_WINDING) {
     sink->SetFillMode(D2D1_FILL_MODE_WINDING);
   }
 
   return new PathBuilderD2D(sink, path, aFillRule);
@@ -1300,17 +1300,17 @@ DrawTargetD2D::CreateGradientStops(Gradi
 
   HRESULT hr =
     mRT->CreateGradientStopCollection(stops, aNumStops,
                                       D2D1_GAMMA_2_2, D2DExtend(aExtendMode),
                                       byRef(stopCollection));
   delete [] stops;
 
   if (FAILED(hr)) {
-    gfxWarning() << "Failed to create GradientStopCollection. Code: " << hr;
+    gfxWarning() << "Failed to create GradientStopCollection. Code: " << hexa(hr);
     return nullptr;
   }
 
   return new GradientStopsD2D(stopCollection);
 }
 
 TemporaryRef<FilterNode>
 DrawTargetD2D::CreateFilter(FilterType aType)
@@ -1357,17 +1357,17 @@ DrawTargetD2D::Init(const IntSize &aSize
                              mSize.width,
                              mSize.height,
                              1, 1);
   desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
 
   hr = mDevice->CreateTexture2D(&desc, nullptr, byRef(mTexture));
 
   if (FAILED(hr)) {
-    gfxCriticalError() << "Failed to init Direct2D DrawTarget. Size: " << mSize << " Code: " << hr;
+    gfxCriticalError() << "Failed to init Direct2D DrawTarget. Size: " << mSize << " Code: " << hexa(hr);
     return false;
   }
 
   if (!InitD2DRenderTarget()) {
     return false;
   }
 
   mRT->Clear(D2D1::ColorF(0, 0));
@@ -1427,17 +1427,17 @@ DrawTargetD2D::InitD3D10Data()
   decltype(D3D10CreateEffectFromMemory)* createD3DEffect;
   HMODULE d3dModule = LoadLibraryW(L"d3d10_1.dll");
   createD3DEffect = (decltype(D3D10CreateEffectFromMemory)*)
       GetProcAddress(d3dModule, "D3D10CreateEffectFromMemory");
 
   hr = createD3DEffect((void*)d2deffect, sizeof(d2deffect), 0, mDevice, nullptr, byRef(mPrivateData->mEffect));
 
   if (FAILED(hr)) {
-    gfxWarning() << "Failed to initialize Direct2D required effects. Code: " << hr;
+    gfxWarning() << "Failed to initialize Direct2D required effects. Code: " << hexa(hr);
     return false;
   }
 
   privateDataSize = sizeof(mPrivateData);
   mDevice->SetPrivateData(sPrivateDataD2D, privateDataSize, &mPrivateData);
 
   D3D10_INPUT_ELEMENT_DESC layout[] =
   {
@@ -1449,29 +1449,29 @@ DrawTargetD2D::InitD3D10Data()
 
   hr = mDevice->CreateInputLayout(layout,
                                   sizeof(layout) / sizeof(D3D10_INPUT_ELEMENT_DESC),
                                   passDesc.pIAInputSignature,
                                   passDesc.IAInputSignatureSize,
                                   byRef(mPrivateData->mInputLayout));
 
   if (FAILED(hr)) {
-    gfxWarning() << "Failed to initialize Direct2D required InputLayout. Code: " << hr;
+    gfxWarning() << "Failed to initialize Direct2D required InputLayout. Code: " << hexa(hr);
     return false;
   }
 
   D3D10_SUBRESOURCE_DATA data;
   Vertex vertices[] = { {0.0, 0.0}, {1.0, 0.0}, {0.0, 1.0}, {1.0, 1.0} };
   data.pSysMem = vertices;
   CD3D10_BUFFER_DESC bufferDesc(sizeof(vertices), D3D10_BIND_VERTEX_BUFFER);
 
   hr = mDevice->CreateBuffer(&bufferDesc, &data, byRef(mPrivateData->mVB));
 
   if (FAILED(hr)) {
-    gfxWarning() << "Failed to initialize Direct2D required VertexBuffer. Code: " << hr;
+    gfxWarning() << "Failed to initialize Direct2D required VertexBuffer. Code: " << hexa(hr);
     return false;
   }
 
   return true;
 }
 
 /*
  * Private helpers
@@ -1766,26 +1766,26 @@ DrawTargetD2D::FinalizeRTForOperation(Co
       HRESULT hr = mDevice->CreateTexture2D(&desc, nullptr, byRef(tmpTexture));
       if (FAILED(hr)) {
         gfxWarning() << "Failed to create temporary texture to hold surface data.";
         return;
       }
 
       mDevice->CopyResource(tmpTexture, mTexture);
       if (FAILED(hr)) {
-        gfxWarning() << *this << "Failed to create shader resource view for temp texture. Code: " << hr;
+        gfxWarning() << *this << "Failed to create shader resource view for temp texture. Code: " << hexa(hr);
         return;
       }
 
       DrawTargetD2D::Flush();
 
       hr = mDevice->CreateShaderResourceView(tmpTexture, nullptr, byRef(mBckSRView));
 
       if (FAILED(hr)) {
-        gfxWarning() << *this << "Failed to create shader resource view for temp texture. Code: " << hr;
+        gfxWarning() << *this << "Failed to create shader resource view for temp texture. Code: " << hexa(hr);
         return;
       }
 
       unsigned int compop = (unsigned int)aOperator - (unsigned int)CompositionOp::OP_XOR;
       mPrivateData->mEffect->GetVariableByName("bcktex")->AsShaderResource()->SetResource(mBckSRView);
       mPrivateData->mEffect->GetVariableByName("blendop")->AsScalar()->SetInt(compop);
 
       if (aOperator > CompositionOp::OP_EXCLUSION)
@@ -2000,31 +2000,31 @@ DrawTargetD2D::EnsureViews()
                              mSize.height,
                              1, 1);
   desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
 
   hr = mDevice->CreateTexture2D(&desc, nullptr, byRef(mTempTexture));
 
   if (FAILED(hr)) {
     gfxWarning() << *this << "Failed to create temporary texture for rendertarget. Size: "
-      << mSize << " Code: " << hr;
+      << mSize << " Code: " << hexa(hr);
     return;
   }
 
   hr = mDevice->CreateShaderResourceView(mTempTexture, nullptr, byRef(mSRView));
 
   if (FAILED(hr)) {
-    gfxWarning() << *this << "Failed to create shader resource view for temp texture. Code: " << hr;
+    gfxWarning() << *this << "Failed to create shader resource view for temp texture. Code: " << hexa(hr);
     return;
   }
 
   hr = mDevice->CreateRenderTargetView(mTexture, nullptr, byRef(mRTView));
 
   if (FAILED(hr)) {
-    gfxWarning() << *this << "Failed to create rendertarget view for temp texture. Code: " << hr;
+    gfxWarning() << *this << "Failed to create rendertarget view for temp texture. Code: " << hexa(hr);
   }
 }
 
 void
 DrawTargetD2D::PopAllClips()
 {
   if (mClipsArePushed) {
     PopClipsFromRT(mRT);
--- a/gfx/2d/DrawTargetD2D1.cpp
+++ b/gfx/2d/DrawTargetD2D1.cpp
@@ -615,17 +615,17 @@ DrawTargetD2D1::CreateSourceSurfaceFromD
 {
   RefPtr<ID2D1Bitmap1> bitmap;
 
   HRESULT hr = mDC->CreateBitmap(D2DIntSize(aSize), aData, aStride,
                                  D2D1::BitmapProperties1(D2D1_BITMAP_OPTIONS_NONE, D2DPixelFormat(aFormat)),
                                  byRef(bitmap));
 
   if (FAILED(hr)) {
-    gfxCriticalError() << "[D2D1.1] CreateBitmap failure " << aSize << " Code: " << hr;
+    gfxCriticalError() << "[D2D1.1] CreateBitmap failure " << aSize << " Code: " << hexa(hr);
   }
 
   if (!bitmap) {
     return nullptr;
   }
 
   return new SourceSurfaceD2D1(bitmap.get(), mDC, aFormat, aSize);
 }
@@ -644,24 +644,24 @@ DrawTargetD2D1::CreateSimilarDrawTarget(
 
 TemporaryRef<PathBuilder>
 DrawTargetD2D1::CreatePathBuilder(FillRule aFillRule) const
 {
   RefPtr<ID2D1PathGeometry> path;
   HRESULT hr = factory()->CreatePathGeometry(byRef(path));
 
   if (FAILED(hr)) {
-    gfxWarning() << *this << ": Failed to create Direct2D Path Geometry. Code: " << hr;
+    gfxWarning() << *this << ": Failed to create Direct2D Path Geometry. Code: " << hexa(hr);
     return nullptr;
   }
 
   RefPtr<ID2D1GeometrySink> sink;
   hr = path->Open(byRef(sink));
   if (FAILED(hr)) {
-    gfxWarning() << *this << ": Failed to access Direct2D Path Geometry. Code: " << hr;
+    gfxWarning() << *this << ": Failed to access Direct2D Path Geometry. Code: " << hexa(hr);
     return nullptr;
   }
 
   if (aFillRule == FillRule::FILL_WINDING) {
     sink->SetFillMode(D2D1_FILL_MODE_WINDING);
   }
 
   return new PathBuilderD2D(sink, path, aFillRule);
@@ -686,17 +686,17 @@ DrawTargetD2D1::CreateGradientStops(Grad
 
   HRESULT hr =
     mDC->CreateGradientStopCollection(stops, aNumStops,
                                       D2D1_GAMMA_2_2, D2DExtend(aExtendMode),
                                       byRef(stopCollection));
   delete [] stops;
 
   if (FAILED(hr)) {
-    gfxWarning() << *this << ": Failed to create GradientStopCollection. Code: " << hr;
+    gfxWarning() << *this << ": Failed to create GradientStopCollection. Code: " << hexa(hr);
     return nullptr;
   }
 
   return new GradientStopsD2D(stopCollection);
 }
 
 TemporaryRef<FilterNode>
 DrawTargetD2D1::CreateFilter(FilterType aType)
@@ -707,17 +707,17 @@ DrawTargetD2D1::CreateFilter(FilterType 
 bool
 DrawTargetD2D1::Init(ID3D11Texture2D* aTexture, SurfaceFormat aFormat)
 {
   HRESULT hr;
 
   hr = Factory::GetD2D1Device()->CreateDeviceContext(D2D1_DEVICE_CONTEXT_OPTIONS_ENABLE_MULTITHREADED_OPTIMIZATIONS, byRef(mDC));
 
   if (FAILED(hr)) {
-    gfxWarning() << *this << ": Error " << hr << " failed to initialize new DeviceContext.";
+    gfxWarning() << *this << ": Error " << hexa(hr) << " failed to initialize new DeviceContext.";
     return false;
   }
 
   RefPtr<IDXGISurface> dxgiSurface;
   aTexture->QueryInterface(__uuidof(IDXGISurface),
                            (void**)((IDXGISurface**)byRef(dxgiSurface)));
   if (!dxgiSurface) {
     return false;
@@ -727,33 +727,33 @@ DrawTargetD2D1::Init(ID3D11Texture2D* aT
   props.dpiX = 96;
   props.dpiY = 96;
   props.pixelFormat = D2DPixelFormat(aFormat);
   props.colorContext = nullptr;
   props.bitmapOptions = D2D1_BITMAP_OPTIONS_TARGET;
   hr = mDC->CreateBitmapFromDxgiSurface(dxgiSurface, props, (ID2D1Bitmap1**)byRef(mBitmap));
 
   if (FAILED(hr)) {
-    gfxCriticalError() << "[D2D1.1] CreateBitmapFromDxgiSurface failure Code: " << hr;
+    gfxCriticalError() << "[D2D1.1] CreateBitmapFromDxgiSurface failure Code: " << hexa(hr);
     return false;
   }
 
   mFormat = aFormat;
   D3D11_TEXTURE2D_DESC desc;
   aTexture->GetDesc(&desc);
   desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
   mSize.width = desc.Width;
   mSize.height = desc.Height;
   props.pixelFormat.alphaMode = D2D1_ALPHA_MODE_PREMULTIPLIED;
   props.pixelFormat.format = DXGI_FORMAT_B8G8R8A8_UNORM;
 
   hr = mDC->CreateBitmap(D2DIntSize(mSize), nullptr, 0, props, (ID2D1Bitmap1**)byRef(mTempBitmap));
 
   if (FAILED(hr)) {
-    gfxCriticalError() << "[D2D1.1] CreateBitmap failure " << mSize << " Code: " << hr;
+    gfxCriticalError() << "[D2D1.1] CreateBitmap failure " << mSize << " Code: " << hexa(hr);
     return false;
   }
 
   mDC->SetTarget(mBitmap);
 
   mDC->BeginDraw();
   return true;
 }
@@ -761,17 +761,17 @@ DrawTargetD2D1::Init(ID3D11Texture2D* aT
 bool
 DrawTargetD2D1::Init(const IntSize &aSize, SurfaceFormat aFormat)
 {
   HRESULT hr;
 
   hr = Factory::GetD2D1Device()->CreateDeviceContext(D2D1_DEVICE_CONTEXT_OPTIONS_ENABLE_MULTITHREADED_OPTIMIZATIONS, byRef(mDC));
 
   if (FAILED(hr)) {
-    gfxWarning() << *this << ": Error " << hr << " failed to initialize new DeviceContext.";
+    gfxWarning() << *this << ": Error " << hexa(hr) << " failed to initialize new DeviceContext.";
     return false;
   }
 
   if (mDC->GetMaximumBitmapSize() < UINT32(aSize.width) ||
       mDC->GetMaximumBitmapSize() < UINT32(aSize.height)) {
     // This is 'ok'
     gfxDebug() << *this << ": Attempt to use unsupported surface size for D2D 1.1.";
     return false;
@@ -781,17 +781,17 @@ DrawTargetD2D1::Init(const IntSize &aSiz
   props.dpiX = 96;
   props.dpiY = 96;
   props.pixelFormat = D2DPixelFormat(aFormat);
   props.colorContext = nullptr;
   props.bitmapOptions = D2D1_BITMAP_OPTIONS_TARGET;
   mDC->CreateBitmap(D2DIntSize(aSize), nullptr, 0, props, (ID2D1Bitmap1**)byRef(mBitmap));
 
   if (FAILED(hr)) {
-    gfxWarning() << *this << ": Error " << hr << " failed to create new CommandList.";
+    gfxWarning() << *this << ": Error " << hexa(hr) << " failed to create new CommandList.";
     return false;
   }
 
   props.pixelFormat.alphaMode = D2D1_ALPHA_MODE_PREMULTIPLIED;
   props.pixelFormat.format = DXGI_FORMAT_B8G8R8A8_UNORM;
 
   mDC->CreateBitmap(D2DIntSize(aSize), nullptr, 0, props, (ID2D1Bitmap1**)byRef(mTempBitmap));
 
@@ -1278,17 +1278,17 @@ DrawTargetD2D1::OptimizeSourceSurface(So
   }
 
   RefPtr<ID2D1Bitmap1> bitmap;
   HRESULT hr = mDC->CreateBitmap(D2DIntSize(data->GetSize()), map.mData, map.mStride,
                                  D2D1::BitmapProperties1(D2D1_BITMAP_OPTIONS_NONE, D2DPixelFormat(data->GetFormat())),
                                  byRef(bitmap));
 
   if (FAILED(hr)) {
-    gfxCriticalError() << "[D2D1.1] CreateBitmap failure " << data->GetSize() << " Code: " << hr;
+    gfxCriticalError() << "[D2D1.1] CreateBitmap failure " << data->GetSize() << " Code: " << hexa(hr);
   }
 
   data->Unmap();
 
   if (!bitmap) {
     return data.forget();
   }
 
--- a/gfx/2d/FilterNodeD2D1.cpp
+++ b/gfx/2d/FilterNodeD2D1.cpp
@@ -530,17 +530,17 @@ FilterNodeD2D1::Create(DrawTarget* aDT, 
   }
 
   RefPtr<ID2D1Effect> effect;
   HRESULT hr;
 
   hr = aDC->CreateEffect(GetCLDIDForFilterType(aType), byRef(effect));
 
   if (FAILED(hr)) {
-    gfxWarning() << "Failed to create effect for FilterType: " << hr;
+    gfxWarning() << "Failed to create effect for FilterType: " << hexa(hr);
     return nullptr;
   }
 
   switch (aType) {
     case FilterType::LINEAR_TRANSFER:
     case FilterType::GAMMA_TRANSFER:
     case FilterType::TABLE_TRANSFER:
     case FilterType::DISCRETE_TRANSFER:
--- a/gfx/2d/Logging.h
+++ b/gfx/2d/Logging.h
@@ -96,16 +96,24 @@ public:
   template<typename T>
   NoLog &operator <<(const T &aLogText) { return *this; }
 };
 
 MOZ_BEGIN_ENUM_CLASS(LogOptions, int)
   NoNewline = 0x01
 MOZ_END_ENUM_CLASS(LogOptions)
 
+template<typename T>
+struct Hexa {
+  Hexa(T aVal) : mVal(aVal) {}
+  T mVal;
+};
+template<typename T>
+Hexa<T> hexa(T val) { return Hexa<T>(val); }
+
 template<int L, typename Logger = BasicLogger>
 class Log
 {
 public:
   explicit Log(LogOptions aOptions = LogOptions(0)) : mOptions(aOptions) {}
   ~Log() {
     Flush();
   }
@@ -140,17 +148,19 @@ public:
   template <typename T, typename Sub>
   Log &operator <<(const BaseSize<T, Sub>& aSize)
     { mMessage << "Size(" << aSize.width << "," << aSize.height << ")"; return *this; }
   template <typename T, typename Sub, typename Point, typename SizeT, typename Margin>
   Log &operator <<(const BaseRect<T, Sub, Point, SizeT, Margin>& aRect)
     { mMessage << "Rect" << aRect; return *this; }
   Log &operator<<(const Matrix& aMatrix)
     { mMessage << "Matrix(" << aMatrix._11 << " " << aMatrix._12 << " ; " << aMatrix._21 << " " << aMatrix._22 << " ; " << aMatrix._31 << " " << aMatrix._32 << ")"; return *this; }
-
+  template<typename T>
+  Log &operator<<(Hexa<T> aHex)
+    { mMessage << "0x" << std::hex << aHex.mVal << std::dec; return *this; }
 
 private:
 
   void WriteLog(const std::string &aString) {
     Logger::OutputMessage(aString, L);
   }
 
   std::stringstream mMessage;
--- a/gfx/2d/PathD2D.cpp
+++ b/gfx/2d/PathD2D.cpp
@@ -294,17 +294,17 @@ TemporaryRef<Path>
 PathBuilderD2D::Finish()
 {
   if (mFigureActive) {
     mSink->EndFigure(D2D1_FIGURE_END_OPEN);
   }
 
   HRESULT hr = mSink->Close();
   if (FAILED(hr)) {
-    gfxDebug() << "Failed to close PathSink. Code: " << hr;
+    gfxDebug() << "Failed to close PathSink. Code: " << hexa(hr);
     return nullptr;
   }
 
   return new PathD2D(mGeometry, mFigureActive, mCurrentPoint, mFillRule);
 }
 
 TemporaryRef<PathBuilder>
 PathD2D::CopyToBuilder(FillRule aFillRule) const
@@ -314,24 +314,24 @@ PathD2D::CopyToBuilder(FillRule aFillRul
 
 TemporaryRef<PathBuilder>
 PathD2D::TransformedCopyToBuilder(const Matrix &aTransform, FillRule aFillRule) const
 {
   RefPtr<ID2D1PathGeometry> path;
   HRESULT hr = DrawTargetD2D::factory()->CreatePathGeometry(byRef(path));
 
   if (FAILED(hr)) {
-    gfxWarning() << "Failed to create PathGeometry. Code: " << hr;
+    gfxWarning() << "Failed to create PathGeometry. Code: " << hexa(hr);
     return nullptr;
   }
 
   RefPtr<ID2D1GeometrySink> sink;
   hr = path->Open(byRef(sink));
   if (FAILED(hr)) {
-    gfxWarning() << "Failed to open Geometry for writing. Code: " << hr;
+    gfxWarning() << "Failed to open Geometry for writing. Code: " << hexa(hr);
     return nullptr;
   }
 
   if (aFillRule == FillRule::FILL_WINDING) {
     sink->SetFillMode(D2D1_FILL_MODE_WINDING);
   }
 
   if (mEndedActive) {
@@ -362,17 +362,17 @@ PathD2D::StreamToSink(PathSink *aSink) c
   HRESULT hr;
 
   StreamingGeometrySink sink(aSink);
 
   hr = mGeometry->Simplify(D2D1_GEOMETRY_SIMPLIFICATION_OPTION_CUBICS_AND_LINES,
                            D2D1::IdentityMatrix(), &sink);
 
   if (FAILED(hr)) {
-    gfxWarning() << "Failed to stream D2D path to sink. Code: " << hr;
+    gfxWarning() << "Failed to stream D2D path to sink. Code: " << hexa(hr);
     return;
   }
 }
  
 bool
 PathD2D::ContainsPoint(const Point &aPoint, const Matrix &aTransform) const
 {
   BOOL result;
@@ -413,17 +413,17 @@ Rect
 PathD2D::GetBounds(const Matrix &aTransform) const
 {
   D2D1_RECT_F d2dBounds;
 
   HRESULT hr = mGeometry->GetBounds(D2DMatrix(aTransform), &d2dBounds);
 
   Rect bounds = ToRect(d2dBounds);
   if (FAILED(hr) || !bounds.IsFinite()) {
-    gfxWarning() << "Failed to get stroked bounds for path. Code: " << hr;
+    gfxWarning() << "Failed to get stroked bounds for path. Code: " << hexa(hr);
     return Rect();
   }
 
   return bounds;
 }
 
 Rect
 PathD2D::GetStrokedBounds(const StrokeOptions &aStrokeOptions,
@@ -433,17 +433,17 @@ PathD2D::GetStrokedBounds(const StrokeOp
 
   RefPtr<ID2D1StrokeStyle> strokeStyle = CreateStrokeStyleForOptions(aStrokeOptions);
   HRESULT hr =
     mGeometry->GetWidenedBounds(aStrokeOptions.mLineWidth, strokeStyle,
                                 D2DMatrix(aTransform), &d2dBounds);
 
   Rect bounds = ToRect(d2dBounds);
   if (FAILED(hr) || !bounds.IsFinite()) {
-    gfxWarning() << "Failed to get stroked bounds for path. Code: " << hr;
+    gfxWarning() << "Failed to get stroked bounds for path. Code: " << hexa(hr);
     return Rect();
   }
 
   return bounds;
 }
 
 }
 }
--- a/gfx/2d/RadialGradientEffectD2D1.cpp
+++ b/gfx/2d/RadialGradientEffectD2D1.cpp
@@ -377,16 +377,16 @@ RadialGradientEffectD2D1::CreateGradient
   props.bufferPrecision = D2D1_BUFFER_PRECISION_8BPC_UNORM;
   props.filter = D2D1_FILTER_MIN_MAG_MIP_LINEAR;
   D2D1_EXTEND_MODE extendMode[] = { mStopCollection->GetExtendMode(), mStopCollection->GetExtendMode() };
   props.extendModes = extendMode;
 
   HRESULT hr = mEffectContext->CreateResourceTexture(nullptr, &props, &textureData.front(), &stride, 4096 * 4, byRef(tex));
 
   if (FAILED(hr)) {
-    gfxWarning() << "Failed to create resource texture: " << hr;
+    gfxWarning() << "Failed to create resource texture: " << hexa(hr);
   }
 
   return tex.forget();
 }
 
 }
 }
--- a/gfx/2d/SourceSurfaceD2D.cpp
+++ b/gfx/2d/SourceSurfaceD2D.cpp
@@ -67,24 +67,24 @@ SourceSurfaceD2D::InitFromData(unsigned 
     gfxDebug() << "Bitmap does not fit in texture.";
     return false;
   }
 
   D2D1_BITMAP_PROPERTIES props = D2D1::BitmapProperties(D2DPixelFormat(aFormat));
   hr = aRT->CreateBitmap(D2DIntSize(aSize), props, byRef(mBitmap));
 
   if (FAILED(hr)) {
-    gfxWarning() << "Failed to create D2D Bitmap for data. Code: " << hr;
+    gfxWarning() << "Failed to create D2D Bitmap for data. Code: " << hexa(hr);
     return false;
   }
 
   hr = mBitmap->CopyFromMemory(nullptr, aData, aStride);
 
   if (FAILED(hr)) {
-    gfxWarning() << "Failed to copy data to D2D bitmap. Code: " << hr;
+    gfxWarning() << "Failed to copy data to D2D bitmap. Code: " << hexa(hr);
     return false;
   }
 
   DrawTargetD2D::mVRAMUsageSS += GetByteSize();
   mDevice = Factory::GetDirect3D10Device();
 
   return true;
 }
@@ -96,31 +96,31 @@ SourceSurfaceD2D::InitFromTexture(ID3D10
 {
   HRESULT hr;
 
   RefPtr<IDXGISurface> surf;
 
   hr = aTexture->QueryInterface((IDXGISurface**)&surf);
 
   if (FAILED(hr)) {
-    gfxWarning() << "Failed to QI texture to surface. Code: " << hr;
+    gfxWarning() << "Failed to QI texture to surface. Code: " << hexa(hr);
     return false;
   }
 
   D3D10_TEXTURE2D_DESC desc;
   aTexture->GetDesc(&desc);
 
   mSize = IntSize(desc.Width, desc.Height);
   mFormat = aFormat;
 
   D2D1_BITMAP_PROPERTIES props = D2D1::BitmapProperties(D2DPixelFormat(aFormat));
   hr = aRT->CreateSharedBitmap(IID_IDXGISurface, surf, &props, byRef(mBitmap));
 
   if (FAILED(hr)) {
-    gfxWarning() << "Failed to create SharedBitmap. Code: " << hr;
+    gfxWarning() << "Failed to create SharedBitmap. Code: " << hexa(hr);
     return false;
   }
 
   aTexture->GetDevice(byRef(mDevice));
   DrawTargetD2D::mVRAMUsageSS += GetByteSize();
 
   return true;
 }
@@ -145,37 +145,37 @@ DataSourceSurfaceD2D::DataSourceSurfaceD
   CD3D10_TEXTURE2D_DESC desc(DXGIFormat(mFormat), mSize.width, mSize.height);
   desc.MipLevels = 1;
   desc.Usage = D3D10_USAGE_DEFAULT;
   desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
   RefPtr<ID3D10Texture2D> sourceTexture;
   HRESULT hr = aSourceSurface->mDevice->CreateTexture2D(&desc, nullptr,
                                                         byRef(sourceTexture));
   if (FAILED(hr)) {
-    gfxWarning() << "Failed to create texture. Code: " << hr;
+    gfxWarning() << "Failed to create texture. Code: " << hexa(hr);
     return;
   }
 
   RefPtr<IDXGISurface> dxgiSurface;
   hr = sourceTexture->QueryInterface((IDXGISurface**)byRef(dxgiSurface));
   if (FAILED(hr)) {
-    gfxWarning() << "Failed to create DXGI surface. Code: " << hr;
+    gfxWarning() << "Failed to create DXGI surface. Code: " << hexa(hr);
     return;
   }
 
   D2D1_RENDER_TARGET_PROPERTIES rtProps = D2D1::RenderTargetProperties(
             D2D1_RENDER_TARGET_TYPE_DEFAULT,
             D2D1::PixelFormat(DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_PREMULTIPLIED));
 
   RefPtr<ID2D1RenderTarget> renderTarget;
   hr = DrawTargetD2D::factory()->CreateDxgiSurfaceRenderTarget(dxgiSurface,
                                                                &rtProps,
                                                                byRef(renderTarget));
   if (FAILED(hr)) {
-    gfxWarning() << "Failed to create render target. Code: " << hr;
+    gfxWarning() << "Failed to create render target. Code: " << hexa(hr);
     return;
   }
 
   renderTarget->BeginDraw();
   renderTarget->Clear(D2D1::ColorF(0, 0.0f));
   if (aSourceSurface->GetFormat() != SurfaceFormat::A8) {
     renderTarget->DrawBitmap(aSourceSurface->mBitmap,
                              D2D1::RectF(0, 0,
@@ -184,26 +184,26 @@ DataSourceSurfaceD2D::DataSourceSurfaceD
   } else {
     RefPtr<ID2D1SolidColorBrush> brush;
     renderTarget->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::White), byRef(brush));
     renderTarget->SetAntialiasMode(D2D1_ANTIALIAS_MODE_ALIASED);
     renderTarget->FillOpacityMask(aSourceSurface->mBitmap, brush, D2D1_OPACITY_MASK_CONTENT_GRAPHICS);
   }
   hr = renderTarget->EndDraw();
   if (FAILED(hr)) {
-    gfxWarning() << "Failed to draw bitmap. Code: " << hr;
+    gfxWarning() << "Failed to draw bitmap. Code: " << hexa(hr);
     return;
   }
 
   desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ | D3D10_CPU_ACCESS_WRITE;
   desc.Usage = D3D10_USAGE_STAGING;
   desc.BindFlags = 0;
   hr = aSourceSurface->mDevice->CreateTexture2D(&desc, nullptr, byRef(mTexture));
   if (FAILED(hr)) {
-    gfxWarning() << "Failed to create staging texture. Code: " << hr;
+    gfxWarning() << "Failed to create staging texture. Code: " << hexa(hr);
     mTexture = nullptr;
     return;
   }
 
   aSourceSurface->mDevice->CopyResource(mTexture, sourceTexture);
 }
 
 DataSourceSurfaceD2D::~DataSourceSurfaceD2D()
@@ -268,17 +268,17 @@ DataSourceSurfaceD2D::Map(MapType aMapTy
     mapType = D3D10_MAP_READ_WRITE;
   }
 
   D3D10_MAPPED_TEXTURE2D map;
 
   HRESULT hr = mTexture->Map(0, mapType, 0, &map);
 
   if (FAILED(hr)) {
-    gfxWarning() << "Texture map failed with code: " << hr;
+    gfxWarning() << "Texture map failed with code: " << hexa(hr);
     return false;
   }
 
   aMappedSurface->mData = (uint8_t*)map.pData;
   aMappedSurface->mStride = map.RowPitch;
   mIsMapped = true;
 
   return true;
@@ -301,17 +301,17 @@ DataSourceSurfaceD2D::EnsureMappedTextur
 
   if (mMapped ||
       !mTexture) {
     return;
   }
 
   HRESULT hr = mTexture->Map(0, D3D10_MAP_READ, 0, &mData);
   if (FAILED(hr)) {
-    gfxWarning() << "Failed to map texture. Code: " << hr;
+    gfxWarning() << "Failed to map texture. Code: " << hexa(hr);
     mTexture = nullptr;
   } else {
     mMapped = true;
   }
 }
 
 }
 }
--- a/gfx/2d/SourceSurfaceD2DTarget.cpp
+++ b/gfx/2d/SourceSurfaceD2DTarget.cpp
@@ -62,17 +62,17 @@ SourceSurfaceD2DTarget::GetDataSurface()
   desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
   desc.Usage = D3D10_USAGE_STAGING;
   desc.BindFlags = 0;
   desc.MiscFlags = 0;
 
   HRESULT hr = Factory::GetDirect3D10Device()->CreateTexture2D(&desc, nullptr, byRef(dataSurf->mTexture));
 
   if (FAILED(hr)) {
-    gfxDebug() << "Failed to create staging texture for SourceSurface. Code: " << hr;
+    gfxDebug() << "Failed to create staging texture for SourceSurface. Code: " << hexa(hr);
     return nullptr;
   }
   Factory::GetDirect3D10Device()->CopyResource(dataSurf->mTexture, mTexture);
 
   return dataSurf.forget();
 }
 
 void*
@@ -89,17 +89,17 @@ SourceSurfaceD2DTarget::GetSRView()
 {
   if (mSRView) {
     return mSRView;
   }
 
   HRESULT hr = Factory::GetDirect3D10Device()->CreateShaderResourceView(mTexture, nullptr, byRef(mSRView));
 
   if (FAILED(hr)) {
-    gfxWarning() << "Failed to create ShaderResourceView. Code: " << hr;
+    gfxWarning() << "Failed to create ShaderResourceView. Code: " << hexa(hr);
   }
 
   return mSRView;
 }
 
 void
 SourceSurfaceD2DTarget::DrawTargetWillChange()
 {
@@ -138,31 +138,31 @@ SourceSurfaceD2DTarget::GetBitmap(ID2D1R
   mTexture->GetDesc(&desc);
 
   IntSize size(desc.Width, desc.Height);
   
   RefPtr<IDXGISurface> surf;
   hr = mTexture->QueryInterface((IDXGISurface**)byRef(surf));
 
   if (FAILED(hr)) {
-    gfxWarning() << "Failed to query interface texture to DXGISurface. Code: " << hr;
+    gfxWarning() << "Failed to query interface texture to DXGISurface. Code: " << hexa(hr);
     return nullptr;
   }
 
   D2D1_BITMAP_PROPERTIES props = D2D1::BitmapProperties(D2DPixelFormat(mFormat));
   hr = aRT->CreateSharedBitmap(IID_IDXGISurface, surf, &props, byRef(mBitmap));
 
   if (FAILED(hr)) {
     // This seems to happen for SurfaceFormat::A8 sometimes...
     hr = aRT->CreateBitmap(D2D1::SizeU(desc.Width, desc.Height),
                            D2D1::BitmapProperties(D2DPixelFormat(mFormat)),
                            byRef(mBitmap));
 
     if (FAILED(hr)) {
-      gfxWarning() << "Failed in CreateBitmap. Code: " << hr;
+      gfxWarning() << "Failed in CreateBitmap. Code: " << hexa(hr);
       return nullptr;
     }
 
     RefPtr<ID2D1RenderTarget> rt;
 
     if (mDrawTarget) {
       rt = mDrawTarget->mRT;
     }
@@ -271,17 +271,17 @@ DataSourceSurfaceD2DTarget::Map(MapType 
     mapType = D3D10_MAP_READ_WRITE;
   }
 
   D3D10_MAPPED_TEXTURE2D map;
 
   HRESULT hr = mTexture->Map(0, mapType, 0, &map);
 
   if (FAILED(hr)) {
-    gfxWarning() << "Texture map failed with code: " << hr;
+    gfxWarning() << "Texture map failed with code: " << hexa(hr);
     return false;
   }
 
   aMappedSurface->mData = (uint8_t*)map.pData;
   aMappedSurface->mStride = map.RowPitch;
   mIsMapped = true;
 
   return true;
@@ -299,17 +299,17 @@ DataSourceSurfaceD2DTarget::Unmap()
 void
 DataSourceSurfaceD2DTarget::EnsureMapped()
 {
   // Do not use GetData() after having used Map!
   MOZ_ASSERT(!mIsMapped);
   if (!mMapped) {
     HRESULT hr = mTexture->Map(0, D3D10_MAP_READ, 0, &mMap);
     if (FAILED(hr)) {
-      gfxWarning() << "Failed to map texture to memory. Code: " << hr;
+      gfxWarning() << "Failed to map texture to memory. Code: " << hexa(hr);
       return;
     }
     mMapped = true;
   }
 }
 
 }
 }
--- a/gfx/layers/d3d11/TextureD3D11.cpp
+++ b/gfx/layers/d3d11/TextureD3D11.cpp
@@ -283,17 +283,17 @@ TextureClientD3D11::Unlock()
     desc.Usage = D3D10_USAGE_STAGING;
     desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
     desc.MiscFlags = 0;
 
     RefPtr<ID3D10Texture2D> tex;
     HRESULT hr = device->CreateTexture2D(&desc, nullptr, byRef(tex));
 
     if (FAILED(hr)) {
-      gfx::gfxCriticalError() << "[D3D11] CreateTexture2D failure " << mSize << " Code: " << hr;
+      gfx::gfxCriticalError() << "[D3D11] CreateTexture2D failure " << mSize << " Code: " << gfx::hexa(hr);
       return;
     }
 
     if (SUCCEEDED(hr)) {
       device->CopyResource(tex, mTexture10);
 
       gfxWindowsPlatform::GetPlatform()->GetReadbackManager()->PostTask(tex, mReadbackSink);
     } else {
@@ -370,17 +370,17 @@ TextureClientD3D11::AllocateForSurface(g
       D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE);
 
     newDesc.MiscFlags = D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX;
 
     hr = device->CreateTexture2D(&newDesc, nullptr, byRef(mTexture10));
   }
 
   if (FAILED(hr)) {
-    gfx::gfxCriticalError() << "[D3D11] CreateTexture2D failure " << aSize << " Code: " << hr;
+    gfx::gfxCriticalError() << "[D3D11] CreateTexture2D failure " << aSize << " Code: " << gfx::hexa(hr);
     return false;
   }
 
   // Defer clearing to the next time we lock to avoid an extra (expensive) lock.
   mNeedsClear = aFlags & ALLOC_CLEAR_BUFFER;
   mNeedsClearWhite = aFlags & ALLOC_CLEAR_BUFFER_WHITE;
 
   return true;