diff options
author | clholgat@chromium.org <clholgat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-15 17:54:58 +0000 |
---|---|---|
committer | clholgat@chromium.org <clholgat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-15 17:54:58 +0000 |
commit | e95e40f8561c5231f475cba340e4c30424d8e0bf (patch) | |
tree | c5df2376379e2d6b5f5b6adde38a0f49d941fe6a | |
parent | f0d1c8916ba5d13a4ed2a6cf67fd3ebd19a4caa0 (diff) | |
download | chromium_src-e95e40f8561c5231f475cba340e4c30424d8e0bf.zip chromium_src-e95e40f8561c5231f475cba340e4c30424d8e0bf.tar.gz chromium_src-e95e40f8561c5231f475cba340e4c30424d8e0bf.tar.bz2 |
Adding UV and vertex opacity to UIResourceLayer
We need UV and vertex opacity on the Android side.
Review URL: https://codereview.chromium.org/26948003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@228719 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | cc/layers/ui_resource_layer.cc | 40 | ||||
-rw-r--r-- | cc/layers/ui_resource_layer.h | 14 | ||||
-rw-r--r-- | cc/layers/ui_resource_layer_impl.cc | 53 | ||||
-rw-r--r-- | cc/layers/ui_resource_layer_impl.h | 11 |
4 files changed, 109 insertions, 9 deletions
diff --git a/cc/layers/ui_resource_layer.cc b/cc/layers/ui_resource_layer.cc index 8edc19e..09b8d9a 100644 --- a/cc/layers/ui_resource_layer.cc +++ b/cc/layers/ui_resource_layer.cc @@ -55,7 +55,15 @@ scoped_refptr<UIResourceLayer> UIResourceLayer::Create() { return make_scoped_refptr(new UIResourceLayer()); } -UIResourceLayer::UIResourceLayer() {} +UIResourceLayer::UIResourceLayer() + : Layer(), + uv_top_left_(0.f, 0.f), + uv_bottom_right_(1.f, 1.f) { + vertex_opacity_[0] = 1.0f; + vertex_opacity_[1] = 1.0f; + vertex_opacity_[2] = 1.0f; + vertex_opacity_[3] = 1.0f; +} UIResourceLayer::~UIResourceLayer() {} @@ -64,6 +72,34 @@ scoped_ptr<LayerImpl> UIResourceLayer::CreateLayerImpl( return UIResourceLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); } +void UIResourceLayer::SetUV(gfx::PointF top_left, gfx::PointF bottom_right) { + if (uv_top_left_ == top_left && uv_bottom_right_ == bottom_right) + return; + uv_top_left_ = top_left; + uv_bottom_right_ = bottom_right; + SetNeedsCommit(); +} + +void UIResourceLayer::SetVertexOpacity(float bottom_left, + float top_left, + float top_right, + float bottom_right) { + // Indexing according to the quad vertex generation: + // 1--2 + // | | + // 0--3 + if (vertex_opacity_[0] == bottom_left && + vertex_opacity_[1] == top_left && + vertex_opacity_[2] == top_right && + vertex_opacity_[3] == bottom_right) + return; + vertex_opacity_[0] = bottom_left; + vertex_opacity_[1] = top_left; + vertex_opacity_[2] = top_right; + vertex_opacity_[3] = bottom_right; + SetNeedsCommit(); +} + void UIResourceLayer::SetLayerTreeHost(LayerTreeHost* host) { if (host == layer_tree_host()) return; @@ -121,6 +157,8 @@ void UIResourceLayer::PushPropertiesTo(LayerImpl* layer) { layer_tree_host()->GetUIResourceSize(ui_resource_holder_->id()); layer_impl->SetUIResourceId(ui_resource_holder_->id()); layer_impl->SetImageBounds(image_size); + layer_impl->SetUV(uv_top_left_, uv_bottom_right_); + layer_impl->SetVertexOpacity(vertex_opacity_); } } diff --git a/cc/layers/ui_resource_layer.h b/cc/layers/ui_resource_layer.h index 173ca44..69721a3 100644 --- a/cc/layers/ui_resource_layer.h +++ b/cc/layers/ui_resource_layer.h @@ -31,6 +31,16 @@ class CC_EXPORT UIResourceLayer : public Layer { // An alternative way of setting the resource to allow for sharing. void SetUIResourceId(UIResourceId resource_id); + // Sets a UV transform to be used at draw time. Defaults to (0, 0) and (1, 1). + void SetUV(gfx::PointF top_left, gfx::PointF bottom_right); + + // Sets an opacity value per vertex. It will be multiplied by the layer + // opacity value. + void SetVertexOpacity(float bottom_left, + float top_left, + float top_right, + float bottom_right); + class UIResourceHolder { public: virtual UIResourceId id() = 0; @@ -44,6 +54,10 @@ class CC_EXPORT UIResourceLayer : public Layer { scoped_ptr<UIResourceHolder> ui_resource_holder_; SkBitmap bitmap_; + gfx::PointF uv_top_left_; + gfx::PointF uv_bottom_right_; + float vertex_opacity_[4]; + private: virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) OVERRIDE; diff --git a/cc/layers/ui_resource_layer_impl.cc b/cc/layers/ui_resource_layer_impl.cc index faa3171..23e33f90 100644 --- a/cc/layers/ui_resource_layer_impl.cc +++ b/cc/layers/ui_resource_layer_impl.cc @@ -16,7 +16,14 @@ namespace cc { UIResourceLayerImpl::UIResourceLayerImpl(LayerTreeImpl* tree_impl, int id) : LayerImpl(tree_impl, id), - ui_resource_id_(0) {} + ui_resource_id_(0), + uv_top_left_(0.f, 0.f), + uv_bottom_right_(1.f, 1.f) { + vertex_opacity_[0] = 1.0f; + vertex_opacity_[1] = 1.0f; + vertex_opacity_[2] = 1.0f; + vertex_opacity_[3] = 1.0f; +} UIResourceLayerImpl::~UIResourceLayerImpl() {} @@ -31,6 +38,8 @@ void UIResourceLayerImpl::PushPropertiesTo(LayerImpl* layer) { layer_impl->SetUIResourceId(ui_resource_id_); layer_impl->SetImageBounds(image_bounds_); + layer_impl->SetUV(uv_top_left_, uv_bottom_right_); + layer_impl->SetVertexOpacity(vertex_opacity_); } void UIResourceLayerImpl::SetUIResourceId(UIResourceId uid) { @@ -53,6 +62,28 @@ void UIResourceLayerImpl::SetImageBounds(gfx::Size image_bounds) { NoteLayerPropertyChanged(); } +void UIResourceLayerImpl::SetUV(gfx::PointF top_left, + gfx::PointF bottom_right) { + if (uv_top_left_ == top_left && uv_bottom_right_ == bottom_right) + return; + uv_top_left_ = top_left; + uv_bottom_right_ = bottom_right; + NoteLayerPropertyChanged(); +} + +void UIResourceLayerImpl::SetVertexOpacity(const float vertex_opacity[4]) { + if (vertex_opacity_[0] == vertex_opacity[0] && + vertex_opacity_[1] == vertex_opacity[1] && + vertex_opacity_[2] == vertex_opacity[2] && + vertex_opacity_[3] == vertex_opacity[3]) + return; + vertex_opacity_[0] = vertex_opacity[0]; + vertex_opacity_[1] = vertex_opacity[1]; + vertex_opacity_[2] = vertex_opacity[2]; + vertex_opacity_[3] = vertex_opacity[3]; + NoteLayerPropertyChanged(); +} + bool UIResourceLayerImpl::WillDraw(DrawMode draw_mode, ResourceProvider* resource_provider) { if (!ui_resource_id_ || draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE) @@ -81,13 +112,9 @@ void UIResourceLayerImpl::AppendQuads(QuadSink* quad_sink, DCHECK(!bounds().IsEmpty()); gfx::Rect quad_rect(bounds()); - gfx::Rect uv_top_left(0.f, 0.f); - gfx::Rect uv_bottom_right(1.f, 1.f); // TODO(clholgat): Properly calculate opacity: crbug.com/300027 gfx::Rect opaque_rect(contents_opaque() ? quad_rect : gfx::Rect()); - - const float vertex_opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; scoped_ptr<TextureDrawQuad> quad; quad = TextureDrawQuad::Create(); @@ -96,10 +123,10 @@ void UIResourceLayerImpl::AppendQuads(QuadSink* quad_sink, opaque_rect, resource, premultiplied_alpha, - uv_top_left.origin(), - uv_bottom_right.bottom_right(), + uv_top_left_, + uv_bottom_right_, SK_ColorTRANSPARENT, - vertex_opacity, + vertex_opacity_, flipped); quad_sink->Append(quad.PassAs<DrawQuad>(), append_quads_data); } @@ -113,6 +140,16 @@ base::DictionaryValue* UIResourceLayerImpl::LayerTreeAsJson() const { result->Set("ImageBounds", MathUtil::AsValue(image_bounds_).release()); + base::ListValue* list = new base::ListValue; + list->AppendDouble(vertex_opacity_[0]); + list->AppendDouble(vertex_opacity_[1]); + list->AppendDouble(vertex_opacity_[2]); + list->AppendDouble(vertex_opacity_[3]); + result->Set("VertexOpacity", list); + + result->Set("UVTopLeft", MathUtil::AsValue(uv_top_left_).release()); + result->Set("UVBottomRight", MathUtil::AsValue(uv_bottom_right_).release()); + return result; } diff --git a/cc/layers/ui_resource_layer_impl.h b/cc/layers/ui_resource_layer_impl.h index 4c1ffb6..7f20050 100644 --- a/cc/layers/ui_resource_layer_impl.h +++ b/cc/layers/ui_resource_layer_impl.h @@ -32,6 +32,13 @@ class CC_EXPORT UIResourceLayerImpl : public LayerImpl { void SetImageBounds(gfx::Size image_bounds); + // Sets a UV transform to be used at draw time. Defaults to (0, 0) and (1, 1). + void SetUV(gfx::PointF top_left, gfx::PointF bottom_right); + + // Sets an opacity value per vertex. It will be multiplied by the layer + // opacity value. + void SetVertexOpacity(const float vertex_opacity[4]); + virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) OVERRIDE; virtual void PushPropertiesTo(LayerImpl* layer) OVERRIDE; @@ -51,6 +58,10 @@ class CC_EXPORT UIResourceLayerImpl : public LayerImpl { UIResourceId ui_resource_id_; + gfx::PointF uv_top_left_; + gfx::PointF uv_bottom_right_; + float vertex_opacity_[4]; + private: virtual const char* LayerTypeAsString() const OVERRIDE; |