Skip to content

Commit

Permalink
Bug 1667176 - Replace AppendToString for DeviceColor with ostream ope…
Browse files Browse the repository at this point in the history
…rator. r=mattwoodrow

Depends on D91337

Differential Revision: https://phabricator.services.mozilla.com/D91338
  • Loading branch information
staktrace committed Sep 25, 2020
1 parent d8fb331 commit 8150321
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 15 deletions.
25 changes: 25 additions & 0 deletions gfx/2d/Types.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "Types.h"

#include "nsPrintfCString.h"

#include <ostream>

namespace mozilla {
namespace gfx {

std::ostream& operator<<(std::ostream& aOut, const DeviceColor& aColor) {
aOut << nsPrintfCString("dev_rgba(%d, %d, %d, %f)", uint8_t(aColor.r * 255.f),
uint8_t(aColor.g * 255.f), uint8_t(aColor.b * 255.f),
aColor.a)
.get();
return aOut;
}

} // namespace gfx
} // namespace mozilla
4 changes: 4 additions & 0 deletions gfx/2d/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "mozilla/MacroArgs.h" // for MOZ_CONCAT
#include "mozilla/TypedEnumBits.h"

#include <iosfwd> // for ostream
#include <stddef.h>
#include <stdint.h>

Expand Down Expand Up @@ -572,6 +573,9 @@ struct DeviceColor {
return !(*this == aColor);
}

friend std::ostream& operator<<(std::ostream& aOut,
const DeviceColor& aColor);

Float r, g, b, a;
};

Expand Down
1 change: 1 addition & 0 deletions gfx/2d/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ UNIFIED_SOURCES += [
'SourceSurfaceCapture.cpp',
'SourceSurfaceRawData.cpp',
'Swizzle.cpp',
'Types.cpp',
]

SOURCES += [
Expand Down
4 changes: 2 additions & 2 deletions gfx/layers/Layers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2028,7 +2028,7 @@ void ContainerLayer::DumpPacket(layerscope::LayersPacket* aPacket,

void ColorLayer::PrintInfo(std::stringstream& aStream, const char* aPrefix) {
Layer::PrintInfo(aStream, aPrefix);
AppendToString(aStream, mColor, " [color=", "]");
aStream << "[ color=" << mColor << "]";
AppendToString(aStream, mBounds, " [bounds=", "]");
}

Expand Down Expand Up @@ -2145,7 +2145,7 @@ void ReadbackLayer::PrintInfo(std::stringstream& aStream, const char* aPrefix) {
<< nsPrintfCString("%p", mBackgroundLayer).get() << "]";
AppendToString(aStream, mBackgroundLayerOffset, " [backgroundOffset=", "]");
} else if (mBackgroundColor.a == 1.f) {
AppendToString(aStream, mBackgroundColor, " [backgroundColor=", "]");
aStream << " [backgroundColor=" << mBackgroundColor << "]";
} else {
aStream << " [nobackground]";
}
Expand Down
11 changes: 1 addition & 10 deletions gfx/layers/LayersLogging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,6 @@ using namespace mozilla::gfx;
namespace mozilla {
namespace layers {

void AppendToString(std::stringstream& aStream, const DeviceColor& c,
const char* pfx, const char* sfx) {
aStream << pfx;
aStream << nsPrintfCString("dev_rgba(%d, %d, %d, %f)", uint8_t(c.r * 255.f),
uint8_t(c.g * 255.f), uint8_t(c.b * 255.f), c.a)
.get();
aStream << sfx;
}

void AppendToString(std::stringstream& aStream, const nsPoint& p,
const char* pfx, const char* sfx) {
aStream << pfx;
Expand Down Expand Up @@ -169,7 +160,7 @@ void AppendToString(std::stringstream& aStream, const ScrollMetadata& m,
const char* pfx, const char* sfx) {
aStream << pfx;
AppendToString(aStream, m.GetMetrics(), "{ [metrics=");
AppendToString(aStream, m.GetBackgroundColor(), "] [color=");
aStream << "] [color=" << m.GetBackgroundColor();
if (m.GetScrollParentId() != ScrollableLayerGuid::NULL_SCROLL_ID) {
aStream << "] [scrollParent=" << m.GetScrollParentId();
}
Expand Down
3 changes: 0 additions & 3 deletions gfx/layers/LayersLogging.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ enum class ImageFormat;
namespace layers {
struct ZoomConstraints;

void AppendToString(std::stringstream& aStream, const gfx::DeviceColor& c,
const char* pfx = "", const char* sfx = "");

void AppendToString(std::stringstream& aStream, const nsPoint& p,
const char* pfx = "", const char* sfx = "");

Expand Down

0 comments on commit 8150321

Please sign in to comment.