#ifndef CC_TEST_TILED_LAYER_TEST_COMMON_H_
#define CC_TEST_TILED_LAYER_TEST_COMMON_H_
#include "cc/base/region.h"
#include "cc/layers/tiled_layer.h"
#include "cc/layers/tiled_layer_impl.h"
#include "cc/resources/layer_updater.h"
#include "cc/resources/prioritized_resource.h"
#include "cc/resources/resource_provider.h"
#include "cc/resources/resource_update_queue.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"
namespace cc {
class FakeTiledLayer;
class FakeLayerUpdater : public LayerUpdater {
public:
class Resource : public LayerUpdater::Resource {
public:
Resource(FakeLayerUpdater* updater,
scoped_ptr<PrioritizedResource> resource);
virtual ~Resource();
virtual void Update(ResourceUpdateQueue* queue,
const gfx::Rect& source_rect,
const gfx::Vector2d& dest_offset,
bool partial_update) OVERRIDE;
private:
FakeLayerUpdater* layer_;
SkBitmap bitmap_;
DISALLOW_COPY_AND_ASSIGN(Resource);
};
FakeLayerUpdater();
virtual scoped_ptr<LayerUpdater::Resource> CreateResource(
PrioritizedResourceManager* resource) OVERRIDE;
virtual void PrepareToUpdate(const gfx::Rect& content_rect,
const gfx::Size& tile_size,
float contents_width_scale,
float contents_height_scale,
gfx::Rect* resulting_opaque_rect) OVERRIDE;
void SetRectToInvalidate(const gfx::Rect& rect, FakeTiledLayer* layer);
gfx::Rect last_update_rect() const { return last_update_rect_; }
int prepare_count() const { return prepare_count_; }
void ClearPrepareCount() { prepare_count_ = 0; }
int update_count() const { return update_count_; }
void ClearUpdateCount() { update_count_ = 0; }
void Update() { update_count_++; }
void SetOpaquePaintRect(const gfx::Rect& opaque_paint_rect) {
opaque_paint_rect_ = opaque_paint_rect;
}
protected:
virtual ~FakeLayerUpdater();
private:
int prepare_count_;
int update_count_;
gfx::Rect rect_to_invalidate_;
gfx::Rect last_update_rect_;
gfx::Rect opaque_paint_rect_;
scoped_refptr<FakeTiledLayer> layer_;
DISALLOW_COPY_AND_ASSIGN(FakeLayerUpdater);
};
class FakeTiledLayerImpl : public TiledLayerImpl {
public:
FakeTiledLayerImpl(LayerTreeImpl* tree_impl, int id);
virtual ~FakeTiledLayerImpl();
using TiledLayerImpl::HasTileAt;
using TiledLayerImpl::HasResourceIdForTileAt;
};
class FakeTiledLayer : public TiledLayer {
public:
explicit FakeTiledLayer(PrioritizedResourceManager* resource_manager);
static gfx::Size tile_size() { return gfx::Size(100, 100); }
using TiledLayer::InvalidateContentRect;
using TiledLayer::NeedsIdlePaint;
using TiledLayer::SkipsDraw;
using TiledLayer::NumPaintedTiles;
using TiledLayer::IdlePaintRect;
virtual void SetNeedsDisplayRect(const gfx::RectF& rect) OVERRIDE;
const gfx::RectF& last_needs_display_rect() const {
return last_needs_display_rect_;
}
virtual void SetTexturePriorities(
const PriorityCalculator& priority_calculator) OVERRIDE;
virtual PrioritizedResourceManager* ResourceManager() OVERRIDE;
FakeLayerUpdater* fake_layer_updater() { return fake_updater_.get(); }
gfx::RectF update_rect() { return update_rect_; }
void UpdateContentsScale(float ideal_contents_scale);
void ResetNumDependentsNeedPushProperties();
protected:
virtual LayerUpdater* Updater() const OVERRIDE;
virtual void CreateUpdaterIfNeeded() OVERRIDE {}
virtual ~FakeTiledLayer();
private:
scoped_refptr<FakeLayerUpdater> fake_updater_;
PrioritizedResourceManager* resource_manager_;
gfx::RectF last_needs_display_rect_;
DISALLOW_COPY_AND_ASSIGN(FakeTiledLayer);
};
class FakeTiledLayerWithScaledBounds : public FakeTiledLayer {
public:
explicit FakeTiledLayerWithScaledBounds(
PrioritizedResourceManager* resource_manager);
void SetContentBounds(const gfx::Size& content_bounds);
virtual void CalculateContentsScale(float ideal_contents_scale,
float device_scale_factor,
float page_scale_factor,
bool animating_transform_to_screen,
float* contents_scale_x,
float* contents_scale_y,
gfx::Size* content_bounds) OVERRIDE;
protected:
virtual ~FakeTiledLayerWithScaledBounds();
gfx::Size forced_content_bounds_;
private:
DISALLOW_COPY_AND_ASSIGN(FakeTiledLayerWithScaledBounds);
};
}
#endif