Commit 67d309c4 authored by thakis's avatar thakis Committed by Commit bot

Rewrite three more classes to new blink style.

No behavior change.

BUG=675877

Review-Url: https://codereview.chromium.org/2875703003
Cr-Commit-Position: refs/heads/master@{#471044}
parent 08b2f9e4
...@@ -37,6 +37,9 @@ ...@@ -37,6 +37,9 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
namespace blink {
namespace {
// Buffer helper class // Buffer helper class
// //
// This class perform some trival buffer operations while checking for // This class perform some trival buffer operations while checking for
...@@ -48,46 +51,48 @@ class Buffer { ...@@ -48,46 +51,48 @@ class Buffer {
public: public:
Buffer(const uint8_t* buffer, size_t length) Buffer(const uint8_t* buffer, size_t length)
: m_buffer(buffer), m_length(length), m_offset(0) {} : buffer_(buffer), length_(length), offset_(0) {}
bool skip(size_t numBytes) { bool skip(size_t numBytes) {
if (m_offset + numBytes > m_length) if (offset_ + numBytes > length_)
return false; return false;
m_offset += numBytes; offset_ += numBytes;
return true; return true;
} }
bool readU8(uint8_t* value) { bool ReadU8(uint8_t* value) {
if (m_offset + sizeof(uint8_t) > m_length) if (offset_ + sizeof(uint8_t) > length_)
return false; return false;
*value = m_buffer[m_offset]; *value = buffer_[offset_];
m_offset += sizeof(uint8_t); offset_ += sizeof(uint8_t);
return true; return true;
} }
bool readU16(uint16_t* value) { bool ReadU16(uint16_t* value) {
if (m_offset + sizeof(uint16_t) > m_length) if (offset_ + sizeof(uint16_t) > length_)
return false; return false;
memcpy(value, m_buffer + m_offset, sizeof(uint16_t)); memcpy(value, buffer_ + offset_, sizeof(uint16_t));
*value = ntohs(*value); *value = ntohs(*value);
m_offset += sizeof(uint16_t); offset_ += sizeof(uint16_t);
return true; return true;
} }
bool readS16(int16_t* value) { bool ReadS16(int16_t* value) {
return readU16(reinterpret_cast<uint16_t*>(value)); return ReadU16(reinterpret_cast<uint16_t*>(value));
} }
size_t offset() const { return m_offset; } size_t Offset() const { return offset_; }
void setOffset(size_t newoffset) { m_offset = newoffset; } void SetOffset(size_t newoffset) { offset_ = newoffset; }
private: private:
const uint8_t* const m_buffer; const uint8_t* const buffer_;
const size_t m_length; const size_t length_;
size_t m_offset; size_t offset_;
}; };
} // namespace
// VDMX parsing code. // VDMX parsing code.
// //
// VDMX tables are found in some TrueType/OpenType fonts and contain // VDMX tables are found in some TrueType/OpenType fonts and contain
...@@ -96,8 +101,6 @@ class Buffer { ...@@ -96,8 +101,6 @@ class Buffer {
// //
// Freetype does not parse these tables so we do so here. // Freetype does not parse these tables so we do so here.
namespace blink {
// Parse a TrueType VDMX table. // Parse a TrueType VDMX table.
// yMax: (output) the ascender value from the table // yMax: (output) the ascender value from the table
// yMin: (output) the descender value from the table (negative!) // yMin: (output) the descender value from the table (negative!)
...@@ -119,7 +122,7 @@ bool ParseVDMX(int* y_max, ...@@ -119,7 +122,7 @@ bool ParseVDMX(int* y_max,
// We ignore the version. Future tables should be backwards compatible with // We ignore the version. Future tables should be backwards compatible with
// this layout. // this layout.
uint16_t num_ratios; uint16_t num_ratios;
if (!buf.skip(4) || !buf.readU16(&num_ratios)) if (!buf.skip(4) || !buf.ReadU16(&num_ratios))
return false; return false;
// Now we have two tables. Firstly we have @numRatios Ratio records, then a // Now we have two tables. Firstly we have @numRatios Ratio records, then a
...@@ -128,7 +131,7 @@ bool ParseVDMX(int* y_max, ...@@ -128,7 +131,7 @@ bool ParseVDMX(int* y_max,
// //
// Range 6 <= x <= 262146 // Range 6 <= x <= 262146
unsigned long offset_table_offset = unsigned long offset_table_offset =
buf.offset() + 4 /* sizeof struct ratio */ * num_ratios; buf.Offset() + 4 /* sizeof struct ratio */ * num_ratios;
unsigned desired_ratio = 0xffffffff; unsigned desired_ratio = 0xffffffff;
// We read 4 bytes per record, so the offset range is // We read 4 bytes per record, so the offset range is
...@@ -136,8 +139,8 @@ bool ParseVDMX(int* y_max, ...@@ -136,8 +139,8 @@ bool ParseVDMX(int* y_max,
for (unsigned i = 0; i < num_ratios; ++i) { for (unsigned i = 0; i < num_ratios; ++i) {
uint8_t x_ratio, y_ratio1, y_ratio2; uint8_t x_ratio, y_ratio1, y_ratio2;
if (!buf.skip(1) || !buf.readU8(&x_ratio) || !buf.readU8(&y_ratio1) || if (!buf.skip(1) || !buf.ReadU8(&x_ratio) || !buf.ReadU8(&y_ratio1) ||
!buf.readU8(&y_ratio2)) !buf.ReadU8(&y_ratio2))
return false; return false;
// This either covers 1:1, or this is the default entry (0, 0, 0) // This either covers 1:1, or this is the default entry (0, 0, 0)
...@@ -152,24 +155,24 @@ bool ParseVDMX(int* y_max, ...@@ -152,24 +155,24 @@ bool ParseVDMX(int* y_max,
return false; return false;
// Range 10 <= x <= 393216 // Range 10 <= x <= 393216
buf.setOffset(offset_table_offset + sizeof(uint16_t) * desired_ratio); buf.SetOffset(offset_table_offset + sizeof(uint16_t) * desired_ratio);
// Now we read from the offset table to get the offset of another array // Now we read from the offset table to get the offset of another array
uint16_t group_offset; uint16_t group_offset;
if (!buf.readU16(&group_offset)) if (!buf.ReadU16(&group_offset))
return false; return false;
// Range 0 <= x <= 65535 // Range 0 <= x <= 65535
buf.setOffset(group_offset); buf.SetOffset(group_offset);
uint16_t num_records; uint16_t num_records;
if (!buf.readU16(&num_records) || !buf.skip(sizeof(uint16_t))) if (!buf.ReadU16(&num_records) || !buf.skip(sizeof(uint16_t)))
return false; return false;
// We read 6 bytes per record, so the offset range is // We read 6 bytes per record, so the offset range is
// 4 <= x <= 458749 // 4 <= x <= 458749
for (unsigned i = 0; i < num_records; ++i) { for (unsigned i = 0; i < num_records; ++i) {
uint16_t pixel_size; uint16_t pixel_size;
if (!buf.readU16(&pixel_size)) if (!buf.ReadU16(&pixel_size))
return false; return false;
// the entries are sorted, so we can abort early if need be // the entries are sorted, so we can abort early if need be
if (pixel_size > target_pixel_size) if (pixel_size > target_pixel_size)
...@@ -177,7 +180,7 @@ bool ParseVDMX(int* y_max, ...@@ -177,7 +180,7 @@ bool ParseVDMX(int* y_max,
if (pixel_size == target_pixel_size) { if (pixel_size == target_pixel_size) {
int16_t temp_y_max, temp_y_min; int16_t temp_y_max, temp_y_min;
if (!buf.readS16(&temp_y_max) || !buf.readS16(&temp_y_min)) if (!buf.ReadS16(&temp_y_max) || !buf.ReadS16(&temp_y_min))
return false; return false;
*y_min = temp_y_min; *y_min = temp_y_min;
*y_max = temp_y_max; *y_max = temp_y_max;
......
...@@ -156,7 +156,7 @@ class Canvas2DLayerBridgeTest : public Test { ...@@ -156,7 +156,7 @@ class Canvas2DLayerBridgeTest : public Test {
std::unique_ptr<FakeWebGraphicsContext3DProvider> context_provider = std::unique_ptr<FakeWebGraphicsContext3DProvider> context_provider =
WTF::WrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); WTF::WrapUnique(new FakeWebGraphicsContext3DProvider(&gl));
gl.setIsContextLost(true); gl.SetIsContextLost(true);
Canvas2DLayerBridgePtr bridge(AdoptRef(new Canvas2DLayerBridge( Canvas2DLayerBridgePtr bridge(AdoptRef(new Canvas2DLayerBridge(
std::move(context_provider), IntSize(300, 150), 0, kNonOpaque, std::move(context_provider), IntSize(300, 150), 0, kNonOpaque,
Canvas2DLayerBridge::kEnableAcceleration, CanvasColorParams()))); Canvas2DLayerBridge::kEnableAcceleration, CanvasColorParams())));
...@@ -217,7 +217,7 @@ class Canvas2DLayerBridgeTest : public Test { ...@@ -217,7 +217,7 @@ class Canvas2DLayerBridgeTest : public Test {
uint32_t gen_id = bridge->GetOrCreateSurface()->generationID(); uint32_t gen_id = bridge->GetOrCreateSurface()->generationID();
bridge->Canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), flags); bridge->Canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), flags);
EXPECT_EQ(gen_id, bridge->GetOrCreateSurface()->generationID()); EXPECT_EQ(gen_id, bridge->GetOrCreateSurface()->generationID());
gl.setIsContextLost(true); gl.SetIsContextLost(true);
EXPECT_EQ(gen_id, bridge->GetOrCreateSurface()->generationID()); EXPECT_EQ(gen_id, bridge->GetOrCreateSurface()->generationID());
bridge->Canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), flags); bridge->Canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), flags);
EXPECT_EQ(gen_id, bridge->GetOrCreateSurface()->generationID()); EXPECT_EQ(gen_id, bridge->GetOrCreateSurface()->generationID());
...@@ -243,7 +243,7 @@ class Canvas2DLayerBridgeTest : public Test { ...@@ -243,7 +243,7 @@ class Canvas2DLayerBridgeTest : public Test {
// When the context is lost we are not sure if we should still be producing // When the context is lost we are not sure if we should still be producing
// GL frames for the compositor or not, so fail to generate frames. // GL frames for the compositor or not, so fail to generate frames.
gl.setIsContextLost(true); gl.SetIsContextLost(true);
cc::TextureMailbox texture_mailbox; cc::TextureMailbox texture_mailbox;
std::unique_ptr<cc::SingleReleaseCallback> release_callback; std::unique_ptr<cc::SingleReleaseCallback> release_callback;
...@@ -264,7 +264,7 @@ class Canvas2DLayerBridgeTest : public Test { ...@@ -264,7 +264,7 @@ class Canvas2DLayerBridgeTest : public Test {
EXPECT_TRUE(bridge->CheckSurfaceValid()); EXPECT_TRUE(bridge->CheckSurfaceValid());
// When the context is lost we are not sure if we should still be producing // When the context is lost we are not sure if we should still be producing
// GL frames for the compositor or not, so fail to generate frames. // GL frames for the compositor or not, so fail to generate frames.
gl.setIsContextLost(true); gl.SetIsContextLost(true);
EXPECT_FALSE(bridge->CheckSurfaceValid()); EXPECT_FALSE(bridge->CheckSurfaceValid());
// Restoration will fail because // Restoration will fail because
...@@ -1168,7 +1168,7 @@ TEST_F(Canvas2DLayerBridgeTest, DISABLED_HibernationAbortedDueToLostContext) ...@@ -1168,7 +1168,7 @@ TEST_F(Canvas2DLayerBridgeTest, DISABLED_HibernationAbortedDueToLostContext)
MockLogger* mock_logger_ptr = mock_logger.get(); MockLogger* mock_logger_ptr = mock_logger.get();
bridge->SetLoggerForTesting(std::move(mock_logger)); bridge->SetLoggerForTesting(std::move(mock_logger));
gl.setIsContextLost(true); gl.SetIsContextLost(true);
// Test entering hibernation // Test entering hibernation
std::unique_ptr<WaitableEvent> hibernation_aborted_event = std::unique_ptr<WaitableEvent> hibernation_aborted_event =
WTF::MakeUnique<WaitableEvent>(); WTF::MakeUnique<WaitableEvent>();
......
...@@ -20,7 +20,7 @@ class SharedGpuContextTest : public Test { ...@@ -20,7 +20,7 @@ class SharedGpuContextTest : public Test {
public: public:
void SetUp() override { void SetUp() override {
SharedGpuContext::SetContextProviderFactoryForTesting([this] { SharedGpuContext::SetContextProviderFactoryForTesting([this] {
gl_.setIsContextLost(false); gl_.SetIsContextLost(false);
return std::unique_ptr<WebGraphicsContext3DProvider>( return std::unique_ptr<WebGraphicsContext3DProvider>(
new FakeWebGraphicsContext3DProvider(&gl_)); new FakeWebGraphicsContext3DProvider(&gl_));
}); });
...@@ -36,7 +36,7 @@ class SharedGpuContextTest : public Test { ...@@ -36,7 +36,7 @@ class SharedGpuContextTest : public Test {
TEST_F(SharedGpuContextTest, contextLossAutoRecovery) { TEST_F(SharedGpuContextTest, contextLossAutoRecovery) {
EXPECT_TRUE(SharedGpuContext::IsValid()); EXPECT_TRUE(SharedGpuContext::IsValid());
unsigned context_id = SharedGpuContext::ContextId(); unsigned context_id = SharedGpuContext::ContextId();
gl_.setIsContextLost(true); gl_.SetIsContextLost(true);
EXPECT_FALSE(SharedGpuContext::IsValidWithoutRestoring()); EXPECT_FALSE(SharedGpuContext::IsValidWithoutRestoring());
EXPECT_TRUE(SharedGpuContext::IsValid()); EXPECT_TRUE(SharedGpuContext::IsValid());
EXPECT_NE(context_id, SharedGpuContext::ContextId()); EXPECT_NE(context_id, SharedGpuContext::ContextId());
......
...@@ -37,8 +37,8 @@ ...@@ -37,8 +37,8 @@
namespace blink { namespace blink {
static const struct CompositOpToXfermodeMode { static const struct CompositOpToXfermodeMode {
CompositeOperator m_composit_op; CompositeOperator composit_op;
SkBlendMode xfermode_mode_; SkBlendMode xfermode_mode;
} kGMapCompositOpsToXfermodeModes[] = { } kGMapCompositOpsToXfermodeModes[] = {
{kCompositeClear, SkBlendMode::kClear}, {kCompositeClear, SkBlendMode::kClear},
{kCompositeCopy, SkBlendMode::kSrc}, {kCompositeCopy, SkBlendMode::kSrc},
...@@ -98,8 +98,8 @@ SkBlendMode WebCoreCompositeToSkiaComposite(CompositeOperator op, ...@@ -98,8 +98,8 @@ SkBlendMode WebCoreCompositeToSkiaComposite(CompositeOperator op,
op)); op));
return SkBlendMode::kSrcOver; return SkBlendMode::kSrcOver;
} }
SkASSERT(table[static_cast<uint8_t>(op)].m_composit_op == op); SkASSERT(table[static_cast<uint8_t>(op)].composit_op == op);
return table[static_cast<uint8_t>(op)].xfermode_mode_; return table[static_cast<uint8_t>(op)].xfermode_mode;
} }
CompositeOperator CompositeOperatorFromSkia(SkBlendMode xfer_mode) { CompositeOperator CompositeOperatorFromSkia(SkBlendMode xfer_mode) {
......
...@@ -11,14 +11,14 @@ class FakeGLES2Interface : public gpu::gles2::GLES2InterfaceStub { ...@@ -11,14 +11,14 @@ class FakeGLES2Interface : public gpu::gles2::GLES2InterfaceStub {
public: public:
// GLES2Interface implementation. // GLES2Interface implementation.
GLenum GetGraphicsResetStatusKHR() override { GLenum GetGraphicsResetStatusKHR() override {
return m_contextLost ? GL_INVALID_OPERATION : GL_NO_ERROR; return context_lost_ ? GL_INVALID_OPERATION : GL_NO_ERROR;
} }
// Methods for tests. // Methods for tests.
void setIsContextLost(bool lost) { m_contextLost = lost; } void SetIsContextLost(bool lost) { context_lost_ = lost; }
private: private:
bool m_contextLost = false; bool context_lost_ = false;
}; };
#endif // FakeGLES2Interface_h #endif // FakeGLES2Interface_h
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment