Home | History | Annotate | Download | only in quads
      1 // Copyright 2011 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/quads/render_pass.h"
      6 
      7 #include "base/values.h"
      8 #include "cc/base/math_util.h"
      9 #include "cc/debug/traced_value.h"
     10 #include "cc/output/copy_output_request.h"
     11 #include "cc/quads/draw_quad.h"
     12 #include "cc/quads/shared_quad_state.h"
     13 
     14 namespace cc {
     15 
     16 void* RenderPass::Id::AsTracingId() const {
     17   COMPILE_ASSERT(sizeof(size_t) <= sizeof(void*), size_t_bigger_than_pointer);
     18   return reinterpret_cast<void*>(base::HashPair(layer_id, index));
     19 }
     20 
     21 scoped_ptr<RenderPass> RenderPass::Create() {
     22   return make_scoped_ptr(new RenderPass);
     23 }
     24 
     25 RenderPass::RenderPass()
     26     : id(Id(-1, -1)),
     27       has_transparent_background(true),
     28       has_occlusion_from_outside_target_surface(false) {}
     29 
     30 RenderPass::~RenderPass() {
     31   TRACE_EVENT_OBJECT_DELETED_WITH_ID(
     32       TRACE_DISABLED_BY_DEFAULT("cc.debug.quads"),
     33       "cc::RenderPass", id.AsTracingId());
     34 }
     35 
     36 scoped_ptr<RenderPass> RenderPass::Copy(Id new_id) const {
     37   scoped_ptr<RenderPass> copy_pass(Create());
     38   copy_pass->SetAll(new_id,
     39                     output_rect,
     40                     damage_rect,
     41                     transform_to_root_target,
     42                     has_transparent_background,
     43                     has_occlusion_from_outside_target_surface);
     44   return copy_pass.Pass();
     45 }
     46 
     47 void RenderPass::SetNew(Id id,
     48                         gfx::Rect output_rect,
     49                         gfx::RectF damage_rect,
     50                         const gfx::Transform& transform_to_root_target) {
     51   DCHECK_GT(id.layer_id, 0);
     52   DCHECK_GE(id.index, 0);
     53 
     54   this->id = id;
     55   this->output_rect = output_rect;
     56   this->damage_rect = damage_rect;
     57   this->transform_to_root_target = transform_to_root_target;
     58 
     59   DCHECK(quad_list.empty());
     60   DCHECK(shared_quad_state_list.empty());
     61 }
     62 
     63 void RenderPass::SetAll(Id id,
     64                         gfx::Rect output_rect,
     65                         gfx::RectF damage_rect,
     66                         const gfx::Transform& transform_to_root_target,
     67                         bool has_transparent_background,
     68                         bool has_occlusion_from_outside_target_surface) {
     69   DCHECK_GT(id.layer_id, 0);
     70   DCHECK_GE(id.index, 0);
     71 
     72   this->id = id;
     73   this->output_rect = output_rect;
     74   this->damage_rect = damage_rect;
     75   this->transform_to_root_target = transform_to_root_target;
     76   this->has_transparent_background = has_transparent_background;
     77   this->has_occlusion_from_outside_target_surface =
     78       has_occlusion_from_outside_target_surface;
     79 
     80   DCHECK(quad_list.empty());
     81   DCHECK(shared_quad_state_list.empty());
     82 }
     83 
     84 scoped_ptr<base::Value> RenderPass::AsValue() const {
     85   scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
     86   value->Set("output_rect", MathUtil::AsValue(output_rect).release());
     87   value->Set("damage_rect", MathUtil::AsValue(damage_rect).release());
     88   value->SetBoolean("has_transparent_background", has_transparent_background);
     89   value->SetBoolean("has_occlusion_from_outside_target_surface",
     90                     has_occlusion_from_outside_target_surface);
     91   value->SetInteger("copy_requests", copy_requests.size());
     92   scoped_ptr<base::ListValue> shared_states_value(new base::ListValue());
     93   for (size_t i = 0; i < shared_quad_state_list.size(); ++i) {
     94     shared_states_value->Append(shared_quad_state_list[i]->AsValue().release());
     95   }
     96   value->Set("shared_quad_state_list", shared_states_value.release());
     97   scoped_ptr<base::ListValue> quad_list_value(new base::ListValue());
     98   for (size_t i = 0; i < quad_list.size(); ++i) {
     99     quad_list_value->Append(quad_list[i]->AsValue().release());
    100   }
    101   value->Set("quad_list", quad_list_value.release());
    102 
    103   TracedValue::MakeDictIntoImplicitSnapshotWithCategory(
    104       TRACE_DISABLED_BY_DEFAULT("cc.debug.quads"),
    105       value.get(), "cc::RenderPass", id.AsTracingId());
    106   return value.PassAs<base::Value>();
    107 }
    108 
    109 }  // namespace cc
    110