summaryrefslogtreecommitdiffstats
path: root/cc/content_layer_unittest.cc
blob: f53d6416e13c7b196462748848dbdac28e95ec7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright 2012 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 "config.h"

#include "cc/content_layer.h"

#include "cc/bitmap_canvas_layer_texture_updater.h"
#include "cc/content_layer_client.h"
#include "cc/rendering_stats.h"
#include "cc/test/geometry_test_utils.h"
#include "skia/ext/platform_canvas.h"
#include "testing/gtest/include/gtest/gtest.h"
#include <public/WebFloatRect.h>
#include <public/WebRect.h>

using namespace cc;
using namespace WebKit;

namespace {

class MockContentLayerChromiumClient : public ContentLayerChromiumClient {
public:
    explicit MockContentLayerChromiumClient(IntRect opaqueLayerRect)
        : m_opaqueLayerRect(opaqueLayerRect)
    {
    }

    virtual void paintContents(SkCanvas*, const IntRect&, FloatRect& opaque) OVERRIDE
    {
        opaque = FloatRect(m_opaqueLayerRect);
    }

private:
    IntRect m_opaqueLayerRect;
};

TEST(ContentLayerChromiumTest, ContentLayerPainterWithDeviceScale)
{
    float contentsScale = 2;
    IntRect contentRect(10, 10, 100, 100);
    IntRect opaqueRectInLayerSpace(5, 5, 20, 20);
    IntRect opaqueRectInContentSpace = opaqueRectInLayerSpace;
    opaqueRectInContentSpace.scale(contentsScale);
    MockContentLayerChromiumClient client(opaqueRectInLayerSpace);
    scoped_refptr<BitmapCanvasLayerTextureUpdater> updater = BitmapCanvasLayerTextureUpdater::create(ContentLayerPainter::create(&client).PassAs<LayerPainterChromium>());

    IntRect resultingOpaqueRect;
    CCRenderingStats stats;
    updater->prepareToUpdate(contentRect, IntSize(256, 256), contentsScale, contentsScale, resultingOpaqueRect, stats);

    EXPECT_RECT_EQ(opaqueRectInContentSpace, resultingOpaqueRect);
}

} // namespace