| Index: cc/trees/layer_tree_host_pixeltest_on_demand_raster.cc
|
| diff --git a/cc/trees/layer_tree_host_pixeltest_on_demand_raster.cc b/cc/trees/layer_tree_host_pixeltest_on_demand_raster.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..f8c4c3f232d816827ebeef73624c9f95fdcabbf2
|
| --- /dev/null
|
| +++ b/cc/trees/layer_tree_host_pixeltest_on_demand_raster.cc
|
| @@ -0,0 +1,111 @@
|
| +// Copyright 2013 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.
|
| +
|
| +#include "cc/layers/append_quads_data.h"
|
| +#include "cc/layers/content_layer_client.h"
|
| +#include "cc/layers/picture_layer.h"
|
| +#include "cc/layers/picture_layer_impl.h"
|
| +#include "cc/quads/draw_quad.h"
|
| +#include "cc/test/layer_tree_pixel_test.h"
|
| +#include "cc/test/mock_quad_culler.h"
|
| +#include "cc/trees/layer_tree_impl.h"
|
| +#include "third_party/skia/include/core/SkCanvas.h"
|
| +#include "third_party/skia/include/core/SkColor.h"
|
| +#include "ui/gfx/rect.h"
|
| +#include "ui/gfx/rect_f.h"
|
| +
|
| +#if !defined(OS_ANDROID)
|
| +
|
| +namespace cc {
|
| +namespace {
|
| +
|
| +class LayerTreeHostOnDemandRasterPixelTest : public LayerTreePixelTest {
|
| + public:
|
| + LayerTreeHostOnDemandRasterPixelTest() {
|
| + m_settings.implSidePainting = true;
|
| + }
|
| +
|
| + virtual void beginCommitOnThread(LayerTreeHostImpl* impl) OVERRIDE {
|
| + // Not enough memory available. Enforce on-demand rasterization.
|
| + impl->SetManagedMemoryPolicy(
|
| + ManagedMemoryPolicy(1, ManagedMemoryPolicy::CUTOFF_ALLOW_EVERYTHING,
|
| + 1, ManagedMemoryPolicy::CUTOFF_ALLOW_NOTHING));
|
| + }
|
| +
|
| + virtual void swapBuffersOnThread(LayerTreeHostImpl* host_impl,
|
| + bool result) OVERRIDE {
|
| + // Find the PictureLayerImpl ask it to append quads to check their material.
|
| + // The PictureLayerImpl is assumed to be the first child of the root layer
|
| + // in the active tree.
|
| + PictureLayerImpl* picture_layer = static_cast<PictureLayerImpl*>(
|
| + host_impl->active_tree()->root_layer()->child_at(0));
|
| +
|
| + QuadList quads;
|
| + SharedQuadStateList shared_states;
|
| + MockQuadCuller quad_culler(quads, shared_states);
|
| +
|
| + AppendQuadsData data;
|
| + picture_layer->AppendQuads(&quad_culler, &data);
|
| +
|
| + for (size_t i = 0; i < quads.size(); ++i)
|
| + EXPECT_EQ(quads[i]->material, DrawQuad::PICTURE_CONTENT);
|
| +
|
| + // Triggers pixel readback and ends the test.
|
| + LayerTreePixelTest::swapBuffersOnThread(host_impl, result);
|
| + }
|
| +};
|
| +
|
| +class BlueYellowLayerClient : public ContentLayerClient {
|
| + public:
|
| + BlueYellowLayerClient(const gfx::Rect& rect) : rect_(rect) { }
|
| +
|
| + virtual void PaintContents(SkCanvas* canvas,
|
| + gfx::Rect clip,
|
| + gfx::RectF* opaque) OVERRIDE {
|
| + *opaque = gfx::RectF(rect_.width(), rect_.height());
|
| +
|
| + // Skia uses BGRA ordering rather than RGBA. As the results will be later
|
| + // compared with a RGBA image, swap the red and blue components here.
|
| + SkPaint paint;
|
| + paint.setColor(SwapRB(SK_ColorBLUE));
|
| + canvas->drawRect(SkRect::MakeWH(rect_.width() / 2, rect_.height()), paint);
|
| +
|
| + paint.setColor(SwapRB(SK_ColorYELLOW));
|
| + canvas->drawRect(
|
| + SkRect::MakeXYWH(rect_.width() / 2, 0,
|
| + rect_.width() / 2, rect_.height()),
|
| + paint);
|
| + }
|
| +
|
| + static SkColor SwapRB(SkColor color) {
|
| + return SkColorSetARGB(
|
| + SkColorGetA(color),
|
| + SkColorGetB(color),
|
| + SkColorGetG(color),
|
| + SkColorGetR(color));
|
| + }
|
| +
|
| + private:
|
| + gfx::Rect rect_;
|
| +};
|
| +
|
| +TEST_F(LayerTreeHostOnDemandRasterPixelTest, RasterPictureLayer) {
|
| + // Use multiple colors in a single layer to prevent bypassing on-demand
|
| + // rasterization if a single solid color is detected in picture analysis.
|
| + gfx::Rect rect(200, 200);
|
| + BlueYellowLayerClient client(rect);
|
| + scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client);
|
| +
|
| + layer->SetIsDrawable(true);
|
| + layer->SetAnchorPoint(gfx::PointF());
|
| + layer->SetBounds(rect.size());
|
| + layer->SetPosition(rect.origin());
|
| +
|
| + RunPixelTest(layer, base::FilePath(FILE_PATH_LITERAL("blue_yellow.png")));
|
| +}
|
| +
|
| +} // namespace
|
| +} // namespace cc
|
| +
|
| +#endif // OS_ANDROID
|
|
|