ref_ptr<IDCollections> UserMarkGenerator::GetIdCollection(TileKey const & tileKey, kml::MarkGroupId groupId) { ref_ptr<MarksIDGroups> tileGroups; auto itTileGroups = m_index.find(tileKey); if (itTileGroups == m_index.end()) { auto tileIDGroups = make_unique_dp<MarksIDGroups>(); tileGroups = make_ref(tileIDGroups); m_index.insert(make_pair(tileKey, std::move(tileIDGroups))); } else { tileGroups = make_ref(itTileGroups->second); } ref_ptr<IDCollections> groupIDs; auto itGroupIDs = tileGroups->find(groupId); if (itGroupIDs == tileGroups->end()) { auto groupMarkIndexes = make_unique_dp<IDCollections>(); groupIDs = make_ref(groupMarkIndexes); tileGroups->insert(make_pair(groupId, std::move(groupMarkIndexes))); } else { groupIDs = make_ref(itGroupIDs->second); } return groupIDs; }
void sendSync(Args...args) { typename CommandSync<T>::FlagType flag(0); send<CommandSync<T>>(make_ref(*this), make_ref(flag), args...); beginWait(); while(!flag) wait(); endWait(); }
struct regexp *make_regexp(struct info *info, char *pat) { struct regexp *regexp; make_ref(regexp); regexp->info = ref(info); make_ref(regexp->pattern); regexp->pattern->str = pat; return regexp; }
FontTexture(m2::PointU const & size, ref_ptr<GlyphManager> glyphMng, ref_ptr<HWTextureAllocator> allocator) : m_index(size, glyphMng) { TBase::TextureParams params; params.m_size = size; params.m_format = TextureFormat::ALPHA; params.m_filter = gl_const::GLLinear; vector<uint8_t> initData(params.m_size.x * params.m_size.y, 0); TBase::Init(allocator, make_ref(&m_index), params, make_ref(initData.data())); }
static struct regexp *make_key_regexp(struct info *info, const char *pat) { struct regexp *regexp; size_t len = strlen(pat) + 4; make_ref(regexp); make_ref(regexp->pattern); regexp->info = ref(info); CALLOC(regexp->pattern->str, len); snprintf(regexp->pattern->str, len, "(%s)/", pat); return regexp; }
ref_ptr<RenderBucket> Batcher::GetBucket(GLState const & state) { TBuckets::iterator it = m_buckets.find(state); if (it != m_buckets.end()) return make_ref(it->second); drape_ptr<VertexArrayBuffer> vao = make_unique_dp<VertexArrayBuffer>(m_indexBufferSize, m_vertexBufferSize); drape_ptr<RenderBucket> buffer = make_unique_dp<RenderBucket>(move(vao)); ref_ptr<RenderBucket> result = make_ref(buffer); m_buckets.emplace(state, move(buffer)); return result; }
drape_ptr<ShapeRenderer> Watermark::Draw(ref_ptr<dp::GraphicsContext> context, m2::PointF & size, ref_ptr<dp::TextureManager> tex) const { dp::TextureManager::SymbolRegion region; tex->GetSymbolRegion("watermark", region); glsl::vec2 const halfSize = glsl::ToVec2(region.GetPixelSize() * 0.5f); m2::RectF const texRect = region.GetTexRect(); WatermarkVertex vertexes[] = { WatermarkVertex(glsl::vec2(-halfSize.x, halfSize.y), glsl::ToVec2(texRect.LeftTop())), WatermarkVertex(glsl::vec2(-halfSize.x, -halfSize.y), glsl::ToVec2(texRect.LeftBottom())), WatermarkVertex(glsl::vec2(halfSize.x, halfSize.y), glsl::ToVec2(texRect.RightTop())), WatermarkVertex(glsl::vec2(halfSize.x, -halfSize.y), glsl::ToVec2(texRect.RightBottom())) }; auto state = df::CreateRenderState(gpu::Program::TexturingGui, df::DepthLayer::GuiLayer); state.SetColorTexture(region.GetTexture()); state.SetDepthTestEnabled(false); dp::AttributeProvider provider(1 /* streamCount */, 4 /* vertexCount */); dp::BindingInfo info(2 /* count */); dp::BindingDecl & posDecl = info.GetBindingDecl(0); posDecl.m_attributeName = "a_position"; posDecl.m_componentCount = 2; posDecl.m_componentType = gl_const::GLFloatType; posDecl.m_offset = 0; posDecl.m_stride = sizeof(WatermarkVertex); dp::BindingDecl & texDecl = info.GetBindingDecl(1); texDecl.m_attributeName = "a_colorTexCoords"; texDecl.m_componentCount = 2; texDecl.m_componentType = gl_const::GLFloatType; texDecl.m_offset = sizeof(glsl::vec2); texDecl.m_stride = posDecl.m_stride; provider.InitStream(0, info, make_ref(&vertexes)); size = region.GetPixelSize(); drape_ptr<dp::OverlayHandle> handle = make_unique_dp<WatermarkVertexHandle>( EGuiHandle::GuiHandleWatermark, m_position.m_pixelPivot, m_position.m_anchor, size); drape_ptr<ShapeRenderer> renderer = make_unique_dp<ShapeRenderer>(); dp::Batcher batcher(dp::Batcher::IndexPerQuad, dp::Batcher::VertexPerQuad); batcher.SetBatcherHash(static_cast<uint64_t>(df::BatcherBucket::Default)); dp::SessionGuard guard(context, batcher, std::bind(&ShapeRenderer::AddShape, renderer.get(), _1, _2)); batcher.InsertTriangleStrip(context, state, make_ref(&provider), std::move(handle)); return renderer; }
ref_ptr<MarksIDGroups> UserMarkGenerator::GetUserMarksGroups(TileKey const & tileKey) { auto const itTile = m_index.find(tileKey); if (itTile != m_index.end()) return make_ref(itTile->second); return nullptr; }
struct transform *make_transform(struct lens *lens, struct filter *filter) { struct transform *xform; make_ref(xform); xform->lens = lens; xform->filter = filter; return xform; }
void lcb_callback(void *lcb, lua_State *L, int idx) { LuaCallback *data = (LuaCallback*) lcb; data->L = L; data->callback = make_ref(L,idx); data->buf = NULL; data->handle = NULL; }
/* * Filters */ struct filter *make_filter(struct string *glb, unsigned int include) { struct filter *f; make_ref(f); f->glob = glb; f->include = include; return f; }
StipplePenTexture(m2::PointU const & size, ref_ptr<HWTextureAllocator> allocator) : m_index(size) { TBase::DynamicTextureParams params{size, TextureFormat::Alpha, TextureFilter::Nearest, false /* m_usePixelBuffer */}; TBase::Init(allocator, make_ref(&m_index), params); }
void c_foreach(int flags, int idx1, int idx2) { IF_DEBUG(stack_in_use_as_temporary++); if (flags & FOREACH_MAPPING) { CHECK_TYPES(sp, T_MAPPING, 2, F_FOREACH); push_refed_array(mapping_indices(sp->u.map)); STACK_INC; sp->type = T_NUMBER; sp->u.lvalue = (sp-1)->u.arr->item; sp->subtype = (sp-1)->u.arr->size; STACK_INC; sp->type = T_LVALUE; if (flags & FOREACH_LEFT_GLOBAL) { sp->u.lvalue = ¤t_object->variables[idx1 + variable_index_offset]; } else { sp->u.lvalue = fp + idx1; } } else if (sp->type == T_STRING) { STACK_INC; sp->type = T_NUMBER; sp->u.lvalue_byte = (unsigned char *)((sp-1)->u.string); sp->subtype = SVALUE_STRLEN(sp - 1); } else { CHECK_TYPES(sp, T_ARRAY, 2, F_FOREACH); STACK_INC; sp->type = T_NUMBER; sp->u.lvalue = (sp-1)->u.arr->item; sp->subtype = (sp-1)->u.arr->size; } if (flags & FOREACH_RIGHT_GLOBAL) { STACK_INC; sp->type = T_LVALUE; sp->u.lvalue = ¤t_object->variables[idx2 + variable_index_offset]; } else if (flags & FOREACH_REF) { ref_t *ref = make_ref(); svalue_t *loc = fp + idx2; /* foreach guarantees our target remains valid */ ref->lvalue = 0; ref->sv.type = T_NUMBER; STACK_INC; sp->type = T_REF; sp->u.ref = ref; DEBUG_CHECK(loc->type != T_NUMBER && loc->type != T_REF, "Somehow a reference in foreach acquired a value before coming into scope"); loc->type = T_REF; loc->u.ref = ref; ref->ref++; } else { STACK_INC; sp->type = T_LVALUE; sp->u.lvalue = fp + idx2; } }
/// enumerate over all top-level windows. // @param callback a function to receive each window object // @function enum_windows def enum_windows(Value callback) { Ref ref; sL = L; ref = make_ref(L,callback); EnumWindows(&enum_callback,ref); release_ref(L,ref); return 0; }
/// enumerate all child windows. // @param a callback which to receive each window object // @function enum_children def enum_children(Value callback) { Ref ref; sL = L; ref = make_ref(L,callback); EnumChildWindows(this->hwnd,&enum_callback,ref); release_ref(L,ref); return 0; }
static struct lens *make_lens(enum lens_tag tag, struct info *info) { struct lens *lens; make_ref(lens); lens->tag = tag; lens->info = info; return lens; }
void TextShape::DrawSubStringOutlined(StraightTextLayout const & layout, dp::FontDecl const & font, glm::vec2 const & baseOffset, ref_ptr<dp::Batcher> batcher, ref_ptr<dp::TextureManager> textures, bool isPrimary, bool isOptional) const { gpu::TTextOutlinedStaticVertexBuffer staticBuffer; gpu::TTextDynamicVertexBuffer dynamicBuffer; dp::TextureManager::ColorRegion color, outline; textures->GetColorRegion(font.m_color, color); textures->GetColorRegion(font.m_outlineColor, outline); layout.Cache(glsl::vec4(glsl::ToVec2(m_basePoint), m_params.m_depth, -m_params.m_posZ), baseOffset, color, outline, staticBuffer, dynamicBuffer); dp::GLState state(gpu::TEXT_OUTLINED_PROGRAM, dp::GLState::OverlayLayer); state.SetProgram3dIndex(gpu::TEXT_OUTLINED_BILLBOARD_PROGRAM); ASSERT(color.GetTexture() == outline.GetTexture(), ()); state.SetColorTexture(color.GetTexture()); state.SetMaskTexture(layout.GetMaskTexture()); gpu::TTextDynamicVertexBuffer initialDynBuffer(dynamicBuffer.size()); m2::PointU const & pixelSize = layout.GetPixelSize(); drape_ptr<dp::OverlayHandle> handle = make_unique_dp<StraightTextHandle>(m_params.m_featureID, layout.GetText(), m_params.m_anchor, glsl::ToVec2(m_basePoint), glsl::vec2(pixelSize.x, pixelSize.y), baseOffset, GetOverlayPriority(), textures, isOptional, m_affectedByZoomPriority, move(dynamicBuffer), true); handle->SetPivotZ(m_params.m_posZ); handle->SetOverlayRank(m_hasPOI ? (isPrimary ? dp::OverlayRank1 : dp::OverlayRank2) : dp::OverlayRank0); handle->SetExtendingSize(m_params.m_extendingSize); dp::AttributeProvider provider(2, staticBuffer.size()); provider.InitStream(0, gpu::TextOutlinedStaticVertex::GetBindingInfo(), make_ref(staticBuffer.data())); provider.InitStream(1, gpu::TextDynamicVertex::GetBindingInfo(), make_ref(initialDynBuffer.data())); batcher->InsertListOfStrip(state, make_ref(&provider), move(handle), 4); }
void CircleShape::Draw(ref_ptr<dp::Batcher> batcher, ref_ptr<dp::TextureManager> textures) const { int const TriangleCount = 20; double const etalonSector = (2.0 * math::pi) / static_cast<double>(TriangleCount); dp::TextureManager::ColorRegion region; textures->GetColorRegion(m_params.m_color, region); glsl::vec2 colorPoint(glsl::ToVec2(region.GetTexRect().Center())); buffer_vector<gpu::SolidTexturingVertex, 22> vertexes; vertexes.push_back(gpu::SolidTexturingVertex { glsl::vec4(glsl::ToVec2(m_pt), m_params.m_depth, 0.0f), glsl::vec2(0.0f, 0.0f), colorPoint }); m2::PointD startNormal(0.0f, m_params.m_radius); for (size_t i = 0; i < TriangleCount + 1; ++i) { m2::PointD rotatedNormal = m2::Rotate(startNormal, (i) * etalonSector); vertexes.push_back(gpu::SolidTexturingVertex { glsl::vec4(glsl::ToVec2(m_pt), m_params.m_depth, 0.0f), glsl::ToVec2(rotatedNormal), colorPoint }); } dp::GLState state(gpu::TEXTURING_PROGRAM, dp::GLState::OverlayLayer); state.SetColorTexture(region.GetTexture()); double handleSize = 2 * m_params.m_radius; drape_ptr<dp::OverlayHandle> overlay = make_unique_dp<dp::SquareHandle>(m_params.m_id, dp::Center, m_pt, m2::PointD(handleSize, handleSize), GetOverlayPriority(), ""); dp::AttributeProvider provider(1, TriangleCount + 2); provider.InitStream(0, gpu::SolidTexturingVertex::GetBindingInfo(), make_ref(vertexes.data())); batcher->InsertTriangleFan(state, make_ref(&provider), move(overlay)); }
ref_ptr<DataBuffer> VertexArrayBuffer::GetOrCreateBuffer(BindingInfo const & bindingInfo, bool isDynamic) { TBuffersMap * buffers = nullptr; if (isDynamic) buffers = &m_dynamicBuffers; else buffers = &m_staticBuffers; TBuffersMap::iterator it = buffers->find(bindingInfo); if (it == buffers->end()) { drape_ptr<DataBuffer> dataBuffer = make_unique_dp<DataBuffer>(bindingInfo.GetElementSize(), m_dataBufferSize); ref_ptr<DataBuffer> result = make_ref(dataBuffer); (*buffers).insert(make_pair(bindingInfo, move(dataBuffer))); return result; } return make_ref(it->second); }
void MyPosition::CacheAccuracySector(ref_ptr<dp::TextureManager> mng) { int const TriangleCount = 40; int const VertexCount = 3 * TriangleCount; float const etalonSector = math::twicePi / static_cast<double>(TriangleCount); dp::TextureManager::ColorRegion color; mng->GetColorRegion(df::GetColorConstant(GetStyleReader().GetCurrentStyle(), df::MyPositionAccuracy), color); glsl::vec2 colorCoord = glsl::ToVec2(color.GetTexRect().Center()); buffer_vector<Vertex, TriangleCount> buffer; glsl::vec2 startNormal(0.0f, 1.0f); for (size_t i = 0; i < TriangleCount + 1; ++i) { glsl::vec2 normal = glsl::rotate(startNormal, i * etalonSector); glsl::vec2 nextNormal = glsl::rotate(startNormal, (i + 1) * etalonSector); buffer.emplace_back(startNormal, colorCoord); buffer.emplace_back(normal, colorCoord); buffer.emplace_back(nextNormal, colorCoord); } dp::GLState state(gpu::ACCURACY_PROGRAM, dp::GLState::OverlayLayer); state.SetColorTexture(color.GetTexture()); { dp::Batcher batcher(TriangleCount * dp::Batcher::IndexPerTriangle, VertexCount); dp::SessionGuard guard(batcher, [this](dp::GLState const & state, drape_ptr<dp::RenderBucket> && b) { drape_ptr<dp::RenderBucket> bucket = move(b); ASSERT(bucket->GetOverlayHandlesCount() == 0, ()); m_nodes.emplace_back(state, bucket->MoveBuffer()); m_parts[MY_POSITION_ACCURACY].second = m_nodes.size() - 1; }); dp::AttributeProvider provider(1 /*stream count*/, VertexCount); provider.InitStream(0 /*stream index*/, GetBindingInfo(), make_ref(buffer.data())); m_parts[MY_POSITION_ACCURACY].first = batcher.InsertTriangleList(state, make_ref(&provider), nullptr); ASSERT(m_parts[MY_POSITION_ACCURACY].first.IsValid(), ()); }
static struct regexp *make_regexp_from_string(struct info *info, struct string *string) { struct regexp *r; make_ref(r); if (r != NULL) { r->info = ref(info); r->pattern = ref(string); } return r; }
ref_t make_string(char *s, size_t size) { if (s != NULL) size = strlen(s); struct string *obj = gc_alloc(sizeof(struct string) + size); obj->tag = OBJ_STRING; if (s != NULL) strcpy(obj->bytes, s); else memset(obj->bytes, 0, size); return make_ref(obj, LOWTAG_STRING); }
struct string *dup_string(const char *str) { struct string *string; make_ref(string); if (str == NULL) string->str = strdup(""); else string->str = strdup(str); if (string->str == NULL) unref(string, string); return string; }
struct regexp *regexp_make_empty(struct info *info) { struct regexp *regexp; make_ref(regexp); if (regexp != NULL) { regexp->info = ref(info); /* Casting away the CONST for EMPTY_PATTERN is ok since it is protected against changes because REF == REF_MAX */ regexp->pattern = (struct string *) empty_pattern; } return regexp; }
void FrontendRenderer::AddToRenderGroup(vector<drape_ptr<RenderGroup>> & groups, dp::GLState const & state, drape_ptr<dp::RenderBucket> && renderBucket, TileKey const & newTile) { drape_ptr<RenderGroup> group = make_unique_dp<RenderGroup>(state, newTile); ref_ptr<dp::GpuProgram> program = m_gpuProgramManager->GetProgram(state.GetProgramIndex()); ref_ptr<dp::GpuProgram> program3d = m_gpuProgramManager->GetProgram(state.GetProgram3dIndex()); group->SetRenderParams(program, program3d, make_ref(&m_generalUniforms)); group->AddBucket(move(renderBucket)); groups.push_back(move(group)); }
ref_ptr<MarksIDGroups> UserMarkGenerator::GetUserLinesGroups(TileKey const & tileKey) { auto itTile = m_index.end(); int const lineZoom = GetNearestLineIndexZoom(tileKey.m_zoomLevel); CalcTilesCoverage(tileKey.GetGlobalRect(), lineZoom, [this, &itTile, lineZoom](int tileX, int tileY) { itTile = m_index.find(TileKey(tileX, tileY, lineZoom)); }); if (itTile != m_index.end()) return make_ref(itTile->second); return nullptr; }
ref_ptr<DataBuffer> VertexArrayBuffer::GetBuffer(BindingInfo const & bindingInfo, bool isDynamic) const { TBuffersMap const * buffers = nullptr; if (isDynamic) buffers = &m_dynamicBuffers; else buffers = &m_staticBuffers; TBuffersMap::const_iterator it = buffers->find(bindingInfo); if (it == buffers->end()) return nullptr; return make_ref(it->second); }
void DrawWidget::CreateEngine() { Framework::DrapeCreationParams p; p.m_surfaceWidth = m_ratio * width(); p.m_surfaceHeight = m_ratio * height(); p.m_visualScale = m_ratio; m_skin.reset(new gui::Skin(gui::ResolveGuiSkinFile("default"), m_ratio)); m_skin->Resize(p.m_surfaceWidth, p.m_surfaceHeight); m_skin->ForEach([&p](gui::EWidget widget, gui::Position const & pos) { p.m_widgetsInitInfo[widget] = pos; }); p.m_widgetsInitInfo[gui::WIDGET_SCALE_LABEL] = gui::Position(dp::LeftBottom); m_framework->CreateDrapeEngine(make_ref(m_contextFactory), std::move(p)); m_framework->AddViewportListener(bind(&DrawWidget::OnViewportChanged, this, _1)); }
void MapWidget::CreateEngine() { Framework::DrapeCreationParams p; p.m_apiVersion = m_apiOpenGLES3 ? dp::ApiVersion::OpenGLES3 : dp::ApiVersion::OpenGLES2; p.m_surfaceWidth = m_screenshotMode ? width() : static_cast<int>(m_ratio * width()); p.m_surfaceHeight = m_screenshotMode ? height() : static_cast<int>(m_ratio * height()); p.m_visualScale = static_cast<float>(m_ratio); p.m_hints.m_screenshotMode = m_screenshotMode; m_skin.reset(new gui::Skin(gui::ResolveGuiSkinFile("default"), m_ratio)); m_skin->Resize(p.m_surfaceWidth, p.m_surfaceHeight); m_skin->ForEach( [&p](gui::EWidget widget, gui::Position const & pos) { p.m_widgetsInitInfo[widget] = pos; }); p.m_widgetsInitInfo[gui::WIDGET_SCALE_FPS_LABEL] = gui::Position(dp::LeftBottom); m_framework.CreateDrapeEngine(make_ref(m_contextFactory), std::move(p)); m_framework.SetViewportListener(std::bind(&MapWidget::OnViewportChanged, this, std::placeholders::_1)); }
drape_ptr<LayerRenderer> LayerCacher::RecacheWidgets(TWidgetsInitInfo const & initInfo, ref_ptr<dp::TextureManager> textures) { using TCacheShape = function<m2::PointF (Position anchor, ref_ptr<LayerRenderer> renderer, ref_ptr<dp::TextureManager> textures)>; static map<EWidget, TCacheShape> cacheFunctions { make_pair(WIDGET_COMPASS, bind(&LayerCacher::CacheCompass, this, _1, _2, _3)), make_pair(WIDGET_RULER, bind(&LayerCacher::CacheRuler, this, _1, _2, _3)), make_pair(WIDGET_COPYRIGHT, bind(&LayerCacher::CacheCopyright, this, _1, _2, _3)), make_pair(WIDGET_SCALE_LABEL, bind(&LayerCacher::CacheScaleLabel, this, _1, _2, _3)) }; drape_ptr<LayerRenderer> renderer = make_unique_dp<LayerRenderer>(); for (auto node : initInfo) { auto cacheFunction = cacheFunctions.find(node.first); if (cacheFunction != cacheFunctions.end()) cacheFunction->second(node.second, make_ref(renderer), textures); } // Flush gui geometry. GLFunctions::glFlush(); return renderer; }