flutter_flutter/compositor/resource_manager.h
Adam Barth 1ae192ac2e The Sky compositor should recycle textures
Previously, we were creating a new texture for every frame. Using tracing on a
Nexus 5, that appears to cost about 6ms per frame on the GPU thread. After this
CL, we keep a cache of recently used textures and only allocate a new one when
either (1) we don't have one free or (2) our size requirements have changed.

If our size requirements change, we dump the whole texture cache. In the
future, we'll probably need something fancier if we ever need more than one
size texture per frame.

R=jamesr@chromium.org

Review URL: https://codereview.chromium.org/845963006
2015-01-15 11:09:56 -08:00

50 lines
1.3 KiB
C++

// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SKY_COMPOSITOR_RESOURCE_MANAGER_H_
#define SKY_COMPOSITOR_RESOURCE_MANAGER_H_
#include "base/containers/hash_tables.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "base/memory/weak_ptr.h"
#include "mojo/services/surfaces/public/interfaces/surfaces.mojom.h"
namespace gfx {
class Size;
}
namespace mojo {
class GLContext;
class GLTexture;
}
namespace sky {
class Layer;
class LayerHost;
class ResourceManager {
public:
explicit ResourceManager(base::WeakPtr<mojo::GLContext> gl_context);
~ResourceManager();
scoped_ptr<mojo::GLTexture> CreateTexture(const gfx::Size& size);
mojo::TransferableResourcePtr CreateTransferableResource(Layer* layer);
void ReturnResources(mojo::Array<mojo::ReturnedResourcePtr> resources);
private:
base::WeakPtr<mojo::GLContext> gl_context_;
uint32_t next_resource_id_;
base::hash_map<uint32_t, mojo::GLTexture*> resource_to_texture_map_;
ScopedVector<mojo::GLTexture> available_textures_;
DISALLOW_COPY_AND_ASSIGN(ResourceManager);
};
} // namespace examples
#endif // SKY_COMPOSITOR_RESOURCE_MANAGER_H_