[4] | 1 | /****************************************************************************** |
---|
| 2 | * SAGE - Scalable Adaptive Graphics Environment |
---|
| 3 | * |
---|
| 4 | * Module: pixelDownloader.h |
---|
| 5 | * Author : Byungil Jeong |
---|
| 6 | * |
---|
| 7 | * Copyright (C) 2004 Electronic Visualization Laboratory, |
---|
| 8 | * University of Illinois at Chicago |
---|
| 9 | * |
---|
| 10 | * All rights reserved. |
---|
| 11 | * |
---|
| 12 | * Redistribution and use in source and binary forms, with or without |
---|
| 13 | * modification, are permitted provided that the following conditions are met: |
---|
| 14 | * |
---|
| 15 | * * Redistributions of source code must retain the above copyright |
---|
| 16 | * notice, this list of conditions and the following disclaimer. |
---|
| 17 | * * Redistributions in binary form must reproduce the above |
---|
| 18 | * copyright notice, this list of conditions and the following disclaimer |
---|
| 19 | * in the documentation and/or other materials provided with the distribution. |
---|
| 20 | * * Neither the name of the University of Illinois at Chicago nor |
---|
| 21 | * the names of its contributors may be used to endorse or promote |
---|
| 22 | * products derived from this software without specific prior written permission. |
---|
| 23 | * |
---|
| 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
| 25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
| 26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
| 27 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
---|
| 28 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
---|
| 29 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
---|
| 30 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
---|
| 31 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
---|
| 32 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
---|
| 33 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
| 34 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 35 | * |
---|
| 36 | * Direct questions, comments etc about SAGE to sage_users@listserv.uic.edu or |
---|
| 37 | * http://www.evl.uic.edu/cavern/forum/ |
---|
| 38 | * |
---|
| 39 | *****************************************************************************/ |
---|
| 40 | |
---|
| 41 | #ifndef PIXEL_DOWNLOADER_H_ |
---|
| 42 | #define PIXEL_DOWNLOADER_H_ |
---|
| 43 | |
---|
| 44 | #include "sage.h" |
---|
| 45 | #include "sageSync.h" |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | #include "sageEvent.h" |
---|
| 49 | |
---|
| 50 | class pixelDownloader; |
---|
| 51 | class dispSharedData; |
---|
| 52 | class sageMontage; |
---|
| 53 | class sageBlockBuf; |
---|
| 54 | class sagePixelBlock; |
---|
| 55 | class displayContext; |
---|
| 56 | class sageBlockPartition; |
---|
| 57 | class sagePixelReceiver; |
---|
| 58 | class streamProtocol; |
---|
| 59 | |
---|
| 60 | /** |
---|
| 61 | * class montagePair |
---|
| 62 | */ |
---|
| 63 | class montagePair { |
---|
| 64 | private: |
---|
| 65 | //int tileID; |
---|
| 66 | sageMontage *montage[2]; |
---|
| 67 | int frontMon; |
---|
| 68 | bool renewMontage; |
---|
| 69 | bool active; |
---|
| 70 | //bool updated; |
---|
| 71 | bool clearFlag; |
---|
| 72 | |
---|
| 73 | public: |
---|
| 74 | montagePair() : renewMontage(false), frontMon(0), active(false), |
---|
| 75 | clearFlag(false) {} |
---|
| 76 | int init(displayContext *context, sagePixFmt pfmt, int index, float depth); |
---|
| 77 | inline sageMontage* getFrontMon() { return montage[frontMon]; } |
---|
| 78 | inline sageMontage* getBackMon() { return montage[1-frontMon]; } |
---|
| 79 | int setDepth(float depth); |
---|
| 80 | int setLocalTileIdx(int idx); |
---|
| 81 | |
---|
| 82 | /** |
---|
| 83 | * when a window is moved or resized, the config of back montage is updated immediately,<BR> |
---|
| 84 | * the front montage is updated when it is swapped |
---|
| 85 | */ |
---|
| 86 | void swapMontage(); |
---|
| 87 | |
---|
| 88 | int deleteMontage(); |
---|
| 89 | //int getLocalTileIdx() { return montage[0]->tileIdx; } |
---|
| 90 | inline bool isActive() { return active; } |
---|
| 91 | inline void activate() { active = true, clearFlag = false; } |
---|
| 92 | inline void deactivate(){ active = false, clearFlag = false; } |
---|
| 93 | inline void clear() { clearFlag = true; } |
---|
| 94 | inline bool getClearFlag() { return clearFlag; } |
---|
| 95 | |
---|
| 96 | //void update() { updated = true; } |
---|
| 97 | inline void renew() { renewMontage = true; } |
---|
| 98 | inline bool isRenewed() { return renewMontage; } |
---|
| 99 | |
---|
| 100 | //bool isUpdated() { return updated; } |
---|
| 101 | //void resetUpdateFlag() { updated = false; } |
---|
| 102 | ~montagePair(); |
---|
| 103 | }; |
---|
| 104 | |
---|
| 105 | #define PDL_WAIT_CONFIG 1 |
---|
| 106 | #define PDL_WAIT_DATA 2 |
---|
| 107 | #define PDL_WAIT_SYNC 3 |
---|
| 108 | |
---|
| 109 | /** |
---|
| 110 | * \brief class pixelDownloader (per application). It reads pixel data from buffer and downloads into texture memory. |
---|
| 111 | */ |
---|
| 112 | class pixelDownloader { |
---|
| 113 | public: |
---|
| 114 | int instID; /**< application ID */ |
---|
| 115 | protected: |
---|
| 116 | int streamNum; |
---|
| 117 | int tileNum; /**< how many tiles a single node has ? */ |
---|
| 118 | int updatedFrame, curFrame, syncFrame; |
---|
| 119 | int configID, dispConfigID; |
---|
| 120 | int groupSize, blockSize; |
---|
| 121 | dispSharedData *shared; /**< dispSharedData *. This is assigned at the sageDisplayManager */ |
---|
| 122 | bool frameCheck; |
---|
| 123 | bool syncOn; /**< whether we ensure sync b/w tiles or not */ |
---|
| 124 | int syncLevel; |
---|
| 125 | bool displayActive; |
---|
| 126 | int status; /**< PDL_WAIT_CONFIG 1, PDL_WAIT_DATA 2, and PDL_WAIT_SYNC 3*/ |
---|
| 127 | bool m_initialized; |
---|
| 128 | |
---|
| 129 | sagePixelReceiver *recv; /**< sagePixelReceiver */ |
---|
| 130 | sageBlockBuf *blockBuf; /**< sageBlockBuf */ |
---|
| 131 | montagePair *montageList; |
---|
| 132 | |
---|
| 133 | sageCounter frameCounter; |
---|
| 134 | int reportRate; |
---|
| 135 | sageTimer perfTimer; |
---|
| 136 | unsigned long bandWidth; |
---|
| 137 | unsigned long packetLoss; |
---|
| 138 | unsigned frameBlockNum; /**< PDL is supposed to received this many blocks for given group */ |
---|
| 139 | int actualFrameBlockNum; |
---|
| 140 | unsigned long frameSize; |
---|
| 141 | |
---|
| 142 | sageBlockPartition *partition; |
---|
| 143 | sageRect windowLayout; |
---|
| 144 | |
---|
| 145 | /** |
---|
| 146 | * how many sageReceiver involves ? |
---|
| 147 | */ |
---|
| 148 | int activeRcvs; |
---|
| 149 | int updateType; |
---|
| 150 | bool passiveUpdate; |
---|
| 151 | |
---|
| 152 | /** |
---|
| 153 | * stream coming from bridge and it's actually parallel app |
---|
| 154 | */ |
---|
| 155 | bool fromBridgeParallel; |
---|
| 156 | |
---|
| 157 | std::deque<char *> configQueue; |
---|
| 158 | |
---|
| 159 | //int sendPerformanceInfo(); |
---|
| 160 | int downloadPixelBlock(sagePixelBlock *block, montagePair &monPair); |
---|
| 161 | int clearTile(int tileIdx); |
---|
| 162 | |
---|
| 163 | /** |
---|
| 164 | * for each tileNum, clearTile() is called |
---|
| 165 | */ |
---|
| 166 | int clearScreen(); |
---|
| 167 | int setupSyncInfo(sagePixelBlock *block); |
---|
| 168 | |
---|
| 169 | public: |
---|
| 170 | /** |
---|
| 171 | * starts with updateType = SAGE_UPDATE_FOLLOW, status = PDL_WAIT_DATA |
---|
| 172 | */ |
---|
| 173 | pixelDownloader(); |
---|
| 174 | |
---|
| 175 | /** |
---|
| 176 | * creates montagePair, sageBlockPartition, sageBlockBuf, sagePixelReceiver objects<BR> |
---|
| 177 | * this is invoked by initStreams in the sageDisplayManager (when EVENT_NEW_CONNECTION) |
---|
| 178 | * |
---|
| 179 | * msg contains groupSize and blockSize. These are passed to sageBlockBuf constructor. |
---|
| 180 | */ |
---|
| 181 | int init(char *msg, dispSharedData *sh, streamProtocol *nwObj, bool sync, int syncLevel); |
---|
| 182 | |
---|
| 183 | /** |
---|
| 184 | * Called when EVENT_READ_BLOCK, EVENT_SYNC_MESSAGE, and RCV_UPDATE_DISPLAY<BR> |
---|
| 185 | * This function is the one which calls sageSyncClient::sendSlaveUpdate()<BR> |
---|
| 186 | * When syncOn is true and updateFrame > curFrame<BR> |
---|
| 187 | * <BR> |
---|
| 188 | * It first fetches block data from the block buffer by calling sageBlockBuf.front()<BR> |
---|
| 189 | * then calculates packet loss.. then.. |
---|
| 190 | * .. |
---|
| 191 | * .. |
---|
| 192 | * |
---|
| 193 | */ |
---|
| 194 | int fetchSageBlocks(); |
---|
| 195 | |
---|
| 196 | /** |
---|
| 197 | * It looks like this function is responsible for syncing b/w tiles<BR> |
---|
| 198 | * The first argument frame is the frame that we want to sync to<BR> |
---|
| 199 | * <BR> |
---|
| 200 | * if this syncSlave's updated frame is equal to the sync frame(argument), |
---|
| 201 | * then it swaps texture (swapMontage()) => HARD_SYNC |
---|
| 202 | */ |
---|
| 203 | void processSync(int frame, int cmd = 0); |
---|
| 204 | |
---|
| 205 | int enqueConfig(char *data); |
---|
| 206 | int setDepth(float depth); |
---|
| 207 | |
---|
| 208 | /** |
---|
| 209 | * just calls sagePixelReceiver::addStream()<BR> |
---|
| 210 | * called by sageDisplayManager::initStream() |
---|
| 211 | */ |
---|
| 212 | int addStream(int senderID); |
---|
| 213 | |
---|
| 214 | /** |
---|
| 215 | * When a window is moved or resized, the config of back montage is |
---|
| 216 | * updated immediately, the front montage is updated when it is swapped. |
---|
| 217 | */ |
---|
| 218 | int swapMontages(); |
---|
| 219 | bool reconfigDisplay(int id); |
---|
| 220 | int evalPerformance(char **frameStr, char **bandStr); /**< evaluate performance */ |
---|
| 221 | inline void setReportRate(int rate) { reportRate = rate; } |
---|
| 222 | inline void resetTimer() { perfTimer.reset(); } |
---|
| 223 | inline void resetBandWidth() { bandWidth = 0; } |
---|
| 224 | inline void resetFrame() { frameCounter.reset(); } |
---|
| 225 | inline int getInstID() { return instID; } |
---|
| 226 | inline int getStatus() { return status; } |
---|
| 227 | bool isInitialized(void) { return m_initialized; } |
---|
| 228 | |
---|
| 229 | ~pixelDownloader(); |
---|
| 230 | }; |
---|
| 231 | |
---|
| 232 | #endif |
---|