flutter_flutter/compositor/resource_manager.h
Adam Barth 95cbc86ade Sky shouldn't crash on device rotate
There were two problems (both fixed in this CL):

1) When we were resized by the view manager, we forgot to deflate by the
   device-pixel-ratio when converting to engine types. That caused use to
   allocate a backing texture that was 9x what we needed.

2) When the surfaces system returned textures to us for re-use, we'd put them
   into the cache even if they were the old size. That caused us to thrash the
   texture cache. In this CL, we make the size of the textures in the cache
   explicit.

R=eseidel@chromium.org
BUG=449001

Review URL: https://codereview.chromium.org/868263002
2015-01-23 21:20:14 -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"
#include "sky/compositor/texture_cache.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_;
TextureCache texture_cache_;
DISALLOW_COPY_AND_ASSIGN(ResourceManager);
};
} // namespace sky
#endif // SKY_COMPOSITOR_RESOURCE_MANAGER_H_