Commit 8c25cdec by Jamie Madill

Only check dynamic type in Impl casting helpers.

We can use the Impl casting helper methods to clean up dynamic type casting. Change-Id: I5706da74eedd9f3cdc5a728420074a91ad7c95cb Reviewed-on: https://chromium-review.googlesource.com/263520Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent f4bf3811
......@@ -149,20 +149,4 @@ bool DebugAnnotationsActive();
#define UNREACHABLE() ERR("\t! Unreachable reached: %s(%d)\n", __FUNCTION__, __LINE__)
#endif
// A macro that determines whether an object has a given runtime type.
#if defined(__clang__)
#if __has_feature(cxx_rtti)
#define ANGLE_HAS_DYNAMIC_CAST 1
#endif
#elif !defined(NDEBUG) && (!defined(_MSC_VER) || defined(_CPPRTTI)) && (!defined(__GNUC__) || __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3) || defined(__GXX_RTTI))
#define ANGLE_HAS_DYNAMIC_CAST 1
#endif
#ifdef ANGLE_HAS_DYNAMIC_CAST
#define HAS_DYNAMIC_TYPE(type, obj) (dynamic_cast<type>(obj) != nullptr)
#undef ANGLE_HAS_DYNAMIC_CAST
#else
#define HAS_DYNAMIC_TYPE(type, obj) (obj != nullptr)
#endif
#endif // COMMON_DEBUG_H_
......@@ -289,21 +289,39 @@ enum VendorID : uint32_t
VENDOR_ID_NVIDIA = 0x10DE,
};
// A macro that determines whether an object has a given runtime type.
#if defined(__clang__)
#if __has_feature(cxx_rtti)
#define ANGLE_HAS_DYNAMIC_CAST 1
#endif
#elif !defined(NDEBUG) && (!defined(_MSC_VER) || defined(_CPPRTTI)) && (!defined(__GNUC__) || __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3) || defined(__GXX_RTTI))
#define ANGLE_HAS_DYNAMIC_CAST 1
#endif
#ifdef ANGLE_HAS_DYNAMIC_CAST
#define ANGLE_HAS_DYNAMIC_TYPE(type, obj) (dynamic_cast<type >(obj) != nullptr)
#undef ANGLE_HAS_DYNAMIC_CAST
#else
#define ANGLE_HAS_DYNAMIC_TYPE(type, obj) (obj != nullptr)
#endif
// Downcast a base implementation object (EG TextureImpl to TextureD3D)
template <typename DestT, typename SrcT>
inline DestT *GetAs(SrcT *src)
{
ASSERT(HAS_DYNAMIC_TYPE(DestT*, src));
ASSERT(ANGLE_HAS_DYNAMIC_TYPE(DestT*, src));
return static_cast<DestT*>(src);
}
template <typename DestT, typename SrcT>
inline const DestT *GetAs(const SrcT *src)
{
ASSERT(HAS_DYNAMIC_TYPE(const DestT*, src));
ASSERT(ANGLE_HAS_DYNAMIC_TYPE(const DestT*, src));
return static_cast<const DestT*>(src);
}
#undef ANGLE_HAS_DYNAMIC_TYPE
// Downcast a GL object to an Impl (EG gl::Texture to rx::TextureD3D)
template <typename DestT, typename SrcT>
inline DestT *GetImplAs(SrcT *src)
......
......@@ -449,9 +449,7 @@ ID3D11Buffer *Buffer11::getBuffer(BufferUsage usage)
return NULL;
}
ASSERT(HAS_DYNAMIC_TYPE(NativeStorage*, bufferStorage));
return static_cast<NativeStorage*>(bufferStorage)->getNativeStorage();
return GetAs<NativeStorage>(bufferStorage)->getNativeStorage();
}
ID3D11ShaderResourceView *Buffer11::getSRV(DXGI_FORMAT srvFormat)
......@@ -464,8 +462,7 @@ ID3D11ShaderResourceView *Buffer11::getSRV(DXGI_FORMAT srvFormat)
return NULL;
}
ASSERT(HAS_DYNAMIC_TYPE(NativeStorage*, storage));
ID3D11Buffer *buffer = static_cast<NativeStorage*>(storage)->getNativeStorage();
ID3D11Buffer *buffer = GetAs<NativeStorage>(storage)->getNativeStorage();
auto bufferSRVIt = mBufferResourceViews.find(srvFormat);
......@@ -628,8 +625,7 @@ Buffer11::NativeStorage *Buffer11::getStagingStorage()
return NULL;
}
ASSERT(HAS_DYNAMIC_TYPE(NativeStorage*, stagingStorage));
return static_cast<NativeStorage*>(stagingStorage);
return GetAs<NativeStorage>(stagingStorage);
}
Buffer11::PackStorage *Buffer11::getPackStorage()
......@@ -642,8 +638,7 @@ Buffer11::PackStorage *Buffer11::getPackStorage()
return NULL;
}
ASSERT(HAS_DYNAMIC_TYPE(PackStorage*, packStorage));
return static_cast<PackStorage*>(packStorage);
return GetAs<PackStorage>(packStorage);
}
bool Buffer11::supportsDirectBinding() const
......@@ -729,8 +724,6 @@ bool Buffer11::NativeStorage::copyFromStorage(BufferStorage *source, size_t sour
}
else
{
ASSERT(HAS_DYNAMIC_TYPE(NativeStorage*, source));
D3D11_BOX srcBox;
srcBox.left = sourceOffset;
srcBox.right = sourceOffset + size;
......@@ -739,8 +732,7 @@ bool Buffer11::NativeStorage::copyFromStorage(BufferStorage *source, size_t sour
srcBox.front = 0;
srcBox.back = 1;
ASSERT(HAS_DYNAMIC_TYPE(NativeStorage*, source));
ID3D11Buffer *sourceBuffer = static_cast<NativeStorage*>(source)->getNativeStorage();
ID3D11Buffer *sourceBuffer = GetAs<NativeStorage>(source)->getNativeStorage();
context->CopySubresourceRegion(mNativeStorage, 0, destOffset, 0, 0, sourceBuffer, 0, &srcBox);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment