blob: e85246522ef9630550d85d60831b0f8934dae330 [file] [log] [blame]
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FakeGraphicsLayerClient_h
#define FakeGraphicsLayerClient_h
#include "platform/graphics/GraphicsLayerClient.h"
namespace blink {
// A simple GraphicsLayerClient implementation suitable for use in unit tests.
class FakeGraphicsLayerClient : public GraphicsLayerClient {
public:
// GraphicsLayerClient implementation.
IntRect ComputeInterestRect(const GraphicsLayer*,
const IntRect&) const override {
return IntRect();
}
String DebugName(const GraphicsLayer*) const override { return String(); }
bool IsTrackingRasterInvalidations() const override {
return is_tracking_raster_invalidations_;
}
bool NeedsRepaint(const GraphicsLayer&) const override {
return needs_repaint_;
}
void PaintContents(const GraphicsLayer* layer,
GraphicsContext& context,
GraphicsLayerPaintingPhase phase,
const IntRect& rect) const override {
if (painter_)
painter_(layer, context, phase, rect);
}
void SetIsTrackingRasterInvalidations(bool is_tracking_raster_invalidations) {
is_tracking_raster_invalidations_ = is_tracking_raster_invalidations;
}
void SetNeedsRepaint(bool needs_repaint) { needs_repaint_ = needs_repaint; }
using Painter = std::function<void(const GraphicsLayer*,
GraphicsContext&,
GraphicsLayerPaintingPhase,
const IntRect&)>;
void SetPainter(const Painter& painter) { painter_ = painter; }
private:
Painter painter_ = nullptr;
bool is_tracking_raster_invalidations_ = false;
bool needs_repaint_ = false;
};
} // namespace blink
#endif // FakeGraphicsLayerClient_h