Skip to content

Instantly share code, notes, and snippets.

View stoyannk's full-sized avatar

Stoyan Nikolov stoyannk

View GitHub Profile
@stoyannk
stoyannk / coro_example.cpp
Created May 5, 2019 13:48
Experiment with coroutines and cppcoro
using namespace cppcoro;
static const std::filesystem::path testCSS{"../test_res/style.css"};
static const std::filesystem::path testHTML{"../test_res/index.html"};
using DataBuffer = std::unique_ptr<std::uint8_t[]>;
task<DataBuffer> ReadFile(const std::filesystem::path& p)
{
DataBuffer result = std::make_unique<std::uint8_t[]>(len);
@stoyannk
stoyannk / task_example.cpp
Last active May 7, 2019 15:25
Task system sample
static const std::filesystem::path testHTML{"../test_res/index.html"};
static const std::filesystem::path testCSS{"../test_res/style.css"};
using DataBuffer = std::unique_ptr<std::uint8_t[]>;
struct Document
{
DataBuffer HTMLData;
DataBuffer CSSData;
std::mutex DataMut;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<!--
Created using JS Bin
http://jsbin.com
Copyright (c) 2017 by jakearchibald (http://jsbin.com/surane/7/edit)
Copyright (c) 2017 by Stoyan Nikolov
@stoyannk
stoyannk / TaskValidation.hpp
Last active April 22, 2017 12:52
Task Validation - marking types
// By default passing a naked pointer to a task is fobidden
template<typename T>
struct allow_thread_sharing_from_naked_ptr
{
using type = std::false_type;
};
// The macro allows explicitly marking a type
// as sharable in a task by naked pointer
#define ALLOW_TASK_SHARING_AS_NAKED_PTR(TYPE) \
@stoyannk
stoyannk / TaskValidation.hpp
Last active April 22, 2017 12:39
Task validation - validation function
template<typename T>
TaskValidation_t ValidateTaskParameters(const T& arg)
{
static_assert(meta_if<std::is_pointer<T>::value, typename allow_thread_sharing_from_naked_ptr<typename std::remove_pointer<typename std::remove_cv<T>::type>::type>::type, std::true_type>::type::value, "It is not allowed to pass naked pointers of this type in tasks!");
//.. More conditions omitted for brevity
static_assert(!forbid_thread_sharing<typename std::remove_pointer<typename std::remove_cv<T>::type>::type>::type::value, "This type is explicitly forbidden to be passed in tasks!");
return TaskValidation_t{};
}
@stoyannk
stoyannk / CreateTask.cpp
Created January 15, 2017 14:09
Task validation - create task
auto recalcVisualStyle = Task::Create("RecalculateVisualStyle",
TASK_PARAMS(recordRenderingParams, info)(Task*, TaskFamily) mutable {
LayoutSolver::RecalcVisualStyle(info,
recordRenderingParams->LayoutRoot.get(),
recordRenderingParams->ViewDims,
recordRenderingParams->DirtyRegion);
}
);
@stoyannk
stoyannk / BlendModesFuncSample_Fix.cpp
Created December 10, 2016 09:53
Sample for fixed blend modes function
static const BlendingState s_BlendingModes2State[] = {
{ /* Clear */
true,
BC_Zero,
BC_Zero,
BLOP_Add,
BC_Zero,
BC_Zero,
BLOP_Add,
},
@stoyannk
stoyannk / BlendModesFuncSample.cpp
Last active December 10, 2016 09:37
Sample of the blend modes unoptimal function
inline BlendingState BlendingMode2State(BlendModes mode)
{
static BlendingState states[] = {
{ /* Clear */
true,
BC_Zero,
BC_Zero,
BLOP_Add,
BC_Zero,
BC_Zero,
template
void Unite2D(const Rectangle& other, bool allowEmpty = false)
{
static_assert(sizeof...(Components) >= sizeof...(RhsComponents), "Cannot assign to type with less components than operand!");
static_assert(meta_contains_types<meta_packer, meta_packer>::value, "Operand has components that are not part of this object!");
m_Value.Unite2D(other.m_Value, allowEmpty);
}
@stoyannk
stoyannk / Data_oriented_example.cpp
Created November 14, 2015 09:20
Sample that shows different approaces in the desing of a problem. For the HPC course in FMI 2015.
// Data-oriented variant for drawing moving shapes
struct Positions
{
unsigned Count;
float* Xs; // Simplify SIMD-ification
float* Ys;
};
struct ShapePositions