1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 #include "ContentLayerChromium.h"
9 #include "BitmapCanvasLayerTextureUpdater.h"
10 #include "CCRenderingStats.h"
11 #include "ContentLayerChromiumClient.h"
12 #include "cc/test/geometry_test_utils.h"
13 #include "skia/ext/platform_canvas.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include <public/WebFloatRect.h>
16 #include <public/WebRect.h>
19 using namespace WebKit
;
23 class MockContentLayerChromiumClient
: public ContentLayerChromiumClient
{
25 explicit MockContentLayerChromiumClient(IntRect opaqueLayerRect
)
26 : m_opaqueLayerRect(opaqueLayerRect
)
30 virtual void paintContents(SkCanvas
*, const IntRect
&, FloatRect
& opaque
) OVERRIDE
32 opaque
= FloatRect(m_opaqueLayerRect
);
36 IntRect m_opaqueLayerRect
;
39 TEST(ContentLayerChromiumTest
, ContentLayerPainterWithDeviceScale
)
41 float contentsScale
= 2;
42 IntRect
contentRect(10, 10, 100, 100);
43 IntRect
opaqueRectInLayerSpace(5, 5, 20, 20);
44 IntRect opaqueRectInContentSpace
= opaqueRectInLayerSpace
;
45 opaqueRectInContentSpace
.scale(contentsScale
);
46 MockContentLayerChromiumClient
client(opaqueRectInLayerSpace
);
47 RefPtr
<BitmapCanvasLayerTextureUpdater
> updater
= BitmapCanvasLayerTextureUpdater::create(ContentLayerPainter::create(&client
).PassAs
<LayerPainterChromium
>());
49 IntRect resultingOpaqueRect
;
50 CCRenderingStats stats
;
51 updater
->prepareToUpdate(contentRect
, IntSize(256, 256), contentsScale
, contentsScale
, resultingOpaqueRect
, stats
);
53 EXPECT_RECT_EQ(opaqueRectInContentSpace
, resultingOpaqueRect
);