| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "cc/layers/surface_layer.h" | 5 #include "cc/layers/surface_layer.h" |
| 6 | 6 |
| 7 #include "cc/base/swap_promise.h" | 7 #include "cc/base/swap_promise.h" |
| 8 #include "cc/layers/surface_layer_impl.h" | 8 #include "cc/layers/surface_layer_impl.h" |
| 9 #include "cc/trees/layer_tree_host.h" | 9 #include "cc/trees/layer_tree_host.h" |
| 10 | 10 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 scoped_refptr<SurfaceLayer> SurfaceLayer::Create( | 37 scoped_refptr<SurfaceLayer> SurfaceLayer::Create( |
| 38 const SatisfyCallback& satisfy_callback, | 38 const SatisfyCallback& satisfy_callback, |
| 39 const RequireCallback& require_callback) { | 39 const RequireCallback& require_callback) { |
| 40 return make_scoped_refptr( | 40 return make_scoped_refptr( |
| 41 new SurfaceLayer(satisfy_callback, require_callback)); | 41 new SurfaceLayer(satisfy_callback, require_callback)); |
| 42 } | 42 } |
| 43 | 43 |
| 44 SurfaceLayer::SurfaceLayer(const SatisfyCallback& satisfy_callback, | 44 SurfaceLayer::SurfaceLayer(const SatisfyCallback& satisfy_callback, |
| 45 const RequireCallback& require_callback) | 45 const RequireCallback& require_callback) |
| 46 : Layer(), | 46 : Layer(), |
| 47 surface_scale_(1.f), |
| 47 satisfy_callback_(satisfy_callback), | 48 satisfy_callback_(satisfy_callback), |
| 48 require_callback_(require_callback) { | 49 require_callback_(require_callback) { |
| 49 } | 50 } |
| 50 | 51 |
| 51 SurfaceLayer::~SurfaceLayer() { | 52 SurfaceLayer::~SurfaceLayer() { |
| 52 DCHECK(!layer_tree_host()); | 53 DCHECK(!layer_tree_host()); |
| 53 DCHECK(destroy_sequence_.is_null()); | 54 DCHECK(destroy_sequence_.is_null()); |
| 54 } | 55 } |
| 55 | 56 |
| 56 void SurfaceLayer::SetSurfaceId(SurfaceId surface_id, const gfx::Size& size) { | 57 void SurfaceLayer::SetSurfaceId(SurfaceId surface_id, |
| 58 float scale, |
| 59 const gfx::Size& size) { |
| 57 SatisfyDestroySequence(); | 60 SatisfyDestroySequence(); |
| 58 surface_id_ = surface_id; | 61 surface_id_ = surface_id; |
| 59 surface_size_ = size; | 62 surface_size_ = size; |
| 63 surface_scale_ = scale; |
| 60 CreateNewDestroySequence(); | 64 CreateNewDestroySequence(); |
| 61 | 65 |
| 62 UpdateDrawsContent(HasDrawableContent()); | 66 UpdateDrawsContent(HasDrawableContent()); |
| 63 SetNeedsPushProperties(); | 67 SetNeedsPushProperties(); |
| 64 } | 68 } |
| 65 | 69 |
| 66 scoped_ptr<LayerImpl> SurfaceLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) { | 70 scoped_ptr<LayerImpl> SurfaceLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) { |
| 67 return SurfaceLayerImpl::Create(tree_impl, id()); | 71 return SurfaceLayerImpl::Create(tree_impl, id()); |
| 68 } | 72 } |
| 69 | 73 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 87 SurfaceLayerImpl* layer_impl = static_cast<SurfaceLayerImpl*>(layer); | 91 SurfaceLayerImpl* layer_impl = static_cast<SurfaceLayerImpl*>(layer); |
| 88 | 92 |
| 89 layer_impl->SetSurfaceId(surface_id_); | 93 layer_impl->SetSurfaceId(surface_id_); |
| 90 } | 94 } |
| 91 | 95 |
| 92 void SurfaceLayer::CalculateContentsScale(float ideal_contents_scale, | 96 void SurfaceLayer::CalculateContentsScale(float ideal_contents_scale, |
| 93 float* contents_scale_x, | 97 float* contents_scale_x, |
| 94 float* contents_scale_y, | 98 float* contents_scale_y, |
| 95 gfx::Size* content_bounds) { | 99 gfx::Size* content_bounds) { |
| 96 *content_bounds = surface_size_; | 100 *content_bounds = surface_size_; |
| 97 *contents_scale_x = | 101 *contents_scale_x = surface_scale_; |
| 98 bounds().IsEmpty() ? 1.f : static_cast<float>(content_bounds->width()) / | 102 *contents_scale_y = surface_scale_; |
| 99 bounds().width(); | |
| 100 *contents_scale_y = | |
| 101 bounds().IsEmpty() ? 1.f : static_cast<float>(content_bounds->height()) / | |
| 102 bounds().height(); | |
| 103 } | 103 } |
| 104 | 104 |
| 105 void SurfaceLayer::CreateNewDestroySequence() { | 105 void SurfaceLayer::CreateNewDestroySequence() { |
| 106 DCHECK(destroy_sequence_.is_null()); | 106 DCHECK(destroy_sequence_.is_null()); |
| 107 if (layer_tree_host()) { | 107 if (layer_tree_host()) { |
| 108 destroy_sequence_ = layer_tree_host()->CreateSurfaceSequence(); | 108 destroy_sequence_ = layer_tree_host()->CreateSurfaceSequence(); |
| 109 require_callback_.Run(surface_id_, destroy_sequence_); | 109 require_callback_.Run(surface_id_, destroy_sequence_); |
| 110 } | 110 } |
| 111 } | 111 } |
| 112 | 112 |
| 113 void SurfaceLayer::SatisfyDestroySequence() { | 113 void SurfaceLayer::SatisfyDestroySequence() { |
| 114 if (!layer_tree_host()) | 114 if (!layer_tree_host()) |
| 115 return; | 115 return; |
| 116 DCHECK(!destroy_sequence_.is_null()); | 116 DCHECK(!destroy_sequence_.is_null()); |
| 117 scoped_ptr<SatisfySwapPromise> satisfy( | 117 scoped_ptr<SatisfySwapPromise> satisfy( |
| 118 new SatisfySwapPromise(destroy_sequence_, satisfy_callback_)); | 118 new SatisfySwapPromise(destroy_sequence_, satisfy_callback_)); |
| 119 layer_tree_host()->QueueSwapPromise(satisfy.Pass()); | 119 layer_tree_host()->QueueSwapPromise(satisfy.Pass()); |
| 120 destroy_sequence_ = SurfaceSequence(); | 120 destroy_sequence_ = SurfaceSequence(); |
| 121 } | 121 } |
| 122 | 122 |
| 123 } // namespace cc | 123 } // namespace cc |
| OLD | NEW |