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. 4 5 #include "cc/quads/draw_quad.h" 6 7 #include "base/logging.h" 8 #include "base/values.h" 9 #include "cc/base/math_util.h" 10 #include "cc/debug/traced_value.h" 11 #include "cc/quads/checkerboard_draw_quad.h" 12 #include "cc/quads/debug_border_draw_quad.h" 13 #include "cc/quads/io_surface_draw_quad.h" 14 #include "cc/quads/picture_draw_quad.h" 15 #include "cc/quads/render_pass_draw_quad.h" 16 #include "cc/quads/solid_color_draw_quad.h" 17 #include "cc/quads/stream_video_draw_quad.h" 18 #include "cc/quads/texture_draw_quad.h" 19 #include "cc/quads/tile_draw_quad.h" 20 #include "cc/quads/yuv_video_draw_quad.h" 21 #include "ui/gfx/quad_f.h" 22 23 namespace { 24 template<typename T> T* TypedCopy(const cc::DrawQuad* other) { 25 return new T(*T::MaterialCast(other)); 26 } 27 } // namespace 28 29 namespace cc { 30 31 DrawQuad::DrawQuad() 32 : material(INVALID), 33 needs_blending(false), 34 shared_quad_state() { 35 } 36 37 void DrawQuad::SetAll(const SharedQuadState* shared_quad_state, 38 Material material, 39 gfx::Rect rect, 40 gfx::Rect opaque_rect, 41 gfx::Rect visible_rect, 42 bool needs_blending) { 43 DCHECK(rect.Contains(visible_rect)) << "rect: " << rect.ToString() 44 << " visible_rect: " 45 << visible_rect.ToString(); 46 DCHECK(opaque_rect.IsEmpty() || rect.Contains(opaque_rect)) 47 << "rect: " << rect.ToString() << "opaque_rect " 48 << opaque_rect.ToString(); 49 50 this->material = material; 51 this->rect = rect; 52 this->opaque_rect = opaque_rect; 53 this->visible_rect = visible_rect; 54 this->needs_blending = needs_blending; 55 this->shared_quad_state = shared_quad_state; 56 57 DCHECK(shared_quad_state); 58 DCHECK(material != INVALID); 59 } 60 61 DrawQuad::~DrawQuad() { 62 } 63 64 scoped_ptr<DrawQuad> DrawQuad::Copy( 65 const SharedQuadState* copied_shared_quad_state) const { 66 scoped_ptr<DrawQuad> copy_quad; 67 switch (material) { 68 case CHECKERBOARD: 69 copy_quad.reset(TypedCopy<CheckerboardDrawQuad>(this)); 70 break; 71 case DEBUG_BORDER: 72 copy_quad.reset(TypedCopy<DebugBorderDrawQuad>(this)); 73 break; 74 case IO_SURFACE_CONTENT: 75 copy_quad.reset(TypedCopy<IOSurfaceDrawQuad>(this)); 76 break; 77 case PICTURE_CONTENT: 78 copy_quad.reset(TypedCopy<PictureDrawQuad>(this)); 79 break; 80 case TEXTURE_CONTENT: 81 copy_quad.reset(TypedCopy<TextureDrawQuad>(this)); 82 break; 83 case SOLID_COLOR: 84 copy_quad.reset(TypedCopy<SolidColorDrawQuad>(this)); 85 break; 86 case TILED_CONTENT: 87 copy_quad.reset(TypedCopy<TileDrawQuad>(this)); 88 break; 89 case STREAM_VIDEO_CONTENT: 90 copy_quad.reset(TypedCopy<StreamVideoDrawQuad>(this)); 91 break; 92 case YUV_VIDEO_CONTENT: 93 copy_quad.reset(TypedCopy<YUVVideoDrawQuad>(this)); 94 break; 95 case RENDER_PASS: // RenderPass quads have their own copy() method. 96 case INVALID: 97 LOG(FATAL) << "Invalid DrawQuad material " << material; 98 break; 99 } 100 copy_quad->shared_quad_state = copied_shared_quad_state; 101 return copy_quad.Pass(); 102 } 103 104 scoped_ptr<base::Value> DrawQuad::AsValue() const { 105 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); 106 value->SetInteger("material", material); 107 value->Set("shared_state", 108 TracedValue::CreateIDRef(shared_quad_state).release()); 109 110 value->Set("content_space_rect", MathUtil::AsValue(rect).release()); 111 bool rect_is_clipped; 112 gfx::QuadF rect_as_target_space_quad = MathUtil::MapQuad( 113 shared_quad_state->content_to_target_transform, 114 gfx::QuadF(rect), 115 &rect_is_clipped); 116 value->Set("rect_as_target_space_quad", 117 MathUtil::AsValue(rect_as_target_space_quad).release()); 118 value->SetBoolean("rect_is_clipped", rect_is_clipped); 119 120 value->Set("content_space_opaque_rect", 121 MathUtil::AsValue(opaque_rect).release()); 122 bool opaque_rect_is_clipped; 123 gfx::QuadF opaque_rect_as_target_space_quad = MathUtil::MapQuad( 124 shared_quad_state->content_to_target_transform, 125 gfx::QuadF(opaque_rect), 126 &opaque_rect_is_clipped); 127 value->Set("opaque_rect_as_target_space_quad", 128 MathUtil::AsValue(opaque_rect_as_target_space_quad).release()); 129 value->SetBoolean("opaque_rect_is_clipped", opaque_rect_is_clipped); 130 131 value->Set("content_space_visible_rect", 132 MathUtil::AsValue(visible_rect).release()); 133 bool visible_rect_is_clipped; 134 gfx::QuadF visible_rect_as_target_space_quad = MathUtil::MapQuad( 135 shared_quad_state->content_to_target_transform, 136 gfx::QuadF(visible_rect), 137 &visible_rect_is_clipped); 138 value->Set("visible_rect_as_target_space_quad", 139 MathUtil::AsValue(visible_rect_as_target_space_quad).release()); 140 value->SetBoolean("visible_rect_is_clipped", visible_rect_is_clipped); 141 142 value->SetBoolean("needs_blending", needs_blending); 143 value->SetBoolean("should_draw_with_blending", ShouldDrawWithBlending()); 144 ExtendValue(value.get()); 145 return value.PassAs<base::Value>(); 146 } 147 148 } // namespace cc 149