Home | History | Annotate | Download | only in test
      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, int id)
     17     : DelegatedRendererLayerImpl(tree_impl, id) {}
     18 
     19 FakeDelegatedRendererLayerImpl::~FakeDelegatedRendererLayerImpl() {}
     20 
     21 scoped_ptr<LayerImpl> FakeDelegatedRendererLayerImpl::CreateLayerImpl(
     22     LayerTreeImpl* tree_impl) {
     23   return FakeDelegatedRendererLayerImpl::Create(
     24       tree_impl, id()).PassAs<LayerImpl>();
     25 }
     26 
     27 static ResourceProvider::ResourceId AddResourceToFrame(
     28     ResourceProvider* resource_provider,
     29     DelegatedFrameData* frame,
     30     ResourceProvider::ResourceId resource_id) {
     31   TransferableResource resource;
     32   resource.id = resource_id;
     33   resource.target = resource_provider->TargetForTesting(resource_id);
     34   frame->resource_list.push_back(resource);
     35   return resource_id;
     36 }
     37 
     38 ResourceProvider::ResourceIdSet FakeDelegatedRendererLayerImpl::Resources()
     39     const {
     40   ResourceProvider::ResourceIdSet set;
     41   ResourceProvider::ResourceIdArray array;
     42   array = ResourcesForTesting();
     43   for (size_t i = 0; i < array.size(); ++i)
     44     set.insert(array[i]);
     45   return set;
     46 }
     47 
     48 void NoopReturnCallback(const ReturnedResourceArray& returned) {}
     49 
     50 void FakeDelegatedRendererLayerImpl::SetFrameDataForRenderPasses(
     51     ScopedPtrVector<RenderPass>* pass_list) {
     52   scoped_ptr<DelegatedFrameData> delegated_frame(new DelegatedFrameData);
     53   delegated_frame->render_pass_list.swap(*pass_list);
     54 
     55   ResourceProvider* resource_provider = layer_tree_impl()->resource_provider();
     56 
     57   DrawQuad::ResourceIteratorCallback add_resource_to_frame_callback =
     58       base::Bind(&AddResourceToFrame, resource_provider, delegated_frame.get());
     59   for (size_t i = 0; i < delegated_frame->render_pass_list.size(); ++i) {
     60     RenderPass* pass = delegated_frame->render_pass_list[i];
     61     for (size_t j = 0; j < pass->quad_list.size(); ++j)
     62       pass->quad_list[j]->IterateResources(add_resource_to_frame_callback);
     63   }
     64 
     65   CreateChildIdIfNeeded(base::Bind(&NoopReturnCallback));
     66   SetFrameData(delegated_frame.get(), gfx::RectF());
     67 }
     68 
     69 }  // namespace cc
     70