blob: 3f953a782043031b928343f557467e4e003e5bea [file] [log] [blame]
// Copyright 2016 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 CompositorElementId_h
#define CompositorElementId_h
#include "cc/trees/element_id.h"
#include "platform/PlatformExport.h"
#include "platform/wtf/HashFunctions.h"
#include "platform/wtf/HashSet.h"
#include "platform/wtf/HashTraits.h"
namespace blink {
const int kCompositorNamespaceBitCount = 3;
enum class CompositorElementIdNamespace {
kPrimary,
kUniqueObjectId,
kScroll,
// The following are SPv2-only.
kEffectFilter,
kEffectMask,
kEffectClipPath,
// A sentinel to indicate the maximum representable namespace id
// (the maximum is one less than this value).
kMaxRepresentableNamespaceId = 1 << kCompositorNamespaceBitCount
};
using CompositorElementId = cc::ElementId;
using ScrollbarId = uint64_t;
using UniqueObjectId = uint64_t;
using DOMNodeId = uint64_t;
using SyntheticEffectId = uint64_t;
// Call this to get a globally unique object id for a newly allocated object.
UniqueObjectId PLATFORM_EXPORT NewUniqueObjectId();
// Call this with an appropriate namespace if more than one CompositorElementId
// is required for the given UniqueObjectId.
CompositorElementId PLATFORM_EXPORT
CompositorElementIdFromUniqueObjectId(UniqueObjectId,
CompositorElementIdNamespace);
// ...and otherwise call this method if there is only one CompositorElementId
// required for the given UniqueObjectId.
CompositorElementId PLATFORM_EXPORT
CompositorElementIdFromUniqueObjectId(UniqueObjectId);
// TODO(chrishtr): refactor ScrollState to remove this dependency.
CompositorElementId PLATFORM_EXPORT CompositorElementIdFromDOMNodeId(DOMNodeId);
// Note cc::ElementId has a hash function already implemented via
// ElementIdHash::operator(). However for consistency's sake we choose to use
// Blink's hash functions with Blink specific data structures.
struct CompositorElementIdHash {
static unsigned GetHash(const CompositorElementId& key) {
return WTF::HashInt(static_cast<cc::ElementIdType>(key.ToInternalValue()));
}
static bool Equal(const CompositorElementId& a,
const CompositorElementId& b) {
return a == b;
}
static const bool safe_to_compare_to_empty_or_deleted = true;
};
CompositorElementIdNamespace PLATFORM_EXPORT
NamespaceFromCompositorElementId(CompositorElementId);
struct CompositorElementIdHashTraits
: WTF::GenericHashTraits<CompositorElementId> {
static CompositorElementId EmptyValue() { return CompositorElementId(1); }
static void ConstructDeletedValue(CompositorElementId& slot, bool) {
slot = CompositorElementId();
}
static bool IsDeletedValue(CompositorElementId value) {
return value == CompositorElementId();
}
};
using CompositorElementIdSet = HashSet<CompositorElementId,
CompositorElementIdHash,
CompositorElementIdHashTraits>;
} // namespace blink
#endif // CompositorElementId_h