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/texture_draw_quad.h" 6 7 #include "base/logging.h" 8 #include "base/values.h" 9 #include "cc/base/math_util.h" 10 #include "ui/gfx/vector2d_f.h" 11 12 namespace cc { 13 14 TextureDrawQuad::TextureDrawQuad() 15 : resource_id(0), 16 premultiplied_alpha(false), 17 background_color(SK_ColorTRANSPARENT), 18 flipped(false) { 19 this->vertex_opacity[0] = 0.f; 20 this->vertex_opacity[1] = 0.f; 21 this->vertex_opacity[2] = 0.f; 22 this->vertex_opacity[3] = 0.f; 23 } 24 25 scoped_ptr<TextureDrawQuad> TextureDrawQuad::Create() { 26 return make_scoped_ptr(new TextureDrawQuad); 27 } 28 29 void TextureDrawQuad::SetNew(const SharedQuadState* shared_quad_state, 30 const gfx::Rect& rect, 31 const gfx::Rect& opaque_rect, 32 const gfx::Rect& visible_rect, 33 unsigned resource_id, 34 bool premultiplied_alpha, 35 const gfx::PointF& uv_top_left, 36 const gfx::PointF& uv_bottom_right, 37 SkColor background_color, 38 const float vertex_opacity[4], 39 bool flipped) { 40 bool needs_blending = vertex_opacity[0] != 1.0f || vertex_opacity[1] != 1.0f 41 || vertex_opacity[2] != 1.0f || vertex_opacity[3] != 1.0f; 42 DrawQuad::SetAll(shared_quad_state, DrawQuad::TEXTURE_CONTENT, rect, 43 opaque_rect, visible_rect, needs_blending); 44 this->resource_id = resource_id; 45 this->premultiplied_alpha = premultiplied_alpha; 46 this->uv_top_left = uv_top_left; 47 this->uv_bottom_right = uv_bottom_right; 48 this->background_color = background_color; 49 this->vertex_opacity[0] = vertex_opacity[0]; 50 this->vertex_opacity[1] = vertex_opacity[1]; 51 this->vertex_opacity[2] = vertex_opacity[2]; 52 this->vertex_opacity[3] = vertex_opacity[3]; 53 this->flipped = flipped; 54 } 55 56 void TextureDrawQuad::SetAll(const SharedQuadState* shared_quad_state, 57 const gfx::Rect& rect, 58 const gfx::Rect& opaque_rect, 59 const gfx::Rect& visible_rect, bool needs_blending, 60 unsigned resource_id, bool premultiplied_alpha, 61 const gfx::PointF& uv_top_left, 62 const gfx::PointF& uv_bottom_right, 63 SkColor background_color, 64 const float vertex_opacity[4], 65 bool flipped) { 66 DrawQuad::SetAll(shared_quad_state, DrawQuad::TEXTURE_CONTENT, rect, 67 opaque_rect, visible_rect, needs_blending); 68 this->resource_id = resource_id; 69 this->premultiplied_alpha = premultiplied_alpha; 70 this->uv_top_left = uv_top_left; 71 this->uv_bottom_right = uv_bottom_right; 72 this->background_color = background_color; 73 this->vertex_opacity[0] = vertex_opacity[0]; 74 this->vertex_opacity[1] = vertex_opacity[1]; 75 this->vertex_opacity[2] = vertex_opacity[2]; 76 this->vertex_opacity[3] = vertex_opacity[3]; 77 this->flipped = flipped; 78 } 79 80 void TextureDrawQuad::IterateResources( 81 const ResourceIteratorCallback& callback) { 82 resource_id = callback.Run(resource_id); 83 } 84 85 const TextureDrawQuad* TextureDrawQuad::MaterialCast(const DrawQuad* quad) { 86 DCHECK(quad->material == DrawQuad::TEXTURE_CONTENT); 87 return static_cast<const TextureDrawQuad*>(quad); 88 } 89 90 void TextureDrawQuad::ExtendValue(base::DictionaryValue* value) const { 91 value->SetInteger("resource_id", resource_id); 92 value->SetBoolean("premultiplied_alpha", premultiplied_alpha); 93 value->Set("uv_top_left", MathUtil::AsValue(uv_top_left).release()); 94 value->Set("uv_bottom_right", MathUtil::AsValue(uv_bottom_right).release()); 95 value->SetInteger("background_color", background_color); 96 scoped_ptr<base::ListValue> vertex_opacity_value(new base::ListValue); 97 for (size_t i = 0; i < 4; ++i) 98 vertex_opacity_value->AppendDouble(vertex_opacity[i]); 99 value->Set("vertex_opacity", vertex_opacity_value.release()); 100 value->SetBoolean("flipped", flipped); 101 } 102 103 } // namespace cc 104