Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3094)

Unified Diff: cc/layers/heads_up_display_layer_impl.cc

Issue 491783003: cc: Resource list for headup display (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rename to ResourceSizeIsEqualTo Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/layers/heads_up_display_layer_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/layers/heads_up_display_layer_impl.cc
diff --git a/cc/layers/heads_up_display_layer_impl.cc b/cc/layers/heads_up_display_layer_impl.cc
index fcb2733aee90279959fff97e43148cba86413eb4..51c0ed28466063145376a0bef136e345daec4af0 100644
--- a/cc/layers/heads_up_display_layer_impl.cc
+++ b/cc/layers/heads_up_display_layer_impl.cc
@@ -81,27 +81,51 @@ scoped_ptr<LayerImpl> HeadsUpDisplayLayerImpl::CreateLayerImpl(
return HeadsUpDisplayLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>();
}
-bool HeadsUpDisplayLayerImpl::WillDraw(DrawMode draw_mode,
- ResourceProvider* resource_provider) {
- if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE)
- return false;
+void HeadsUpDisplayLayerImpl::AcquireResource(
+ ResourceProvider* resource_provider) {
+ for (ScopedPtrVector<ScopedResource>::iterator it = resources_.begin();
+ it != resources_.end();
+ ++it) {
+ if (!resource_provider->InUseByConsumer((*it)->id())) {
+ resources_.swap(it, resources_.end() - 1);
+ return;
+ }
+ }
- if (!hud_resource_)
- hud_resource_ = ScopedResource::Create(resource_provider);
+ scoped_ptr<ScopedResource> resource =
+ ScopedResource::Create(resource_provider);
+ resource->Allocate(
+ content_bounds(), ResourceProvider::TextureHintImmutable, RGBA_8888);
+ resources_.push_back(resource.Pass());
+}
- // TODO(danakj): The HUD could swap between two textures instead of creating a
- // texture every frame in ubercompositor.
- if (hud_resource_->size() != content_bounds() ||
- (hud_resource_->id() &&
- resource_provider->InUseByConsumer(hud_resource_->id()))) {
- hud_resource_->Free();
- }
+class ResourceSizeIsEqualTo {
+ public:
+ explicit ResourceSizeIsEqualTo(const gfx::Size& size_)
+ : compare_size_(size_) {}
- if (!hud_resource_->id()) {
- hud_resource_->Allocate(
- content_bounds(), ResourceProvider::TextureHintImmutable, RGBA_8888);
+ bool operator()(const ScopedResource* resource) {
+ return resource->size() == compare_size_;
}
+ private:
+ const gfx::Size compare_size_;
+};
+
+void HeadsUpDisplayLayerImpl::ReleaseUnmatchedSizeResources(
+ ResourceProvider* resource_provider) {
+ ScopedPtrVector<ScopedResource>::iterator it_erase =
+ resources_.partition(ResourceSizeIsEqualTo(content_bounds()));
+ resources_.erase(it_erase, resources_.end());
+}
+
+bool HeadsUpDisplayLayerImpl::WillDraw(DrawMode draw_mode,
+ ResourceProvider* resource_provider) {
+ if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE)
+ return false;
+
+ ReleaseUnmatchedSizeResources(resource_provider);
+ AcquireResource(resource_provider);
return LayerImpl::WillDraw(draw_mode, resource_provider);
}
@@ -109,7 +133,7 @@ void HeadsUpDisplayLayerImpl::AppendQuads(
RenderPass* render_pass,
const OcclusionTracker<LayerImpl>& occlusion_tracker,
AppendQuadsData* append_quads_data) {
- if (!hud_resource_->id())
+ if (!resources_.back()->id())
return;
SharedQuadState* shared_quad_state =
@@ -130,7 +154,7 @@ void HeadsUpDisplayLayerImpl::AppendQuads(
quad_rect,
opaque_rect,
visible_quad_rect,
- hud_resource_->id(),
+ resources_.back()->id(),
premultiplied_alpha,
uv_top_left,
uv_bottom_right,
@@ -142,7 +166,7 @@ void HeadsUpDisplayLayerImpl::AppendQuads(
void HeadsUpDisplayLayerImpl::UpdateHudTexture(
DrawMode draw_mode,
ResourceProvider* resource_provider) {
- if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE || !hud_resource_->id())
+ if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE || !resources_.back()->id())
return;
SkISize canvas_size;
@@ -179,14 +203,16 @@ void HeadsUpDisplayLayerImpl::UpdateHudTexture(
DCHECK(pixels);
gfx::Rect content_rect(content_bounds());
DCHECK(info.colorType() == kN32_SkColorType);
- resource_provider->SetPixels(hud_resource_->id(),
+ resource_provider->SetPixels(resources_.back()->id(),
static_cast<const uint8_t*>(pixels),
content_rect,
content_rect,
gfx::Vector2d());
}
-void HeadsUpDisplayLayerImpl::ReleaseResources() { hud_resource_.reset(); }
+void HeadsUpDisplayLayerImpl::ReleaseResources() {
+ resources_.clear();
+}
void HeadsUpDisplayLayerImpl::UpdateHudContents() {
const LayerTreeDebugState& debug_state = layer_tree_impl()->debug_state();
« no previous file with comments | « cc/layers/heads_up_display_layer_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698