void GPUTileStorage::generateMipMap() { if (changes) { int level = 1; int width = tileSize / 2; while (width >= 1) { fbo->setViewport(vec4i(0, 0, width, width)); for (unsigned int n = 0; n < textures.size(); ++n) { fbo->setTextureBuffer(BufferId(1 << n), textures[n], level, -1); } for (unsigned int n = 0; n < textures.size(); ++n) { fbo->setDrawBuffer(BufferId(1 << n)); set<GPUSlot*>::iterator i = dirtySlots[n].begin(); while (i != dirtySlots[n].end()) { GPUSlot *s = *i; mipmapParams->set(vec4i(s->index, s->l, level - 1, width)); fbo->drawQuad(mipmapProg); ++i; } } width /= 2; level += 1; } for (unsigned int n = 0; n < textures.size(); ++n) { dirtySlots[n].clear(); } changes = false; } }
BufferId NetworkModelController::findQueryBuffer(const QModelIndex &index, const QString &predefinedNick) const { NetworkId networkId = index.data(NetworkModel::NetworkIdRole).value<NetworkId>(); if (!networkId.isValid()) return BufferId(); QString nick = predefinedNick.isEmpty() ? nickName(index) : predefinedNick; if (nick.isEmpty()) return BufferId(); return findQueryBuffer(networkId, nick); }
void GPUTileStorage::init(int tileSize, int nTiles, TextureInternalFormat internalf, TextureFormat f, PixelType t, const Texture::Parameters ¶ms, bool useTileMap) { TileStorage::init(tileSize, nTiles); int maxLayers = Texture2DArray::getMaxLayers(); int nTextures = nTiles / maxLayers + (nTiles % maxLayers == 0 ? 0 : 1); needMipmaps = false; for (int i = 0; i < nTextures; ++i) { int nLayers = i == nTextures - 1 && nTiles % maxLayers != 0 ? nTiles % maxLayers : maxLayers; ptr<Texture2DArray> tex = new Texture2DArray(tileSize, tileSize, nLayers, internalf, f, t, params, Buffer::Parameters(), CPUBuffer()); needMipmaps = needMipmaps || (tex->hasMipmaps()); textures.push_back(tex); tex->generateMipMap(); for (int j = 0; j < nLayers; ++j) { freeSlots.push_back(new GPUSlot(this, i, textures[i], j)); } } if (needMipmaps) { assert(nTextures <= 8); dirtySlots = new set<GPUSlot*>[nTextures]; fbo = new FrameBuffer(); fbo->setReadBuffer(BufferId(0)); fbo->setDrawBuffers(BufferId(COLOR0 | COLOR1)); mipmapProg = new Program(new Module(330, mipmapShader)); ptr<Sampler> s = new Sampler(Sampler::Parameters().min(NEAREST).mag(NEAREST).wrapS(CLAMP_TO_EDGE).wrapT(CLAMP_TO_EDGE)); for (int i = 0; i < nTextures; ++i) { char buf[256]; sprintf(buf, "input_[%d]", i); mipmapProg->getUniformSampler(string(buf))->set(textures[i]); mipmapProg->getUniformSampler(string(buf))->setSampler(s); } mipmapParams = mipmapProg->getUniform4i("bufferLayerLevelWidth"); } else { dirtySlots = NULL; } changes = false; if (useTileMap) { assert(nTextures == 1); tileMap = new Texture2D(4096, 8, RG8, RG, UNSIGNED_BYTE, Texture::Parameters().wrapS(CLAMP_TO_EDGE).wrapT(CLAMP_TO_EDGE).min(NEAREST).mag(NEAREST), Buffer::Parameters(), CPUBuffer()); } }
Block * BufferMgr::getBlock(const char* file, uint BlockNum) { BufferId id = BufferId(file, BlockNum); if (numMap.find(id) == numMap.end()) return nullptr; int retBlock = numMap[id]; // 更新LRU表 auto p = leastAddr[retBlock]; leastList.push_front(*p); leastAddr[*p] = leastList.begin(); leastList.erase(p); if (logRecord) printf("[Buffer Mgr]Block #%d in %s is found in Buffer\n", blockInfo[retBlock]->blockNum, blockInfo[retBlock]->fileName); return block[retBlock]; }
void BufferMgr::addBlock(const char *file, Block *b) { if (numMap.find(BufferId(file, b->getBlockNum())) != numMap.end()) return; int nextBlock; if (curSize < MAX_BLOCK_SIZE) { nextBlock = curSize++; } else { // LRU替换策略 nextBlock = getAndReleaseLruBlock(); removeBlock(nextBlock); } BufferId *bid = new BufferId(file, b->getBlockNum()); block[nextBlock] = b; blockInfo[nextBlock] = bid; numMap[*bid] = nextBlock; leastList.push_front(nextBlock); leastAddr[nextBlock] = leastList.begin(); if (logRecord) printf("[Buffer Mgr]Block #%d in %s is added to Buffer\n", b->getBlockNum(), file); }
void ChatScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { QPointF pos = event->scenePos(); QMenu menu; // zoom actions and similar chatView()->addActionsToMenu(&menu, pos); menu.addSeparator(); if(isPosOverSelection(pos)) menu.addAction(SmallIcon("edit-copy"), tr("Copy Selection"), this, SLOT(selectionToClipboard()), QKeySequence::Copy); // item-specific options (select link etc) ChatItem *item = chatItemAt(pos); if(item) item->addActionsToMenu(&menu, item->mapFromScene(pos)); else // no item -> default scene actions GraphicalUi::contextMenuActionProvider()->addActions(&menu, filter(), BufferId()); menu.exec(event->screenPos()); }
ChatScene::ChatScene(QAbstractItemModel *model, const QString &idString, qreal width, ChatView *parent) : QGraphicsScene(0, 0, width, 0, (QObject *)parent), _chatView(parent), _idString(idString), _model(model), _singleBufferId(BufferId()), _sceneRect(0, 0, width, 0), _firstLineRow(-1), _viewportHeight(0), _markerLine(new MarkerLineItem(width)), _markerLineVisible(false), _markerLineValid(false), _markerLineJumpPending(false), _cutoffMode(CutoffRight), _selectingItem(0), _selectionStart(-1), _isSelecting(false), _clickMode(NoClick), _clickHandled(true), _leftButtonPressed(false) { MessageFilter *filter = qobject_cast<MessageFilter*>(model); if(filter && filter->isSingleBufferFilter()) { _singleBufferId = filter->singleBufferId(); } addItem(_markerLine); connect(this, SIGNAL(sceneRectChanged(const QRectF &)), _markerLine, SLOT(sceneRectChanged(const QRectF &))); ChatViewSettings defaultSettings; int defaultFirstColHandlePos = defaultSettings.value("FirstColumnHandlePos", 80).toInt(); int defaultSecondColHandlePos = defaultSettings.value("SecondColumnHandlePos", 200).toInt(); ChatViewSettings viewSettings(this); _firstColHandlePos = viewSettings.value("FirstColumnHandlePos", defaultFirstColHandlePos).toInt(); _secondColHandlePos = viewSettings.value("SecondColumnHandlePos", defaultSecondColHandlePos).toInt(); _firstColHandle = new ColumnHandleItem(QtUi::style()->firstColumnSeparator()); addItem(_firstColHandle); _firstColHandle->setXPos(_firstColHandlePos); connect(_firstColHandle, SIGNAL(positionChanged(qreal)), this, SLOT(firstHandlePositionChanged(qreal))); connect(this, SIGNAL(sceneRectChanged(const QRectF &)), _firstColHandle, SLOT(sceneRectChanged(const QRectF &))); _secondColHandle = new ColumnHandleItem(QtUi::style()->secondColumnSeparator()); addItem(_secondColHandle); _secondColHandle->setXPos(_secondColHandlePos); connect(_secondColHandle, SIGNAL(positionChanged(qreal)), this, SLOT(secondHandlePositionChanged(qreal))); connect(this, SIGNAL(sceneRectChanged(const QRectF &)), _secondColHandle, SLOT(sceneRectChanged(const QRectF &))); setHandleXLimits(); if(model->rowCount() > 0) rowsInserted(QModelIndex(), 0, model->rowCount() - 1); connect(model, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(rowsInserted(const QModelIndex &, int, int))); connect(model, SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)), this, SLOT(rowsAboutToBeRemoved(const QModelIndex &, int, int))); connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(rowsRemoved())); connect(model, SIGNAL(dataChanged(QModelIndex, QModelIndex)), SLOT(dataChanged(QModelIndex, QModelIndex))); #ifdef HAVE_WEBKIT webPreview.timer.setSingleShot(true); connect(&webPreview.timer, SIGNAL(timeout()), this, SLOT(webPreviewNextStep())); #endif _showWebPreview = defaultSettings.showWebPreview(); defaultSettings.notify("ShowWebPreview", this, SLOT(showWebPreviewChanged())); _clickTimer.setInterval(QApplication::doubleClickInterval()); _clickTimer.setSingleShot(true); connect(&_clickTimer, SIGNAL(timeout()), SLOT(clickTimeout())); setItemIndexMethod(QGraphicsScene::NoIndex); }