blob: d6fd0b71f71737579a32081f973511def055462b [file] [log] [blame]
// Copyright 2016 The Cobalt Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef COBALT_LOADER_FONT_REMOTE_TYPEFACE_CACHE_H_
#define COBALT_LOADER_FONT_REMOTE_TYPEFACE_CACHE_H_
#include <memory>
#include <string>
#include "cobalt/loader/loader_factory.h"
#include "cobalt/loader/resource_cache.h"
#include "cobalt/render_tree/typeface.h"
namespace cobalt {
namespace render_tree {
class Typeface;
} // namespace render_tree
namespace loader {
namespace font {
// |RemoteTypefaceResourceCacheType| provides the types and implements the
// functions required by |ResourceCache<CacheType>|
struct RemoteTypefaceResourceCacheType {
typedef render_tree::Typeface ResourceType;
static uint32 GetEstimatedSizeInBytes(
const scoped_refptr<ResourceType>& resource) {
return resource->GetEstimatedSizeInBytes();
}
};
typedef CachedResource<RemoteTypefaceResourceCacheType> CachedRemoteTypeface;
typedef CachedResourceReferenceWithCallbacks
CachedRemoteTypefaceReferenceWithCallbacks;
typedef CachedRemoteTypefaceReferenceWithCallbacks::
CachedResourceReferenceVector CachedRemoteTypefaceReferenceVector;
typedef ResourceCache<RemoteTypefaceResourceCacheType> RemoteTypefaceCache;
// CreateTypefaceCache() provides a mechanism for creating a remote typeface
// cache.
inline static std::unique_ptr<RemoteTypefaceCache> CreateRemoteTypefaceCache(
const std::string& name, const base::DebuggerHooks& debugger_hooks,
uint32 cache_capacity, loader::LoaderFactory* loader_factory) {
return std::unique_ptr<RemoteTypefaceCache>(new RemoteTypefaceCache(
name, debugger_hooks, cache_capacity,
true /*are_loading_retries_enabled*/,
base::Bind(&loader::LoaderFactory::CreateTypefaceLoader,
base::Unretained(loader_factory))));
}
} // namespace font
} // namespace loader
} // namespace cobalt
#endif // COBALT_LOADER_FONT_REMOTE_TYPEFACE_CACHE_H_