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

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: remove unnecessary run in common case. 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..1f926ee446e9de31c20433a2801897f38d3872ab 100644
--- a/cc/layers/heads_up_display_layer_impl.cc
+++ b/cc/layers/heads_up_display_layer_impl.cc
@@ -50,6 +50,18 @@ static inline SkPaint CreatePaint() {
return paint;
}
+class CompareResourceSize {
danakj 2014/08/29 16:42:46 move this down above the function that uses it
+ public:
+ explicit CompareResourceSize(gfx::Size size_) : compare_size_(size_) {}
danakj 2014/08/29 16:42:47 const gfx::Size&
+
+ bool operator()(const ScopedResource* resource) {
+ return (resource->size() == compare_size_);
danakj 2014/08/29 16:42:47 drop the extra ()s
+ }
+
+ private:
+ const gfx::Size compare_size_;
+};
+
HeadsUpDisplayLayerImpl::Graph::Graph(double indicator_value,
double start_upper_bound)
: value(0.0),
@@ -81,27 +93,46 @@ 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();
+void HeadsUpDisplayLayerImpl::ReleaseUnmatchedSizeResources(
+ ResourceProvider* resource_provider) {
+ ScopedPtrVector<ScopedResource>::iterator it_erase = resources_.end();
+ for (ScopedPtrVector<ScopedResource>::iterator it = resources_.begin();
+ it != resources_.end();
+ ++it) {
+ if ((*it)->size() != content_bounds()) {
+ it_erase = resources_.partition(CompareResourceSize(content_bounds()));
danakj 2014/08/29 16:42:47 if you wanna use partition, why do the for loop ar
+ break;
+ }
}
+ if (it_erase != resources_.end())
danakj 2014/08/29 16:42:46 drop the if, just erase.
+ resources_.erase(it_erase, resources_.end());
+}
- if (!hud_resource_->id()) {
- hud_resource_->Allocate(
- content_bounds(), ResourceProvider::TextureHintImmutable, RGBA_8888);
- }
+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 +140,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 +161,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 +173,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 +210,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