1 // Copyright 2013 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/test/fake_delegated_renderer_layer_impl.h"
8 #include "cc/output/delegated_frame_data.h"
9 #include "cc/quads/draw_quad.h"
10 #include "cc/resources/returned_resource.h"
11 #include "cc/trees/layer_tree_impl.h"
15 FakeDelegatedRendererLayerImpl::FakeDelegatedRendererLayerImpl(
16 LayerTreeImpl
* tree_impl
,
18 : DelegatedRendererLayerImpl(tree_impl
, id
) {
21 FakeDelegatedRendererLayerImpl::~FakeDelegatedRendererLayerImpl() {}
23 scoped_ptr
<LayerImpl
> FakeDelegatedRendererLayerImpl::CreateLayerImpl(
24 LayerTreeImpl
* tree_impl
) {
25 return FakeDelegatedRendererLayerImpl::Create(
26 tree_impl
, id()).PassAs
<LayerImpl
>();
29 static ResourceProvider::ResourceId
AddResourceToFrame(
30 ResourceProvider
* resource_provider
,
31 DelegatedFrameData
* frame
,
32 ResourceProvider::ResourceId resource_id
) {
33 TransferableResource resource
;
34 resource
.id
= resource_id
;
35 resource
.mailbox_holder
.texture_target
=
36 resource_provider
->TargetForTesting(resource_id
);
37 frame
->resource_list
.push_back(resource
);
41 ResourceProvider::ResourceIdSet
FakeDelegatedRendererLayerImpl::Resources()
43 ResourceProvider::ResourceIdSet set
;
44 ResourceProvider::ResourceIdArray array
;
45 array
= ResourcesForTesting();
46 for (size_t i
= 0; i
< array
.size(); ++i
)
51 void NoopReturnCallback(const ReturnedResourceArray
& returned
) {}
53 void FakeDelegatedRendererLayerImpl::SetFrameDataForRenderPasses(
54 float device_scale_factor
,
55 RenderPassList
* pass_list
) {
56 scoped_ptr
<DelegatedFrameData
> delegated_frame(new DelegatedFrameData
);
57 delegated_frame
->device_scale_factor
= device_scale_factor
;
58 delegated_frame
->render_pass_list
.swap(*pass_list
);
60 ResourceProvider
* resource_provider
= layer_tree_impl()->resource_provider();
62 DrawQuad::ResourceIteratorCallback add_resource_to_frame_callback
=
63 base::Bind(&AddResourceToFrame
, resource_provider
, delegated_frame
.get());
64 for (size_t i
= 0; i
< delegated_frame
->render_pass_list
.size(); ++i
) {
65 RenderPass
* pass
= delegated_frame
->render_pass_list
[i
];
66 for (size_t j
= 0; j
< pass
->quad_list
.size(); ++j
)
67 pass
->quad_list
[j
]->IterateResources(add_resource_to_frame_callback
);
70 CreateChildIdIfNeeded(base::Bind(&NoopReturnCallback
));
71 SetFrameData(delegated_frame
.get(), gfx::RectF());