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. 4 5 #include "cc/test/fake_delegated_renderer_layer_impl.h" 6 7 #include "base/bind.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" 12 13 namespace cc { 14 15 FakeDelegatedRendererLayerImpl::FakeDelegatedRendererLayerImpl( 16 LayerTreeImpl* tree_impl, 17 int id) 18 : DelegatedRendererLayerImpl(tree_impl, id) { 19 } 20 21 FakeDelegatedRendererLayerImpl::~FakeDelegatedRendererLayerImpl() {} 22 23 scoped_ptr<LayerImpl> FakeDelegatedRendererLayerImpl::CreateLayerImpl( 24 LayerTreeImpl* tree_impl) { 25 return FakeDelegatedRendererLayerImpl::Create( 26 tree_impl, id()).PassAs<LayerImpl>(); 27 } 28 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); 38 return resource_id; 39 } 40 41 ResourceProvider::ResourceIdSet FakeDelegatedRendererLayerImpl::Resources() 42 const { 43 ResourceProvider::ResourceIdSet set; 44 ResourceProvider::ResourceIdArray array; 45 array = ResourcesForTesting(); 46 for (size_t i = 0; i < array.size(); ++i) 47 set.insert(array[i]); 48 return set; 49 } 50 51 void NoopReturnCallback(const ReturnedResourceArray& returned, 52 BlockingTaskRunner* main_thread_task_runner) { 53 } 54 55 void FakeDelegatedRendererLayerImpl::SetFrameDataForRenderPasses( 56 float device_scale_factor, 57 RenderPassList* pass_list) { 58 scoped_ptr<DelegatedFrameData> delegated_frame(new DelegatedFrameData); 59 delegated_frame->device_scale_factor = device_scale_factor; 60 delegated_frame->render_pass_list.swap(*pass_list); 61 62 ResourceProvider* resource_provider = layer_tree_impl()->resource_provider(); 63 64 DrawQuad::ResourceIteratorCallback add_resource_to_frame_callback = 65 base::Bind(&AddResourceToFrame, resource_provider, delegated_frame.get()); 66 for (size_t i = 0; i < delegated_frame->render_pass_list.size(); ++i) { 67 RenderPass* pass = delegated_frame->render_pass_list[i]; 68 for (QuadList::Iterator iter = pass->quad_list.begin(); 69 iter != pass->quad_list.end(); 70 ++iter) { 71 iter->IterateResources(add_resource_to_frame_callback); 72 } 73 } 74 75 CreateChildIdIfNeeded(base::Bind(&NoopReturnCallback)); 76 SetFrameData(delegated_frame.get(), gfx::RectF()); 77 } 78 79 } // namespace cc 80