void ImageContainerChild::SendImageNow(Image* aImage) { NS_ABORT_IF_FALSE(InImageBridgeChildThread(), "Should be in ImageBridgeChild thread."); if (mStop) { return; } bool needsCopy = false; // If the image can be converted to a shared image, no need to do a copy. SharedImage* img = AsSharedImage(aImage); if (!img) { needsCopy = true; // Try to get a compatible shared image from the pool img = GetSharedImageFor(aImage); if (!img && mActiveImageCount < (int)MAX_ACTIVE_SHARED_IMAGES) { // If no shared image available, allocate a new one img = AllocateSharedImageFor(aImage); } } if (img && (!needsCopy || CopyDataIntoSharedImage(aImage, img))) { // Keep a reference to the image we sent to compositor to maintain a // correct reference count. mImageQueue.AppendElement(aImage); SendPublishImage(*img); } else { NS_WARNING("Failed to send an image to the compositor"); } delete img; return; }
void ImageContainerChild::SendImageAsync(ImageContainer* aContainer, Image* aImage) { if(!aContainer || !aImage) { return; } if (mStop) { return; } if (InImageBridgeChildThread()) { SharedImage *img = ImageToSharedImage(aImage); if (img) { SendPublishImage(*img); } else { NS_WARNING("Failed to create a shared image!"); } delete img; return; } // Sending images and (potentially) allocating shmems must be done // on the ImageBridgeChild thread. Task *t = new ImageBridgeCopyAndSendTask(this, aContainer, aImage); GetMessageLoop()->PostTask(FROM_HERE, t); }