NS_INTERFACE_MAP_END NS_IMETHODIMP ImageLoader::Notify(imgIRequest* aRequest, int32_t aType, const nsIntRect* aData) { if (aType == imgINotificationObserver::SIZE_AVAILABLE) { nsCOMPtr<imgIContainer> image; aRequest->GetImage(getter_AddRefs(image)); return OnSizeAvailable(aRequest, image); } if (aType == imgINotificationObserver::IS_ANIMATED) { return OnImageIsAnimated(aRequest); } if (aType == imgINotificationObserver::FRAME_COMPLETE) { return OnFrameComplete(aRequest); } if (aType == imgINotificationObserver::FRAME_UPDATE) { return OnFrameUpdate(aRequest); } return NS_OK; }
/* static */ void ProgressTracker::SyncNotifyInternal(ProxyArray& aProxies, bool aHasImage, Progress aProgress, const nsIntRect& aDirtyRect) { MOZ_ASSERT(NS_IsMainThread()); if (aProgress & FLAG_SIZE_AVAILABLE) NOTIFY_IMAGE_OBSERVERS(aProxies, OnSizeAvailable()); if (aProgress & FLAG_DECODE_STARTED) NOTIFY_IMAGE_OBSERVERS(aProxies, OnStartDecode()); if (aProgress & FLAG_ONLOAD_BLOCKED) NOTIFY_IMAGE_OBSERVERS(aProxies, BlockOnload()); if (aHasImage) { // OnFrameUpdate // If there's any content in this frame at all (always true for // vector images, true for raster images that have decoded at // least one frame) then send OnFrameUpdate. if (!aDirtyRect.IsEmpty()) NOTIFY_IMAGE_OBSERVERS(aProxies, OnFrameUpdate(&aDirtyRect)); if (aProgress & FLAG_FRAME_COMPLETE) NOTIFY_IMAGE_OBSERVERS(aProxies, OnFrameComplete()); if (aProgress & FLAG_HAS_TRANSPARENCY) NOTIFY_IMAGE_OBSERVERS(aProxies, OnImageHasTransparency()); if (aProgress & FLAG_IS_ANIMATED) NOTIFY_IMAGE_OBSERVERS(aProxies, OnImageIsAnimated()); } // Send UnblockOnload before OnStopDecode and OnStopRequest. This allows // observers that can fire events when they receive those notifications to do // so then, instead of being forced to wait for UnblockOnload. if (aProgress & FLAG_ONLOAD_UNBLOCKED) { NOTIFY_IMAGE_OBSERVERS(aProxies, UnblockOnload()); } if (aProgress & FLAG_DECODE_COMPLETE) { MOZ_ASSERT(aHasImage, "Stopped decoding without ever having an image?"); NOTIFY_IMAGE_OBSERVERS(aProxies, OnDecodeComplete()); } if (aProgress & FLAG_LOAD_COMPLETE) { NOTIFY_IMAGE_OBSERVERS(aProxies, OnLoadComplete(aProgress & FLAG_LAST_PART_COMPLETE)); } }
NS_IMETHODIMP nsAlertsIconListener::Notify(imgIRequest *aRequest, int32_t aType, const nsIntRect* aData) { if (aType == imgINotificationObserver::LOAD_COMPLETE) { return OnLoadComplete(aRequest); } if (aType == imgINotificationObserver::FRAME_COMPLETE) { return OnFrameComplete(aRequest); } return NS_OK; }
// Returns true if a new frame is available, otherwise false. bool SPIReader::Poll() { // Read PACKET_SIZE bytes from the SPI port into the current slot in rawdata. read(GetSPIFileDescriptor(), rawdata + row*sizeof(uint8_t)*PACKET_SIZE, sizeof(uint8_t)*PACKET_SIZE); // The second byte of the row should be the same as the row number; if not, we've lost sync; start over. if (rawdata[row*PACKET_SIZE+1] != row) { row = 0; resets += 1; usleep(10); // If there are a LOT of resets, time out the VoSPI protocol, we're way out of sync. // At 20Mbit/s, 750 frames * 164 bytes/frame = 49ms... the device should provide a new frame very 37ms. if (resets == 750) { // TODO: This will actually time out BOTH SPI buses, i.e. any other SPIReader objects in use. // It's not a bad approach (the side effects are mild), but it's sloppy. // Need to use a system timer, and simply keep returning false when polled until the timer elapses. int oldPort = _spiPort; Close(); // Wait 200ms; officially it takes 185ms for the VoSPI protocol to reset. usleep(200000); Open(oldPort); // Don't keep timing out the VoSPI protocol if we don't pick up immediately on the next pass, just start over: resets = 0; // Still, we record the number of total restarts. restarts += 1; } return false; } row++; if (row == ROWS_PER_FRAME) { OnFrameComplete(); return true; } return false; }