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.
5 #include "cc/layers/content_layer.h"
7 #include "cc/layers/content_layer_client.h"
8 #include "cc/resources/bitmap_content_layer_updater.h"
9 #include "cc/test/fake_rendering_stats_instrumentation.h"
10 #include "cc/test/geometry_test_utils.h"
11 #include "skia/ext/platform_canvas.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/gfx/rect_conversions.h"
18 class MockContentLayerClient
: public ContentLayerClient
{
20 explicit MockContentLayerClient(gfx::Rect opaque_layer_rect
)
21 : opaque_layer_rect_(opaque_layer_rect
) {}
23 virtual void PaintContents(SkCanvas
* canvas
,
25 gfx::RectF
* opaque
) OVERRIDE
{
26 *opaque
= gfx::RectF(opaque_layer_rect_
);
28 virtual void DidChangeLayerCanUseLCDText() OVERRIDE
{}
31 gfx::Rect opaque_layer_rect_
;
34 TEST(ContentLayerTest
, ContentLayerPainterWithDeviceScale
) {
35 float contents_scale
= 2.f
;
36 gfx::Rect
content_rect(10, 10, 100, 100);
37 gfx::Rect
opaque_rect_in_layer_space(5, 5, 20, 20);
38 gfx::Rect opaque_rect_in_content_space
= gfx::ScaleToEnclosingRect(
39 opaque_rect_in_layer_space
, contents_scale
, contents_scale
);
40 MockContentLayerClient
client(opaque_rect_in_layer_space
);
41 FakeRenderingStatsInstrumentation stats_instrumentation
;
42 scoped_refptr
<BitmapContentLayerUpdater
> updater
=
43 BitmapContentLayerUpdater::Create(
44 ContentLayerPainter::Create(&client
).PassAs
<LayerPainter
>(),
45 &stats_instrumentation
,
48 gfx::Rect resulting_opaque_rect
;
49 updater
->PrepareToUpdate(content_rect
,
53 &resulting_opaque_rect
);
55 EXPECT_EQ(opaque_rect_in_content_space
.ToString(),
56 resulting_opaque_rect
.ToString());