| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/android/compositor/scene_layer/static_tab_scene_layer.h
" | 5 #include "chrome/browser/android/compositor/scene_layer/static_tab_scene_layer.h
" |
| 6 | 6 |
| 7 #include "cc/layers/layer.h" | 7 #include "cc/layers/layer.h" |
| 8 #include "chrome/browser/android/compositor/layer/content_layer.h" | 8 #include "chrome/browser/android/compositor/layer/content_layer.h" |
| 9 #include "chrome/browser/android/compositor/layer_title_cache.h" | 9 #include "chrome/browser/android/compositor/layer_title_cache.h" |
| 10 #include "chrome/browser/android/compositor/tab_content_manager.h" | 10 #include "chrome/browser/android/compositor/tab_content_manager.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 return root && root->bounds() != layer_->bounds(); | 32 return root && root->bounds() != layer_->bounds(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 SkColor StaticTabSceneLayer::GetBackgroundColor() { | 35 SkColor StaticTabSceneLayer::GetBackgroundColor() { |
| 36 return background_color_; | 36 return background_color_; |
| 37 } | 37 } |
| 38 | 38 |
| 39 void StaticTabSceneLayer::UpdateTabLayer( | 39 void StaticTabSceneLayer::UpdateTabLayer( |
| 40 JNIEnv* env, | 40 JNIEnv* env, |
| 41 const JavaParamRef<jobject>& jobj, | 41 const JavaParamRef<jobject>& jobj, |
| 42 jfloat content_viewport_x, | |
| 43 jfloat content_viewport_y, | |
| 44 jfloat content_viewport_width, | |
| 45 jfloat content_viewport_height, | |
| 46 const JavaParamRef<jobject>& jtab_content_manager, | 42 const JavaParamRef<jobject>& jtab_content_manager, |
| 47 jint id, | 43 jint id, |
| 48 jint toolbar_resource_id, | 44 jint toolbar_resource_id, |
| 49 jboolean can_use_live_layer, | 45 jboolean can_use_live_layer, |
| 50 jint default_background_color, | 46 jint default_background_color, |
| 51 jfloat x, | 47 jfloat x, |
| 52 jfloat y, | 48 jfloat y, |
| 53 jfloat width, | |
| 54 jfloat height, | |
| 55 jfloat content_offset_y, | |
| 56 jfloat static_to_view_blend, | 49 jfloat static_to_view_blend, |
| 57 jfloat saturation, | 50 jfloat saturation, |
| 58 jfloat brightness) { | 51 jfloat brightness) { |
| 59 background_color_ = default_background_color; | 52 background_color_ = default_background_color; |
| 60 gfx::Size content_viewport_size(content_viewport_width, | |
| 61 content_viewport_height); | |
| 62 gfx::Point content_viewport_offset(content_viewport_x, content_viewport_y); | |
| 63 if (!content_layer_.get()) { | 53 if (!content_layer_.get()) { |
| 64 android::TabContentManager* tab_content_manager = | 54 android::TabContentManager* tab_content_manager = |
| 65 android::TabContentManager::FromJavaObject(jtab_content_manager); | 55 android::TabContentManager::FromJavaObject(jtab_content_manager); |
| 66 content_layer_ = android::ContentLayer::Create(tab_content_manager); | 56 content_layer_ = android::ContentLayer::Create(tab_content_manager); |
| 67 layer_->AddChild(content_layer_->layer()); | 57 layer_->AddChild(content_layer_->layer()); |
| 68 } | 58 } |
| 69 | 59 |
| 70 // Only override the alpha of content layers when the static tab is first | 60 // Only override the alpha of content layers when the static tab is first |
| 71 // assigned to the layer tree. | 61 // assigned to the layer tree. |
| 72 float content_alpha_override = 1.f; | 62 float content_alpha_override = 1.f; |
| 73 bool should_override_content_alpha = last_set_tab_id_ != id; | 63 bool should_override_content_alpha = last_set_tab_id_ != id; |
| 74 last_set_tab_id_ = id; | 64 last_set_tab_id_ = id; |
| 75 | 65 |
| 76 // Set up the content layer and move it to the proper position. | |
| 77 content_layer_->layer()->SetBounds(gfx::Size(width, height)); | |
| 78 content_layer_->layer()->SetPosition(gfx::PointF(x, y)); | |
| 79 content_layer_->SetProperties( | 66 content_layer_->SetProperties( |
| 80 id, can_use_live_layer, static_to_view_blend, | 67 id, can_use_live_layer, static_to_view_blend, |
| 81 should_override_content_alpha, content_alpha_override, saturation, | 68 should_override_content_alpha, content_alpha_override, saturation, |
| 82 gfx::Rect(content_viewport_size), content_viewport_size); | 69 false, gfx::Rect()); |
| 83 | |
| 84 gfx::Size content_bounds(0, 0); | |
| 85 content_bounds = content_layer_->layer()->bounds(); | |
| 86 | |
| 87 gfx::Size actual_content_size(content_layer_->GetContentSize()); | |
| 88 | |
| 89 bool view_and_content_have_same_orientation = | |
| 90 (content_viewport_size.width() > content_viewport_size.height()) == | |
| 91 (actual_content_size.width() > actual_content_size.height()) && | |
| 92 actual_content_size.width() > 0 && actual_content_size.height() > 0 && | |
| 93 content_viewport_size.width() > 0 && content_viewport_size.height() > 0; | |
| 94 | |
| 95 // This may not be true for frames during rotation. | |
| 96 bool content_has_consistent_width = | |
| 97 actual_content_size.width() == content_bounds.width() && | |
| 98 actual_content_size.width() == content_viewport_size.width(); | |
| 99 | |
| 100 if (view_and_content_have_same_orientation || | |
| 101 (content_has_consistent_width && content_layer_->ShowingLiveLayer())) { | |
| 102 y += content_offset_y; | |
| 103 } else { | |
| 104 // If our orientations are off and we have a static texture, or if we have | |
| 105 // a live layer of an unexpected width, move the texture in by the | |
| 106 // appropriate amount. | |
| 107 x += content_viewport_offset.x(); | |
| 108 y += content_viewport_offset.y(); | |
| 109 } | |
| 110 | 70 |
| 111 content_layer_->layer()->SetPosition(gfx::PointF(x, y)); | 71 content_layer_->layer()->SetPosition(gfx::PointF(x, y)); |
| 112 content_layer_->layer()->SetIsDrawable(true); | 72 content_layer_->layer()->SetIsDrawable(true); |
| 113 | 73 |
| 114 // Only applies the brightness filter if the value has changed and is less | 74 // Only applies the brightness filter if the value has changed and is less |
| 115 // than 1. | 75 // than 1. |
| 116 if (brightness != brightness_) { | 76 if (brightness != brightness_) { |
| 117 brightness_ = brightness; | 77 brightness_ = brightness; |
| 118 cc::FilterOperations filters; | 78 cc::FilterOperations filters; |
| 119 if (brightness_ < 1.f) | 79 if (brightness_ < 1.f) |
| 120 filters.Append(cc::FilterOperation::CreateBrightnessFilter(brightness_)); | 80 filters.Append(cc::FilterOperation::CreateBrightnessFilter(brightness_)); |
| 121 layer_->SetFilters(filters); | 81 layer_->SetFilters(filters); |
| 122 } | 82 } |
| 123 } | 83 } |
| 124 | 84 |
| 125 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& jobj) { | 85 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& jobj) { |
| 126 // This will automatically bind to the Java object and pass ownership there. | 86 // This will automatically bind to the Java object and pass ownership there. |
| 127 StaticTabSceneLayer* scene_layer = new StaticTabSceneLayer(env, jobj); | 87 StaticTabSceneLayer* scene_layer = new StaticTabSceneLayer(env, jobj); |
| 128 return reinterpret_cast<intptr_t>(scene_layer); | 88 return reinterpret_cast<intptr_t>(scene_layer); |
| 129 } | 89 } |
| 130 | 90 |
| 131 bool RegisterStaticTabSceneLayer(JNIEnv* env) { | 91 bool RegisterStaticTabSceneLayer(JNIEnv* env) { |
| 132 return RegisterNativesImpl(env); | 92 return RegisterNativesImpl(env); |
| 133 } | 93 } |
| 134 | 94 |
| 135 } // namespace android | 95 } // namespace android |
| OLD | NEW |