SharedImage* ImageContainerChild::CreateSharedImageFromData(Image* image) { NS_ABORT_IF_FALSE(InImageBridgeChildThread(), "Should be in ImageBridgeChild thread."); if (!image) { return nullptr; } if (image->GetFormat() == PLANAR_YCBCR ) { PlanarYCbCrImage *planarYCbCrImage = static_cast<PlanarYCbCrImage*>(image); const PlanarYCbCrImage::Data *data = planarYCbCrImage->GetData(); NS_ASSERTION(data, "Must be able to retrieve yuv data from image!"); if (!data) { return nullptr; } SharedMemory::SharedMemoryType shmType = OptimalShmemType(); size_t size = ShmemYCbCrImage::ComputeMinBufferSize(data->mYSize, data->mCbCrSize); Shmem shmem; if (!AllocUnsafeShmem(size, shmType, &shmem)) { return nullptr; } ShmemYCbCrImage::InitializeBufferInfo(shmem.get<uint8_t>(), data->mYSize, data->mCbCrSize); ShmemYCbCrImage shmemImage(shmem); if (!shmemImage.IsValid() || shmem.Size<uint8_t>() < size) { DeallocShmem(shmem); return nullptr; } for (int i = 0; i < data->mYSize.height; i++) { memcpy(shmemImage.GetYData() + i * shmemImage.GetYStride(), data->mYChannel + i * data->mYStride, data->mYSize.width); } for (int i = 0; i < data->mCbCrSize.height; i++) { memcpy(shmemImage.GetCbData() + i * shmemImage.GetCbCrStride(), data->mCbChannel + i * data->mCbCrStride, data->mCbCrSize.width); memcpy(shmemImage.GetCrData() + i * shmemImage.GetCbCrStride(), data->mCrChannel + i * data->mCbCrStride, data->mCbCrSize.width); } ++mActiveImageCount; SharedImage* result = new SharedImage(YCbCrImage(shmem, 0, data->GetPictureRect())); return result; #ifdef MOZ_WIDGET_GONK } else if (image->GetFormat() == GONK_IO_SURFACE) { GonkIOSurfaceImage* gonkImage = static_cast<GonkIOSurfaceImage*>(image); SharedImage* result = new SharedImage(gonkImage->GetSurfaceDescriptor()); return result; } else if (image->GetFormat() == GRALLOC_PLANAR_YCBCR) { GrallocPlanarYCbCrImage* GrallocImage = static_cast<GrallocPlanarYCbCrImage*>(image); SharedImage* result = new SharedImage(GrallocImage->GetSurfaceDescriptor()); return result; #endif } else { NS_RUNTIMEABORT("TODO: Only YCbCrImage is supported here right now."); } return nullptr; }
bool DeviceStorageRequestChild:: Recv__delete__(const DeviceStorageResponseValue& aValue) { switch (aValue.type()) { case DeviceStorageResponseValue::TErrorResponse: { DS_LOG_INFO("error %u", mRequest->GetId()); ErrorResponse r = aValue; mRequest->Reject(r.error()); break; } case DeviceStorageResponseValue::TSuccessResponse: { DS_LOG_INFO("success %u", mRequest->GetId()); nsString fullPath; mRequest->GetFile()->GetFullPath(fullPath); mRequest->Resolve(fullPath); break; } case DeviceStorageResponseValue::TFileDescriptorResponse: { DS_LOG_INFO("fd %u", mRequest->GetId()); FileDescriptorResponse r = aValue; DeviceStorageFile* file = mRequest->GetFile(); DeviceStorageFileDescriptor* descriptor = mRequest->GetFileDescriptor(); nsString fullPath; file->GetFullPath(fullPath); descriptor->mDSFile = file; descriptor->mFileDescriptor = r.fileDescriptor(); mRequest->Resolve(fullPath); break; } case DeviceStorageResponseValue::TBlobResponse: { DS_LOG_INFO("blob %u", mRequest->GetId()); BlobResponse r = aValue; BlobChild* actor = static_cast<BlobChild*>(r.blobChild()); RefPtr<BlobImpl> blobImpl = actor->GetBlobImpl(); mRequest->Resolve(blobImpl.get()); break; } case DeviceStorageResponseValue::TFreeSpaceStorageResponse: { DS_LOG_INFO("free %u", mRequest->GetId()); FreeSpaceStorageResponse r = aValue; mRequest->Resolve(r.freeBytes()); break; } case DeviceStorageResponseValue::TUsedSpaceStorageResponse: { DS_LOG_INFO("used %u", mRequest->GetId()); UsedSpaceStorageResponse r = aValue; mRequest->Resolve(r.usedBytes()); break; } case DeviceStorageResponseValue::TAvailableStorageResponse: { DS_LOG_INFO("available %u", mRequest->GetId()); AvailableStorageResponse r = aValue; mRequest->Resolve(r.mountState()); break; } case DeviceStorageResponseValue::TStorageStatusResponse: { DS_LOG_INFO("status %u", mRequest->GetId()); StorageStatusResponse r = aValue; mRequest->Resolve(r.storageStatus()); break; } case DeviceStorageResponseValue::TFormatStorageResponse: { DS_LOG_INFO("format %u", mRequest->GetId()); FormatStorageResponse r = aValue; mRequest->Resolve(r.mountState()); break; } case DeviceStorageResponseValue::TMountStorageResponse: { DS_LOG_INFO("mount %u", mRequest->GetId()); MountStorageResponse r = aValue; mRequest->Resolve(r.storageStatus()); break; } case DeviceStorageResponseValue::TUnmountStorageResponse: { DS_LOG_INFO("unmount %u", mRequest->GetId()); UnmountStorageResponse r = aValue; mRequest->Resolve(r.storageStatus()); break; } case DeviceStorageResponseValue::TEnumerationResponse: { DS_LOG_INFO("enumerate %u", mRequest->GetId()); EnumerationResponse r = aValue; auto request = static_cast<DeviceStorageCursorRequest*>(mRequest.get()); uint32_t count = r.paths().Length(); request->AddFiles(count); for (uint32_t i = 0; i < count; i++) { RefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(r.type(), r.paths()[i].storageName(), r.rootdir(), r.paths()[i].name()); request->AddFile(dsf.forget()); } request->Continue(); break; } default: { DS_LOG_ERROR("unknown %u", mRequest->GetId()); NS_RUNTIMEABORT("not reached"); break; } } return true; }
nsresult ShutdownXPCOM(nsIServiceManager* aServMgr) { // Make sure the hang monitor is enabled for shutdown. HangMonitor::NotifyActivity(); if (!NS_IsMainThread()) { NS_RUNTIMEABORT("Shutdown on wrong thread"); } nsresult rv; nsCOMPtr<nsISimpleEnumerator> moduleLoaders; // Notify observers of xpcom shutting down { // Block it so that the COMPtr will get deleted before we hit // servicemanager shutdown nsCOMPtr<nsIThread> thread = do_GetCurrentThread(); if (NS_WARN_IF(!thread)) { return NS_ERROR_UNEXPECTED; } RefPtr<nsObserverService> observerService; CallGetService("@mozilla.org/observer-service;1", (nsObserverService**)getter_AddRefs(observerService)); if (observerService) { mozilla::KillClearOnShutdown(ShutdownPhase::WillShutdown); observerService->NotifyObservers(nullptr, NS_XPCOM_WILL_SHUTDOWN_OBSERVER_ID, nullptr); nsCOMPtr<nsIServiceManager> mgr; rv = NS_GetServiceManager(getter_AddRefs(mgr)); if (NS_SUCCEEDED(rv)) { mozilla::KillClearOnShutdown(ShutdownPhase::Shutdown); observerService->NotifyObservers(mgr, NS_XPCOM_SHUTDOWN_OBSERVER_ID, nullptr); } } // This must happen after the shutdown of media and widgets, which // are triggered by the NS_XPCOM_SHUTDOWN_OBSERVER_ID notification. NS_ProcessPendingEvents(thread); gfxPlatform::ShutdownLayersIPC(); mozilla::scache::StartupCache::DeleteSingleton(); if (observerService) { mozilla::KillClearOnShutdown(ShutdownPhase::ShutdownThreads); observerService->NotifyObservers(nullptr, NS_XPCOM_SHUTDOWN_THREADS_OBSERVER_ID, nullptr); } gXPCOMThreadsShutDown = true; NS_ProcessPendingEvents(thread); // Shutdown the timer thread and all timers that might still be alive before // shutting down the component manager nsTimerImpl::Shutdown(); NS_ProcessPendingEvents(thread); // Shutdown all remaining threads. This method does not return until // all threads created using the thread manager (with the exception of // the main thread) have exited. nsThreadManager::get()->Shutdown(); NS_ProcessPendingEvents(thread); HangMonitor::NotifyActivity(); // Late-write checks needs to find the profile directory, so it has to // be initialized before mozilla::services::Shutdown or (because of // xpcshell tests replacing the service) modules being unloaded. mozilla::InitLateWriteChecks(); // We save the "xpcom-shutdown-loaders" observers to notify after // the observerservice is gone. if (observerService) { mozilla::KillClearOnShutdown(ShutdownPhase::ShutdownLoaders); observerService->EnumerateObservers(NS_XPCOM_SHUTDOWN_LOADERS_OBSERVER_ID, getter_AddRefs(moduleLoaders)); observerService->Shutdown(); } } // Free ClearOnShutdown()'ed smart pointers. This needs to happen *after* // we've finished notifying observers of XPCOM shutdown, because shutdown // observers themselves might call ClearOnShutdown(). mozilla::KillClearOnShutdown(ShutdownPhase::ShutdownFinal); // XPCOM is officially in shutdown mode NOW // Set this only after the observers have been notified as this // will cause servicemanager to become inaccessible. mozilla::services::Shutdown(); // We may have AddRef'd for the caller of NS_InitXPCOM, so release it // here again: NS_IF_RELEASE(aServMgr); // Shutdown global servicemanager if (nsComponentManagerImpl::gComponentManager) { nsComponentManagerImpl::gComponentManager->FreeServices(); } // Release the directory service nsDirectoryService::gService = nullptr; free(gGREBinPath); gGREBinPath = nullptr; if (moduleLoaders) { bool more; nsCOMPtr<nsISupports> el; while (NS_SUCCEEDED(moduleLoaders->HasMoreElements(&more)) && more) { moduleLoaders->GetNext(getter_AddRefs(el)); // Don't worry about weak-reference observers here: there is // no reason for weak-ref observers to register for // xpcom-shutdown-loaders // FIXME: This can cause harmless writes from sqlite committing // log files. We have to ignore them before we can move // the mozilla::PoisonWrite call before this point. See bug // 834945 for the details. nsCOMPtr<nsIObserver> obs(do_QueryInterface(el)); if (obs) { obs->Observe(nullptr, NS_XPCOM_SHUTDOWN_LOADERS_OBSERVER_ID, nullptr); } } moduleLoaders = nullptr; } bool shutdownCollect; #ifdef NS_FREE_PERMANENT_DATA shutdownCollect = true; #else shutdownCollect = !!PR_GetEnv("MOZ_CC_RUN_DURING_SHUTDOWN"); #endif nsCycleCollector_shutdown(shutdownCollect); PROFILER_MARKER("Shutdown xpcom"); // If we are doing any shutdown checks, poison writes. if (gShutdownChecks != SCM_NOTHING) { #ifdef XP_MACOSX mozilla::OnlyReportDirtyWrites(); #endif /* XP_MACOSX */ mozilla::BeginLateWriteChecks(); } // Shutdown nsLocalFile string conversion NS_ShutdownLocalFile(); #ifdef XP_UNIX NS_ShutdownNativeCharsetUtils(); #endif // Shutdown xpcom. This will release all loaders and cause others holding // a refcount to the component manager to release it. if (nsComponentManagerImpl::gComponentManager) { rv = (nsComponentManagerImpl::gComponentManager)->Shutdown(); NS_ASSERTION(NS_SUCCEEDED(rv), "Component Manager shutdown failed."); } else { NS_WARNING("Component Manager was never created ..."); } #ifdef MOZ_ENABLE_PROFILER_SPS // In optimized builds we don't do shutdown collections by default, so // uncollected (garbage) objects may keep the nsXPConnect singleton alive, // and its XPCJSRuntime along with it. However, we still destroy various // bits of state in JS_ShutDown(), so we need to make sure the profiler // can't access them when it shuts down. This call nulls out the // JS pseudo-stack's internal reference to the main thread JSRuntime, // duplicating the call in XPCJSRuntime::~XPCJSRuntime() in case that // never fired. if (PseudoStack* stack = mozilla_get_pseudo_stack()) { stack->sampleRuntime(nullptr); } #endif // Shut down the JS engine. JS_ShutDown(); // Release our own singletons // Do this _after_ shutting down the component manager, because the // JS component loader will use XPConnect to call nsIModule::canUnload, // and that will spin up the InterfaceInfoManager again -- bad mojo XPTInterfaceInfoManager::FreeInterfaceInfoManager(); // Finally, release the component manager last because it unloads the // libraries: if (nsComponentManagerImpl::gComponentManager) { nsrefcnt cnt; NS_RELEASE2(nsComponentManagerImpl::gComponentManager, cnt); NS_ASSERTION(cnt == 0, "Component Manager being held past XPCOM shutdown."); } nsComponentManagerImpl::gComponentManager = nullptr; nsCategoryManager::Destroy(); NS_ShutdownAtomTable(); NS_IF_RELEASE(gDebug); delete sIOThread; sIOThread = nullptr; delete sMessageLoop; sMessageLoop = nullptr; if (sCommandLineWasInitialized) { CommandLine::Terminate(); sCommandLineWasInitialized = false; } delete sExitManager; sExitManager = nullptr; Omnijar::CleanUp(); HangMonitor::Shutdown(); delete sMainHangMonitor; sMainHangMonitor = nullptr; BackgroundHangMonitor::Shutdown(); profiler_shutdown(); NS_LogTerm(); #if defined(MOZ_WIDGET_GONK) // This _exit(0) call is intended to be temporary, to get shutdown leak // checking working on non-B2G platforms. // On debug B2G, the child process crashes very late. Instead, just // give up so at least we exit cleanly. See bug 1071866. if (XRE_IsContentProcess()) { NS_WARNING("Exiting child process early!"); _exit(0); } #endif return NS_OK; }
static int X11Error(Display *display, XErrorEvent *event) { // Get an indication of how long ago the request that caused the error was // made. unsigned long age = NextRequest(display) - event->serial; // Get a string to represent the request that caused the error. nsCAutoString message; if (event->request_code < 128) { // Core protocol request message.AppendInt(event->request_code); } else { // Extension request // man XSetErrorHandler says "the error handler should not call any // functions (directly or indirectly) on the display that will generate // protocol requests or that will look for input events" so we use another // temporary Display to request extension information. This assumes on // the DISPLAY environment variable has been set and matches what was used // to open |display|. Display *tmpDisplay = XOpenDisplay(NULL); if (tmpDisplay) { int nExts; char** extNames = XListExtensions(tmpDisplay, &nExts); int first_error; if (extNames) { for (int i = 0; i < nExts; ++i) { int major_opcode, first_event; if (XQueryExtension(tmpDisplay, extNames[i], &major_opcode, &first_event, &first_error) && major_opcode == event->request_code) { message.Append(extNames[i]); message.Append('.'); message.AppendInt(event->minor_code); break; } } XFreeExtensionList(extNames); } XCloseDisplay(tmpDisplay); #ifdef MOZ_WIDGET_GTK2 // GDK2 calls XCloseDevice the devices that it opened on startup, but // the XI protocol no longer ensures that the devices will still exist. // If they have been removed, then a BadDevice error results. Ignore // this error. if (message.EqualsLiteral("XInputExtension.4") && event->error_code == first_error + 0) { return 0; } #endif } } char buffer[BUFSIZE]; if (message.IsEmpty()) { buffer[0] = '\0'; } else { XGetErrorDatabaseText(display, "XRequest", message.get(), "", buffer, sizeof(buffer)); } nsCAutoString notes; if (buffer[0]) { notes.Append(buffer); } else { notes.Append("Request "); notes.AppendInt(event->request_code); notes.Append('.'); notes.AppendInt(event->minor_code); } notes.Append(": "); // Get a string to describe the error. XGetErrorText(display, event->error_code, buffer, sizeof(buffer)); notes.Append(buffer); // For requests where Xlib gets the reply synchronously, |age| will be 1 // and the stack will include the function making the request. For // asynchronous requests, the current stack will often be unrelated to the // point of making the request, even if |age| is 1, but sometimes this may // help us count back to the point of the request. With XSynchronize on, // the stack will include the function making the request, even though // |age| will be 2 for asynchronous requests because XSynchronize is // implemented by an empty request from an XSync, which has not yet been // processed. if (age > 1) { // XSynchronize returns the previous "after function". If a second // XSynchronize call returns the same function after an enable call then // synchronization must have already been enabled. if (XSynchronize(display, True) == XSynchronize(display, False)) { notes.Append("; sync"); } else { notes.Append("; "); notes.AppendInt(PRUint32(age)); notes.Append(" requests ago"); } } #ifdef MOZ_CRASHREPORTER switch (XRE_GetProcessType()) { case GeckoProcessType_Default: case GeckoProcessType_Plugin: case GeckoProcessType_Content: CrashReporter::AppendAppNotesToCrashReport(notes); break; default: ; // crash report notes not supported. } #endif #ifdef DEBUG // The resource id is unlikely to be useful in a crash report without // context of other ids, but add it to the debug console output. notes.Append("; id=0x"); notes.AppendInt(PRUint32(event->resourceid), 16); #ifdef MOZ_X11 // Actually, for requests where Xlib gets the reply synchronously, // MOZ_X_SYNC=1 will not be necessary, but we don't have a table to tell us // which requests get a synchronous reply. if (!PR_GetEnv("MOZ_X_SYNC")) { notes.Append("\nRe-running with MOZ_X_SYNC=1 in the environment may give a more helpful backtrace."); } #endif #endif #ifdef MOZ_WIDGET_QT // We should not abort here if MOZ_X_SYNC is not set // until http://bugreports.qt.nokia.com/browse/QTBUG-4042 // not fixed, just print error value if (!PR_GetEnv("MOZ_X_SYNC")) { fprintf(stderr, "XError: %s\n", notes.get()); return 0; // temporary workaround for bug 161472 } #endif NS_RUNTIMEABORT(notes.get()); return 0; // not reached }
already_AddRefed<CanvasLayer> LayerManagerComposite::CreateCanvasLayer() { NS_RUNTIMEABORT("Should only be called on the drawing side"); return nullptr; }
bool DeviceStorageRequestChild:: Recv__delete__(const DeviceStorageResponseValue& aValue) { if (mCallback) { mCallback->RequestComplete(); mCallback = nullptr; } nsCOMPtr<nsPIDOMWindow> window = mRequest->GetOwner(); if (!window) { return true; } switch (aValue.type()) { case DeviceStorageResponseValue::TErrorResponse: { ErrorResponse r = aValue; mRequest->FireError(r.error()); break; } case DeviceStorageResponseValue::TSuccessResponse: { nsString fullPath; mDSFile->GetFullPath(fullPath); AutoJSContext cx; JS::Rooted<JS::Value> result(cx); StringToJsval(window, fullPath, &result); mRequest->FireSuccess(result); break; } case DeviceStorageResponseValue::TFileDescriptorResponse: { FileDescriptorResponse r = aValue; nsString fullPath; mDSFile->GetFullPath(fullPath); AutoJSContext cx; JS::Rooted<JS::Value> result(cx); StringToJsval(window, fullPath, &result); mDSFileDescriptor->mDSFile = mDSFile; mDSFileDescriptor->mFileDescriptor = r.fileDescriptor(); mRequest->FireSuccess(result); break; } case DeviceStorageResponseValue::TBlobResponse: { BlobResponse r = aValue; BlobChild* actor = static_cast<BlobChild*>(r.blobChild()); nsCOMPtr<nsIDOMBlob> blob = actor->GetBlob(); nsCOMPtr<nsIDOMFile> file = do_QueryInterface(blob); AutoJSContext cx; JS::Rooted<JS::Value> result(cx, InterfaceToJsval(window, file, &NS_GET_IID(nsIDOMFile))); mRequest->FireSuccess(result); break; } case DeviceStorageResponseValue::TFreeSpaceStorageResponse: { FreeSpaceStorageResponse r = aValue; AutoJSContext cx; JS::Rooted<JS::Value> result(cx, JS_NumberValue(double(r.freeBytes()))); mRequest->FireSuccess(result); break; } case DeviceStorageResponseValue::TUsedSpaceStorageResponse: { UsedSpaceStorageResponse r = aValue; AutoJSContext cx; JS::Rooted<JS::Value> result(cx, JS_NumberValue(double(r.usedBytes()))); mRequest->FireSuccess(result); break; } case DeviceStorageResponseValue::TAvailableStorageResponse: { AvailableStorageResponse r = aValue; AutoJSContext cx; JS::Rooted<JS::Value> result(cx); StringToJsval(window, r.mountState(), &result); mRequest->FireSuccess(result); break; } case DeviceStorageResponseValue::TStorageStatusResponse: { StorageStatusResponse r = aValue; AutoJSContext cx; JS::Rooted<JS::Value> result(cx); StringToJsval(window, r.storageStatus(), &result); mRequest->FireSuccess(result); break; } case DeviceStorageResponseValue::TFormatStorageResponse: { FormatStorageResponse r = aValue; AutoJSContext cx; JS::Rooted<JS::Value> result(cx); StringToJsval(window, r.mountState(), &result); mRequest->FireSuccess(result); break; } case DeviceStorageResponseValue::TMountStorageResponse: { MountStorageResponse r = aValue; AutoJSContext cx; JS::Rooted<JS::Value> result(cx); StringToJsval(window, r.storageStatus(), &result); mRequest->FireSuccess(result); break; } case DeviceStorageResponseValue::TUnmountStorageResponse: { UnmountStorageResponse r = aValue; AutoJSContext cx; JS::Rooted<JS::Value> result(cx); StringToJsval(window, r.storageStatus(), &result); mRequest->FireSuccess(result); break; } case DeviceStorageResponseValue::TEnumerationResponse: { EnumerationResponse r = aValue; nsDOMDeviceStorageCursor* cursor = static_cast<nsDOMDeviceStorageCursor*>(mRequest.get()); uint32_t count = r.paths().Length(); for (uint32_t i = 0; i < count; i++) { nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(r.type(), r.paths()[i].storageName(), r.rootdir(), r.paths()[i].name()); cursor->mFiles.AppendElement(dsf); } nsRefPtr<ContinueCursorEvent> event = new ContinueCursorEvent(cursor); event->Continue(); break; } default: { NS_RUNTIMEABORT("not reached"); break; } } return true; }
void ClientLayerManager::ForwardTransaction(bool aScheduleComposite) { mPhase = PHASE_FORWARD; mLatestTransactionId = mTransactionIdAllocator->GetTransactionId(); TimeStamp transactionStart; if (!mTransactionIdAllocator->GetTransactionStart().IsNull()) { transactionStart = mTransactionIdAllocator->GetTransactionStart(); } else { transactionStart = mTransactionStart; } // forward this transaction's changeset to our LayerManagerComposite bool sent; AutoInfallibleTArray<EditReply, 10> replies; if (mForwarder->EndTransaction(&replies, mRegionToClear, mLatestTransactionId, aScheduleComposite, mPaintSequenceNumber, mIsRepeatTransaction, transactionStart, &sent)) { for (nsTArray<EditReply>::size_type i = 0; i < replies.Length(); ++i) { const EditReply& reply = replies[i]; switch (reply.type()) { case EditReply::TOpContentBufferSwap: { MOZ_LAYERS_LOG(("[LayersForwarder] DoubleBufferSwap")); const OpContentBufferSwap& obs = reply.get_OpContentBufferSwap(); CompositableClient* compositable = CompositableClient::FromIPDLActor(obs.compositableChild()); ContentClientRemote* contentClient = static_cast<ContentClientRemote*>(compositable); MOZ_ASSERT(contentClient); contentClient->SwapBuffers(obs.frontUpdatedRegion()); break; } case EditReply::TOpTextureSwap: { MOZ_LAYERS_LOG(("[LayersForwarder] TextureSwap")); const OpTextureSwap& ots = reply.get_OpTextureSwap(); CompositableClient* compositable = CompositableClient::FromIPDLActor(ots.compositableChild()); MOZ_ASSERT(compositable); compositable->SetDescriptorFromReply(ots.textureId(), ots.image()); break; } case EditReply::TReturnReleaseFence: { const ReturnReleaseFence& rep = reply.get_ReturnReleaseFence(); FenceHandle fence = rep.fence(); PTextureChild* child = rep.textureChild(); if (!fence.IsValid() || !child) { break; } RefPtr<TextureClient> texture = TextureClient::AsTextureClient(child); if (texture) { texture->SetReleaseFenceHandle(fence); } break; } default: NS_RUNTIMEABORT("not reached"); } } if (sent) { mNeedsComposite = false; } } else if (HasShadowManager()) { NS_WARNING("failed to forward Layers transaction"); } if (!sent) { // Clear the transaction id so that it doesn't get returned // unless we forwarded to somewhere that doesn't actually // have a compositor. mTransactionIdAllocator->RevokeTransactionId(mLatestTransactionId); } mForwarder->RemoveTexturesIfNecessary(); mForwarder->SendPendingAsyncMessge(); mPhase = PHASE_NONE; // this may result in Layers being deleted, which results in // PLayer::Send__delete__() and DeallocShmem() mKeepAlive.Clear(); }
void DeviceStorageRequestParent::Dispatch() { switch (mParams.type()) { case DeviceStorageParams::TDeviceStorageAddParams: { DeviceStorageAddParams p = mParams; nsCOMPtr<nsIFile> f; NS_NewLocalFile(p.fullpath(), false, getter_AddRefs(f)); nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(p.type(), f); BlobParent* bp = static_cast<BlobParent*>(p.blobParent()); nsCOMPtr<nsIDOMBlob> blob = bp->GetBlob(); nsCOMPtr<nsIInputStream> stream; blob->GetInternalStream(getter_AddRefs(stream)); nsRefPtr<CancelableRunnable> r = new WriteFileEvent(this, dsf, stream); nsCOMPtr<nsIEventTarget> target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); NS_ASSERTION(target, "Must have stream transport service"); target->Dispatch(r, NS_DISPATCH_NORMAL); break; } case DeviceStorageParams::TDeviceStorageGetParams: { DeviceStorageGetParams p = mParams; nsCOMPtr<nsIFile> f; NS_NewLocalFile(p.fullpath(), false, getter_AddRefs(f)); nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(p.type(), f); dsf->SetPath(p.name()); nsRefPtr<CancelableRunnable> r = new ReadFileEvent(this, dsf); nsCOMPtr<nsIEventTarget> target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); NS_ASSERTION(target, "Must have stream transport service"); target->Dispatch(r, NS_DISPATCH_NORMAL); break; } case DeviceStorageParams::TDeviceStorageDeleteParams: { DeviceStorageDeleteParams p = mParams; nsCOMPtr<nsIFile> f; NS_NewLocalFile(p.fullpath(), false, getter_AddRefs(f)); nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(p.type(), f); nsRefPtr<CancelableRunnable> r = new DeleteFileEvent(this, dsf); nsCOMPtr<nsIEventTarget> target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); NS_ASSERTION(target, "Must have stream transport service"); target->Dispatch(r, NS_DISPATCH_NORMAL); break; } case DeviceStorageParams::TDeviceStorageFreeSpaceParams: { DeviceStorageFreeSpaceParams p = mParams; nsCOMPtr<nsIFile> f; NS_NewLocalFile(p.fullpath(), false, getter_AddRefs(f)); nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(p.type(), f); nsRefPtr<FreeSpaceFileEvent> r = new FreeSpaceFileEvent(this, dsf); nsCOMPtr<nsIEventTarget> target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); NS_ASSERTION(target, "Must have stream transport service"); target->Dispatch(r, NS_DISPATCH_NORMAL); break; } case DeviceStorageParams::TDeviceStorageUsedSpaceParams: { DeviceStorageUsedSpaceParams p = mParams; nsCOMPtr<nsIFile> f; NS_NewLocalFile(p.fullpath(), false, getter_AddRefs(f)); nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(p.type(), f); nsRefPtr<UsedSpaceFileEvent> r = new UsedSpaceFileEvent(this, dsf); nsCOMPtr<nsIEventTarget> target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); NS_ASSERTION(target, "Must have stream transport service"); target->Dispatch(r, NS_DISPATCH_NORMAL); break; } case DeviceStorageParams::TDeviceStorageAvailableParams: { nsRefPtr<PostAvailableResultEvent> r = new PostAvailableResultEvent(this); NS_DispatchToMainThread(r); break; } case DeviceStorageParams::TDeviceStorageEnumerationParams: { DeviceStorageEnumerationParams p = mParams; nsCOMPtr<nsIFile> f; NS_NewLocalFile(p.fullpath(), false, getter_AddRefs(f)); nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(p.type(), f); nsRefPtr<CancelableRunnable> r = new EnumerateFileEvent(this, dsf, p.since()); nsCOMPtr<nsIEventTarget> target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); NS_ASSERTION(target, "Must have stream transport service"); target->Dispatch(r, NS_DISPATCH_NORMAL); break; } default: { NS_RUNTIMEABORT("not reached"); break; } } }
bool ShadowLayersParent::RecvUpdate(const InfallibleTArray<Edit>& cset, const TargetConfig& targetConfig, const bool& isFirstPaint, InfallibleTArray<EditReply>* reply) { #ifdef COMPOSITOR_PERFORMANCE_WARNING TimeStamp updateStart = TimeStamp::Now(); #endif MOZ_LAYERS_LOG(("[ParentSide] received txn with %d edits", cset.Length())); if (mDestroyed || layer_manager()->IsDestroyed()) { return true; } EditReplyVector replyv; layer_manager()->BeginTransactionWithTarget(NULL); for (EditArray::index_type i = 0; i < cset.Length(); ++i) { const Edit& edit = cset[i]; switch (edit.type()) { // Create* ops case Edit::TOpCreateThebesLayer: { MOZ_LAYERS_LOG(("[ParentSide] CreateThebesLayer")); nsRefPtr<ShadowThebesLayer> layer = layer_manager()->CreateShadowThebesLayer(); layer->SetAllocator(this); AsShadowLayer(edit.get_OpCreateThebesLayer())->Bind(layer); break; } case Edit::TOpCreateContainerLayer: { MOZ_LAYERS_LOG(("[ParentSide] CreateContainerLayer")); nsRefPtr<ContainerLayer> layer = layer_manager()->CreateShadowContainerLayer(); AsShadowLayer(edit.get_OpCreateContainerLayer())->Bind(layer); break; } case Edit::TOpCreateImageLayer: { MOZ_LAYERS_LOG(("[ParentSide] CreateImageLayer")); nsRefPtr<ShadowImageLayer> layer = layer_manager()->CreateShadowImageLayer(); AsShadowLayer(edit.get_OpCreateImageLayer())->Bind(layer); break; } case Edit::TOpCreateColorLayer: { MOZ_LAYERS_LOG(("[ParentSide] CreateColorLayer")); nsRefPtr<ShadowColorLayer> layer = layer_manager()->CreateShadowColorLayer(); AsShadowLayer(edit.get_OpCreateColorLayer())->Bind(layer); break; } case Edit::TOpCreateCanvasLayer: { MOZ_LAYERS_LOG(("[ParentSide] CreateCanvasLayer")); nsRefPtr<ShadowCanvasLayer> layer = layer_manager()->CreateShadowCanvasLayer(); layer->SetAllocator(this); AsShadowLayer(edit.get_OpCreateCanvasLayer())->Bind(layer); break; } case Edit::TOpCreateRefLayer: { MOZ_LAYERS_LOG(("[ParentSide] CreateRefLayer")); nsRefPtr<ShadowRefLayer> layer = layer_manager()->CreateShadowRefLayer(); layer->SetAllocator(this); AsShadowLayer(edit.get_OpCreateRefLayer())->Bind(layer); break; } // Attributes case Edit::TOpSetLayerAttributes: { MOZ_LAYERS_LOG(("[ParentSide] SetLayerAttributes")); const OpSetLayerAttributes& osla = edit.get_OpSetLayerAttributes(); Layer* layer = AsShadowLayer(osla)->AsLayer(); const LayerAttributes& attrs = osla.attrs(); const CommonLayerAttributes& common = attrs.common(); layer->SetVisibleRegion(common.visibleRegion()); layer->SetContentFlags(common.contentFlags()); layer->SetOpacity(common.opacity()); layer->SetClipRect(common.useClipRect() ? &common.clipRect() : NULL); layer->SetBaseTransform(common.transform().value()); layer->SetPostScale(common.postXScale(), common.postYScale()); static bool fixedPositionLayersEnabled = getenv("MOZ_ENABLE_FIXED_POSITION_LAYERS") != 0; if (fixedPositionLayersEnabled) { layer->SetIsFixedPosition(common.isFixedPosition()); layer->SetFixedPositionAnchor(common.fixedPositionAnchor()); } if (PLayerParent* maskLayer = common.maskLayerParent()) { layer->SetMaskLayer(cast(maskLayer)->AsLayer()); } else { layer->SetMaskLayer(NULL); } layer->SetAnimations(common.animations()); typedef SpecificLayerAttributes Specific; const SpecificLayerAttributes& specific = attrs.specific(); switch (specific.type()) { case Specific::Tnull_t: break; case Specific::TThebesLayerAttributes: { MOZ_LAYERS_LOG(("[ParentSide] thebes layer")); ShadowThebesLayer* thebesLayer = static_cast<ShadowThebesLayer*>(layer); const ThebesLayerAttributes& attrs = specific.get_ThebesLayerAttributes(); thebesLayer->SetValidRegion(attrs.validRegion()); break; } case Specific::TContainerLayerAttributes: { MOZ_LAYERS_LOG(("[ParentSide] container layer")); ContainerLayer* containerLayer = static_cast<ContainerLayer*>(layer); const ContainerLayerAttributes& attrs = specific.get_ContainerLayerAttributes(); containerLayer->SetFrameMetrics(attrs.metrics()); containerLayer->SetPreScale(attrs.preXScale(), attrs.preYScale()); break; } case Specific::TColorLayerAttributes: MOZ_LAYERS_LOG(("[ParentSide] color layer")); static_cast<ColorLayer*>(layer)->SetColor( specific.get_ColorLayerAttributes().color().value()); break; case Specific::TCanvasLayerAttributes: MOZ_LAYERS_LOG(("[ParentSide] canvas layer")); static_cast<CanvasLayer*>(layer)->SetFilter( specific.get_CanvasLayerAttributes().filter()); break; case Specific::TRefLayerAttributes: MOZ_LAYERS_LOG(("[ParentSide] ref layer")); static_cast<RefLayer*>(layer)->SetReferentId( specific.get_RefLayerAttributes().id()); break; case Specific::TImageLayerAttributes: { MOZ_LAYERS_LOG(("[ParentSide] image layer")); ImageLayer* imageLayer = static_cast<ImageLayer*>(layer); const ImageLayerAttributes& attrs = specific.get_ImageLayerAttributes(); imageLayer->SetFilter(attrs.filter()); imageLayer->SetForceSingleTile(attrs.forceSingleTile()); break; } default: NS_RUNTIMEABORT("not reached"); } break; } // Tree ops case Edit::TOpSetRoot: { MOZ_LAYERS_LOG(("[ParentSide] SetRoot")); mRoot = AsShadowLayer(edit.get_OpSetRoot())->AsContainer(); break; } case Edit::TOpInsertAfter: { MOZ_LAYERS_LOG(("[ParentSide] InsertAfter")); const OpInsertAfter& oia = edit.get_OpInsertAfter(); ShadowContainer(oia)->AsContainer()->InsertAfter( ShadowChild(oia)->AsLayer(), ShadowAfter(oia)->AsLayer()); break; } case Edit::TOpAppendChild: { MOZ_LAYERS_LOG(("[ParentSide] AppendChild")); const OpAppendChild& oac = edit.get_OpAppendChild(); ShadowContainer(oac)->AsContainer()->InsertAfter( ShadowChild(oac)->AsLayer(), NULL); break; } case Edit::TOpRemoveChild: { MOZ_LAYERS_LOG(("[ParentSide] RemoveChild")); const OpRemoveChild& orc = edit.get_OpRemoveChild(); Layer* childLayer = ShadowChild(orc)->AsLayer(); ShadowContainer(orc)->AsContainer()->RemoveChild(childLayer); break; } case Edit::TOpRepositionChild: { MOZ_LAYERS_LOG(("[ParentSide] RepositionChild")); const OpRepositionChild& orc = edit.get_OpRepositionChild(); ShadowContainer(orc)->AsContainer()->RepositionChild( ShadowChild(orc)->AsLayer(), ShadowAfter(orc)->AsLayer()); break; } case Edit::TOpRaiseToTopChild: { MOZ_LAYERS_LOG(("[ParentSide] RaiseToTopChild")); const OpRaiseToTopChild& rtc = edit.get_OpRaiseToTopChild(); ShadowContainer(rtc)->AsContainer()->RepositionChild( ShadowChild(rtc)->AsLayer(), NULL); break; } case Edit::TOpPaintTiledLayerBuffer: { MOZ_LAYERS_LOG(("[ParentSide] Paint TiledLayerBuffer")); const OpPaintTiledLayerBuffer& op = edit.get_OpPaintTiledLayerBuffer(); ShadowLayerParent* shadow = AsShadowLayer(op); ShadowThebesLayer* shadowLayer = static_cast<ShadowThebesLayer*>(shadow->AsLayer()); TiledLayerComposer* tileComposer = shadowLayer->AsTiledLayerComposer(); NS_ASSERTION(tileComposer, "shadowLayer is not a tile composer"); BasicTiledLayerBuffer* p = (BasicTiledLayerBuffer*)op.tiledLayerBuffer(); tileComposer->PaintedTiledLayerBuffer(p); break; } case Edit::TOpPaintThebesBuffer: { MOZ_LAYERS_LOG(("[ParentSide] Paint ThebesLayer")); const OpPaintThebesBuffer& op = edit.get_OpPaintThebesBuffer(); ShadowLayerParent* shadow = AsShadowLayer(op); ShadowThebesLayer* thebes = static_cast<ShadowThebesLayer*>(shadow->AsLayer()); const ThebesBuffer& newFront = op.newFrontBuffer(); RenderTraceInvalidateStart(thebes, "FF00FF", op.updatedRegion().GetBounds()); OptionalThebesBuffer newBack; nsIntRegion newValidRegion; OptionalThebesBuffer readonlyFront; nsIntRegion frontUpdatedRegion; thebes->Swap(newFront, op.updatedRegion(), &newBack, &newValidRegion, &readonlyFront, &frontUpdatedRegion); replyv.push_back( OpThebesBufferSwap( shadow, NULL, newBack, newValidRegion, readonlyFront, frontUpdatedRegion)); RenderTraceInvalidateEnd(thebes, "FF00FF"); break; } case Edit::TOpPaintCanvas: { MOZ_LAYERS_LOG(("[ParentSide] Paint CanvasLayer")); const OpPaintCanvas& op = edit.get_OpPaintCanvas(); ShadowLayerParent* shadow = AsShadowLayer(op); ShadowCanvasLayer* canvas = static_cast<ShadowCanvasLayer*>(shadow->AsLayer()); RenderTraceInvalidateStart(canvas, "FF00FF", canvas->GetVisibleRegion().GetBounds()); canvas->SetAllocator(this); CanvasSurface newBack; canvas->Swap(op.newFrontBuffer(), op.needYFlip(), &newBack); canvas->Updated(); replyv.push_back(OpBufferSwap(shadow, NULL, newBack)); RenderTraceInvalidateEnd(canvas, "FF00FF"); break; } case Edit::TOpPaintImage: { MOZ_LAYERS_LOG(("[ParentSide] Paint ImageLayer")); const OpPaintImage& op = edit.get_OpPaintImage(); ShadowLayerParent* shadow = AsShadowLayer(op); ShadowImageLayer* image = static_cast<ShadowImageLayer*>(shadow->AsLayer()); RenderTraceInvalidateStart(image, "FF00FF", image->GetVisibleRegion().GetBounds()); image->SetAllocator(this); SharedImage newBack; image->Swap(op.newFrontBuffer(), &newBack); replyv.push_back(OpImageSwap(shadow, NULL, newBack)); RenderTraceInvalidateEnd(image, "FF00FF"); break; } default: NS_RUNTIMEABORT("not reached"); } } layer_manager()->EndTransaction(NULL, NULL, LayerManager::END_NO_IMMEDIATE_REDRAW); reply->SetCapacity(replyv.size()); if (replyv.size() > 0) { reply->AppendElements(&replyv.front(), replyv.size()); } // Ensure that any pending operations involving back and front // buffers have completed, so that neither process stomps on the // other's buffer contents. ShadowLayerManager::PlatformSyncBeforeReplyUpdate(); mShadowLayersManager->ShadowLayersUpdated(this, targetConfig, isFirstPaint); #ifdef COMPOSITOR_PERFORMANCE_WARNING int compositeTime = (int)(mozilla::TimeStamp::Now() - updateStart).ToMilliseconds(); if (compositeTime > 15) { printf_stderr("Compositor: Layers update took %i ms (blocking gecko).\n", compositeTime); } #endif return true; }
bool LayerTransactionParent::RecvUpdate(const InfallibleTArray<Edit>& cset, const TargetConfig& targetConfig, const bool& isFirstPaint, const bool& scheduleComposite, InfallibleTArray<EditReply>* reply) { profiler_tracing("Paint", "Composite", TRACING_INTERVAL_START); PROFILER_LABEL("LayerTransactionParent", "RecvUpdate"); #ifdef COMPOSITOR_PERFORMANCE_WARNING TimeStamp updateStart = TimeStamp::Now(); #endif MOZ_LAYERS_LOG(("[ParentSide] received txn with %d edits", cset.Length())); if (mDestroyed || !layer_manager() || layer_manager()->IsDestroyed()) { return true; } // Clear fence handles used in previsou transaction. ClearPrevFenceHandles(); EditReplyVector replyv; { AutoResolveRefLayers resolve(mShadowLayersManager->GetCompositionManager()); layer_manager()->BeginTransaction(); } for (EditArray::index_type i = 0; i < cset.Length(); ++i) { const Edit& edit = cset[i]; switch (edit.type()) { // Create* ops case Edit::TOpCreateThebesLayer: { MOZ_LAYERS_LOG(("[ParentSide] CreateThebesLayer")); nsRefPtr<ThebesLayerComposite> layer = layer_manager()->CreateThebesLayerComposite(); AsLayerComposite(edit.get_OpCreateThebesLayer())->Bind(layer); break; } case Edit::TOpCreateContainerLayer: { MOZ_LAYERS_LOG(("[ParentSide] CreateContainerLayer")); nsRefPtr<ContainerLayer> layer = layer_manager()->CreateContainerLayerComposite(); AsLayerComposite(edit.get_OpCreateContainerLayer())->Bind(layer); break; } case Edit::TOpCreateImageLayer: { MOZ_LAYERS_LOG(("[ParentSide] CreateImageLayer")); nsRefPtr<ImageLayerComposite> layer = layer_manager()->CreateImageLayerComposite(); AsLayerComposite(edit.get_OpCreateImageLayer())->Bind(layer); break; } case Edit::TOpCreateColorLayer: { MOZ_LAYERS_LOG(("[ParentSide] CreateColorLayer")); nsRefPtr<ColorLayerComposite> layer = layer_manager()->CreateColorLayerComposite(); AsLayerComposite(edit.get_OpCreateColorLayer())->Bind(layer); break; } case Edit::TOpCreateCanvasLayer: { MOZ_LAYERS_LOG(("[ParentSide] CreateCanvasLayer")); nsRefPtr<CanvasLayerComposite> layer = layer_manager()->CreateCanvasLayerComposite(); AsLayerComposite(edit.get_OpCreateCanvasLayer())->Bind(layer); break; } case Edit::TOpCreateRefLayer: { MOZ_LAYERS_LOG(("[ParentSide] CreateRefLayer")); nsRefPtr<RefLayerComposite> layer = layer_manager()->CreateRefLayerComposite(); AsLayerComposite(edit.get_OpCreateRefLayer())->Bind(layer); break; } // Attributes case Edit::TOpSetLayerAttributes: { MOZ_LAYERS_LOG(("[ParentSide] SetLayerAttributes")); const OpSetLayerAttributes& osla = edit.get_OpSetLayerAttributes(); ShadowLayerParent* layerParent = AsLayerComposite(osla); Layer* layer = layerParent->AsLayer(); if (!layer) { return false; } const LayerAttributes& attrs = osla.attrs(); const CommonLayerAttributes& common = attrs.common(); layer->SetVisibleRegion(common.visibleRegion()); layer->SetEventRegions(common.eventRegions()); layer->SetContentFlags(common.contentFlags()); layer->SetOpacity(common.opacity()); layer->SetClipRect(common.useClipRect() ? &common.clipRect() : nullptr); layer->SetBaseTransform(common.transform().value()); layer->SetPostScale(common.postXScale(), common.postYScale()); layer->SetIsFixedPosition(common.isFixedPosition()); layer->SetFixedPositionAnchor(common.fixedPositionAnchor()); layer->SetFixedPositionMargins(common.fixedPositionMargin()); if (common.isStickyPosition()) { layer->SetStickyPositionData(common.stickyScrollContainerId(), common.stickyScrollRangeOuter(), common.stickyScrollRangeInner()); } layer->SetScrollbarData(common.scrollbarTargetContainerId(), static_cast<Layer::ScrollDirection>(common.scrollbarDirection())); if (PLayerParent* maskLayer = common.maskLayerParent()) { layer->SetMaskLayer(cast(maskLayer)->AsLayer()); } else { layer->SetMaskLayer(nullptr); } layer->SetAnimations(common.animations()); layer->SetInvalidRegion(common.invalidRegion()); typedef SpecificLayerAttributes Specific; const SpecificLayerAttributes& specific = attrs.specific(); switch (specific.type()) { case Specific::Tnull_t: break; case Specific::TThebesLayerAttributes: { MOZ_LAYERS_LOG(("[ParentSide] thebes layer")); ThebesLayerComposite* thebesLayer = layerParent->AsThebesLayerComposite(); if (!thebesLayer) { return false; } const ThebesLayerAttributes& attrs = specific.get_ThebesLayerAttributes(); thebesLayer->SetValidRegion(attrs.validRegion()); break; } case Specific::TContainerLayerAttributes: { MOZ_LAYERS_LOG(("[ParentSide] container layer")); ContainerLayerComposite* containerLayer = layerParent->AsContainerLayerComposite(); if (!containerLayer) { return false; } const ContainerLayerAttributes& attrs = specific.get_ContainerLayerAttributes(); containerLayer->SetFrameMetrics(attrs.metrics()); containerLayer->SetPreScale(attrs.preXScale(), attrs.preYScale()); containerLayer->SetInheritedScale(attrs.inheritedXScale(), attrs.inheritedYScale()); break; } case Specific::TColorLayerAttributes: { MOZ_LAYERS_LOG(("[ParentSide] color layer")); ColorLayerComposite* colorLayer = layerParent->AsColorLayerComposite(); if (!colorLayer) { return false; } colorLayer->SetColor(specific.get_ColorLayerAttributes().color().value()); colorLayer->SetBounds(specific.get_ColorLayerAttributes().bounds()); break; } case Specific::TCanvasLayerAttributes: { MOZ_LAYERS_LOG(("[ParentSide] canvas layer")); CanvasLayerComposite* canvasLayer = layerParent->AsCanvasLayerComposite(); if (!canvasLayer) { return false; } canvasLayer->SetFilter(specific.get_CanvasLayerAttributes().filter()); canvasLayer->SetBounds(specific.get_CanvasLayerAttributes().bounds()); break; } case Specific::TRefLayerAttributes: { MOZ_LAYERS_LOG(("[ParentSide] ref layer")); RefLayerComposite* refLayer = layerParent->AsRefLayerComposite(); if (!refLayer) { return false; } refLayer->SetReferentId(specific.get_RefLayerAttributes().id()); break; } case Specific::TImageLayerAttributes: { MOZ_LAYERS_LOG(("[ParentSide] image layer")); ImageLayerComposite* imageLayer = layerParent->AsImageLayerComposite(); if (!imageLayer) { return false; } const ImageLayerAttributes& attrs = specific.get_ImageLayerAttributes(); imageLayer->SetFilter(attrs.filter()); imageLayer->SetScaleToSize(attrs.scaleToSize(), attrs.scaleMode()); break; } default: NS_RUNTIMEABORT("not reached"); } break; } case Edit::TOpSetDiagnosticTypes: { mLayerManager->GetCompositor()->SetDiagnosticTypes( edit.get_OpSetDiagnosticTypes().diagnostics()); break; } // Tree ops case Edit::TOpSetRoot: { MOZ_LAYERS_LOG(("[ParentSide] SetRoot")); Layer* newRoot = AsLayerComposite(edit.get_OpSetRoot())->AsLayer(); if (newRoot->GetParent()) { return false; } mRoot = newRoot; break; } case Edit::TOpInsertAfter: { MOZ_LAYERS_LOG(("[ParentSide] InsertAfter")); const OpInsertAfter& oia = edit.get_OpInsertAfter(); Layer* child = ShadowChild(oia)->AsLayer(); if (!child) { return false; } ContainerLayerComposite* container = ShadowContainer(oia)->AsContainerLayerComposite(); if (!container || !container->InsertAfter(child, ShadowAfter(oia)->AsLayer())) { return false; } break; } case Edit::TOpPrependChild: { MOZ_LAYERS_LOG(("[ParentSide] PrependChild")); const OpPrependChild& oac = edit.get_OpPrependChild(); Layer* child = ShadowChild(oac)->AsLayer(); if (!child) { return false; } ContainerLayerComposite* container = ShadowContainer(oac)->AsContainerLayerComposite(); if (!container || !container->InsertAfter(child, nullptr)) { return false; } break; } case Edit::TOpRemoveChild: { MOZ_LAYERS_LOG(("[ParentSide] RemoveChild")); const OpRemoveChild& orc = edit.get_OpRemoveChild(); Layer* childLayer = ShadowChild(orc)->AsLayer(); if (!childLayer) { return false; } ContainerLayerComposite* container = ShadowContainer(orc)->AsContainerLayerComposite(); if (!container || !container->RemoveChild(childLayer)) { return false; } break; } case Edit::TOpRepositionChild: { MOZ_LAYERS_LOG(("[ParentSide] RepositionChild")); const OpRepositionChild& orc = edit.get_OpRepositionChild(); Layer* child = ShadowChild(orc)->AsLayer(); if (!child) { return false; } ContainerLayerComposite* container = ShadowContainer(orc)->AsContainerLayerComposite(); if (!container || !container->RepositionChild(child, ShadowAfter(orc)->AsLayer())) { return false; } break; } case Edit::TOpRaiseToTopChild: { MOZ_LAYERS_LOG(("[ParentSide] RaiseToTopChild")); const OpRaiseToTopChild& rtc = edit.get_OpRaiseToTopChild(); Layer* child = ShadowChild(rtc)->AsLayer(); if (!child) { return false; } ContainerLayerComposite* container = ShadowContainer(rtc)->AsContainerLayerComposite(); if (!container || !container->RepositionChild(child, nullptr)) { return false; } break; } case Edit::TCompositableOperation: { ReceiveCompositableUpdate(edit.get_CompositableOperation(), replyv); break; } case Edit::TOpAttachCompositable: { const OpAttachCompositable& op = edit.get_OpAttachCompositable(); if (!Attach(cast(op.layerParent()), cast(op.compositableParent()), false)) { return false; } cast(op.compositableParent())->SetCompositorID( mLayerManager->GetCompositor()->GetCompositorID()); break; } case Edit::TOpAttachAsyncCompositable: { const OpAttachAsyncCompositable& op = edit.get_OpAttachAsyncCompositable(); CompositableParent* compositableParent = CompositableMap::Get(op.containerID()); MOZ_ASSERT(compositableParent, "CompositableParent not found in the map"); if (!Attach(cast(op.layerParent()), compositableParent, true)) { return false; } compositableParent->SetCompositorID(mLayerManager->GetCompositor()->GetCompositorID()); break; } default: NS_RUNTIMEABORT("not reached"); } } { AutoResolveRefLayers resolve(mShadowLayersManager->GetCompositionManager()); layer_manager()->EndTransaction(nullptr, nullptr, LayerManager::END_NO_IMMEDIATE_REDRAW); } if (reply) { reply->SetCapacity(replyv.size()); if (replyv.size() > 0) { reply->AppendElements(&replyv.front(), replyv.size()); } } // Ensure that any pending operations involving back and front // buffers have completed, so that neither process stomps on the // other's buffer contents. LayerManagerComposite::PlatformSyncBeforeReplyUpdate(); mShadowLayersManager->ShadowLayersUpdated(this, targetConfig, isFirstPaint, scheduleComposite); #ifdef COMPOSITOR_PERFORMANCE_WARNING int compositeTime = (int)(mozilla::TimeStamp::Now() - updateStart).ToMilliseconds(); if (compositeTime > 15) { printf_stderr("Compositor: Layers update took %i ms (blocking gecko).\n", compositeTime); } #endif return true; }
virtual already_AddRefed<gfxASurface> CreateBuffer(ContentType, const nsIntRect&, uint32_t, gfxASurface**) { NS_RUNTIMEABORT("ThebesLayerComposite can't paint content"); return nullptr; }
void TextureClientShmemYCbCr::EnsureAllocated(gfx::IntSize aSize, gfxASurface::gfxContentType aType) { NS_RUNTIMEABORT("not enough arguments to do this (need both Y and CbCr sizes)"); }
bool ValidWriteAssert(bool ok) { if (gShutdownChecks == SCM_CRASH && !ok) { MOZ_CRASH(); } // We normally don't poison writes if gShutdownChecks is SCM_NOTHING, but // write poisoning can get more users in the future (profiling for example), // so make sure we behave correctly. if (gShutdownChecks == SCM_NOTHING || ok || !sProfileDirectory || !Telemetry::CanRecord()) { return ok; } // Write the stack and loaded libraries to a file. We can get here // concurrently from many writes, so we use multiple temporary files. std::vector<uintptr_t> rawStack; NS_StackWalk(RecordStackWalker, /* skipFrames */ 0, /* maxFrames */ 0, reinterpret_cast<void*>(&rawStack), 0, nullptr); Telemetry::ProcessedStack stack = Telemetry::GetStackAndModules(rawStack); nsPrintfCString nameAux("%s%s%s", sProfileDirectory, NS_SLASH, "Telemetry.LateWriteTmpXXXXXX"); char *name; nameAux.GetMutableData(&name); // We want the sha1 of the entire file, so please don't write to fd // directly; use sha1Stream. FILE *stream; #ifdef XP_WIN HANDLE hFile; do { // mkstemp isn't supported so keep trying until we get a file int result = _mktemp_s(name, strlen(name) + 1); hFile = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); } while (GetLastError() == ERROR_FILE_EXISTS); if (hFile == INVALID_HANDLE_VALUE) { NS_RUNTIMEABORT("Um, how did we get here?"); } // http://support.microsoft.com/kb/139640 int fd = _open_osfhandle((intptr_t)hFile, _O_APPEND); if (fd == -1) { NS_RUNTIMEABORT("Um, how did we get here?"); } stream = _fdopen(fd, "w"); #else int fd = mkstemp(name); stream = fdopen(fd, "w"); #endif SHA1Stream sha1Stream(stream); size_t numModules = stack.GetNumModules(); sha1Stream.Printf("%u\n", (unsigned)numModules); for (size_t i = 0; i < numModules; ++i) { Telemetry::ProcessedStack::Module module = stack.GetModule(i); sha1Stream.Printf("%s %s\n", module.mBreakpadId.c_str(), module.mName.c_str()); } size_t numFrames = stack.GetStackSize(); sha1Stream.Printf("%u\n", (unsigned)numFrames); for (size_t i = 0; i < numFrames; ++i) { const Telemetry::ProcessedStack::Frame &frame = stack.GetFrame(i); // NOTE: We write the offsets, while the atos tool expects a value with // the virtual address added. For example, running otool -l on the the firefox // binary shows // cmd LC_SEGMENT_64 // cmdsize 632 // segname __TEXT // vmaddr 0x0000000100000000 // so to print the line matching the offset 123 one has to run // atos -o firefox 0x100000123. sha1Stream.Printf("%d %x\n", frame.mModIndex, (unsigned)frame.mOffset); } SHA1Sum::Hash sha1; sha1Stream.Finish(sha1); // Note: These files should be deleted by telemetry once it reads them. If // there were no telemery runs by the time we shut down, we just add files // to the existing ones instead of replacing them. Given that each of these // files is a bug to be fixed, that is probably the right thing to do. // We append the sha1 of the contents to the file name. This provides a simple // client side deduplication. nsPrintfCString finalName("%s%s", sProfileDirectory, "/Telemetry.LateWriteFinal-"); for (int i = 0; i < 20; ++i) { finalName.AppendPrintf("%02x", sha1[i]); } PR_Delete(finalName.get()); PR_Rename(name, finalName.get()); return false; }
void ClientLayerManager::ForwardTransaction() { mPhase = PHASE_FORWARD; // forward this transaction's changeset to our LayerManagerComposite AutoInfallibleTArray<EditReply, 10> replies; if (HasShadowManager() && ShadowLayerForwarder::EndTransaction(&replies)) { for (nsTArray<EditReply>::size_type i = 0; i < replies.Length(); ++i) { const EditReply& reply = replies[i]; switch (reply.type()) { case EditReply::TOpContentBufferSwap: { MOZ_LAYERS_LOG(("[LayersForwarder] DoubleBufferSwap")); const OpContentBufferSwap& obs = reply.get_OpContentBufferSwap(); CompositableChild* compositableChild = static_cast<CompositableChild*>(obs.compositableChild()); ContentClientRemote* contentClient = static_cast<ContentClientRemote*>(compositableChild->GetCompositableClient()); MOZ_ASSERT(contentClient); contentClient->SwapBuffers(obs.frontUpdatedRegion()); break; } case EditReply::TOpTextureSwap: { MOZ_LAYERS_LOG(("[LayersForwarder] TextureSwap")); const OpTextureSwap& ots = reply.get_OpTextureSwap(); CompositableChild* compositableChild = static_cast<CompositableChild*>(ots.compositableChild()); MOZ_ASSERT(compositableChild); compositableChild->GetCompositableClient() ->SetDescriptorFromReply(ots.textureId(), ots.image()); break; } case EditReply::TReplyTextureRemoved: { // XXX - to manage reuse of gralloc buffers, we'll need to add some // glue code here to find the TextureClient and invoke a callback to // let the camera know that the gralloc buffer is not used anymore on // the compositor side and that it can reuse it. break; } default: NS_RUNTIMEABORT("not reached"); } } } else if (HasShadowManager()) { NS_WARNING("failed to forward Layers transaction"); } mPhase = PHASE_NONE; // this may result in Layers being deleted, which results in // PLayer::Send__delete__() and DeallocShmem() mKeepAlive.Clear(); }
void LayerManagerOGL::CreateFBOWithTexture(const nsIntRect& aRect, InitMode aInit, GLuint aCurrentFrameBuffer, GLuint *aFBO, GLuint *aTexture) { GLuint tex, fbo; mGLContext->fActiveTexture(LOCAL_GL_TEXTURE0); mGLContext->fGenTextures(1, &tex); mGLContext->fBindTexture(mFBOTextureTarget, tex); if (aInit == InitModeCopy) { // We're going to create an RGBA temporary fbo. But to // CopyTexImage() from the current framebuffer, the framebuffer's // format has to be compatible with the new texture's. So we // check the format of the framebuffer here and take a slow path // if it's incompatible. GLenum format = GetFrameBufferInternalFormat(gl(), aCurrentFrameBuffer, mWidget); if (AreFormatsCompatibleForCopyTexImage2D(format, LOCAL_GL_RGBA)) { mGLContext->fCopyTexImage2D(mFBOTextureTarget, 0, LOCAL_GL_RGBA, aRect.x, aRect.y, aRect.width, aRect.height, 0); } else { // Curses, incompatible formats. Take a slow path. // // XXX Technically CopyTexSubImage2D also has the requirement of // matching formats, but it doesn't seem to affect us in the // real world. mGLContext->fTexImage2D(mFBOTextureTarget, 0, LOCAL_GL_RGBA, aRect.width, aRect.height, 0, LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_BYTE, NULL); mGLContext->fCopyTexSubImage2D(mFBOTextureTarget, 0, // level 0, 0, // offset aRect.x, aRect.y, aRect.width, aRect.height); } } else { mGLContext->fTexImage2D(mFBOTextureTarget, 0, LOCAL_GL_RGBA, aRect.width, aRect.height, 0, LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_BYTE, NULL); } mGLContext->fTexParameteri(mFBOTextureTarget, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR); mGLContext->fTexParameteri(mFBOTextureTarget, LOCAL_GL_TEXTURE_MAG_FILTER, LOCAL_GL_LINEAR); mGLContext->fTexParameteri(mFBOTextureTarget, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE); mGLContext->fTexParameteri(mFBOTextureTarget, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE); mGLContext->fBindTexture(mFBOTextureTarget, 0); mGLContext->fGenFramebuffers(1, &fbo); mGLContext->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, fbo); mGLContext->fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER, LOCAL_GL_COLOR_ATTACHMENT0, mFBOTextureTarget, tex, 0); // Making this call to fCheckFramebufferStatus prevents a crash on // PowerVR. See bug 695246. GLenum result = mGLContext->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER); if (result != LOCAL_GL_FRAMEBUFFER_COMPLETE) { nsCAutoString msg; msg.Append("Framebuffer not complete -- error 0x"); msg.AppendInt(result, 16); msg.Append(", mFBOTextureTarget 0x"); msg.AppendInt(mFBOTextureTarget, 16); msg.Append(", aRect.width "); msg.AppendInt(aRect.width); msg.Append(", aRect.height "); msg.AppendInt(aRect.height); NS_RUNTIMEABORT(msg.get()); } SetupPipeline(aRect.width, aRect.height, DontApplyWorldTransform); mGLContext->fScissor(0, 0, aRect.width, aRect.height); if (aInit == InitModeClear) { mGLContext->fClearColor(0.0, 0.0, 0.0, 0.0); mGLContext->fClear(LOCAL_GL_COLOR_BUFFER_BIT); } *aFBO = fbo; *aTexture = tex; }
// get the text that we enclose and setup our nsMathMLChar void nsMathMLmoFrame::ProcessTextData() { mFlags = 0; nsAutoString data; if (!nsContentUtils::GetNodeTextContent(mContent, false, data)) { NS_RUNTIMEABORT("OOM"); } data.CompressWhitespace(); int32_t length = data.Length(); char16_t ch = (length == 0) ? char16_t('\0') : data[0]; if ((length == 1) && (ch == kApplyFunction || ch == kInvisibleSeparator || ch == kInvisiblePlus || ch == kInvisibleTimes)) { mFlags |= NS_MATHML_OPERATOR_INVISIBLE; } // don't bother doing anything special if we don't have a single child nsPresContext* presContext = PresContext(); if (mFrames.GetLength() != 1) { data.Truncate(); // empty data to reset the char mMathMLChar.SetData(presContext, data); ResolveMathMLCharStyle(presContext, mContent, mStyleContext, &mMathMLChar, false); return; } // special... in math mode, the usual minus sign '-' looks too short, so // what we do here is to remap <mo>-</mo> to the official Unicode minus // sign (U+2212) which looks much better. For background on this, see // http://groups.google.com/groups?hl=en&th=66488daf1ade7635&rnum=1 if (1 == length && ch == '-') { ch = 0x2212; data = ch; } // cache the special bits: mutable, accent, movablelimits, centered. // we need to do this in anticipation of other requirements, and these // bits don't change. Do not reset these bits unless the text gets changed. // lookup all the forms under which the operator is listed in the dictionary, // and record whether the operator has accent="true" or movablelimits="true" nsOperatorFlags flags[4]; float lspace[4], rspace[4]; nsMathMLOperators::LookupOperators(data, flags, lspace, rspace); nsOperatorFlags allFlags = flags[NS_MATHML_OPERATOR_FORM_INFIX] | flags[NS_MATHML_OPERATOR_FORM_POSTFIX] | flags[NS_MATHML_OPERATOR_FORM_PREFIX]; mFlags |= allFlags & NS_MATHML_OPERATOR_ACCENT; mFlags |= allFlags & NS_MATHML_OPERATOR_MOVABLELIMITS; // see if this is an operator that should be centered to cater for // fonts that are not math-aware if (1 == length) { if ((ch == '+') || (ch == '=') || (ch == '*') || (ch == 0x2212) || // − (ch == 0x2264) || // ≤ (ch == 0x2265) || // ≥ (ch == 0x00D7)) { // × mFlags |= NS_MATHML_OPERATOR_CENTERED; } } // cache the operator mMathMLChar.SetData(presContext, data); // cache the native direction -- beware of bug 133429... // mEmbellishData.direction must always retain our native direction, whereas // mMathMLChar.GetStretchDirection() may change later, when Stretch() is called mEmbellishData.direction = mMathMLChar.GetStretchDirection(); bool isMutable = NS_MATHML_OPERATOR_IS_LARGEOP(allFlags) || (mEmbellishData.direction != NS_STRETCH_DIRECTION_UNSUPPORTED); if (isMutable) mFlags |= NS_MATHML_OPERATOR_MUTABLE; ResolveMathMLCharStyle(presContext, mContent, mStyleContext, &mMathMLChar, isMutable); }
bool LayerTransactionParent::RecvUpdate(const InfallibleTArray<Edit>& cset, const TargetConfig& targetConfig, const bool& isFirstPaint, InfallibleTArray<EditReply>* reply) { #ifdef COMPOSITOR_PERFORMANCE_WARNING TimeStamp updateStart = TimeStamp::Now(); #endif MOZ_LAYERS_LOG(("[ParentSide] received txn with %d edits", cset.Length())); if (mDestroyed || !layer_manager() || layer_manager()->IsDestroyed()) { return true; } EditReplyVector replyv; layer_manager()->BeginTransactionWithTarget(NULL); for (EditArray::index_type i = 0; i < cset.Length(); ++i) { const Edit& edit = cset[i]; switch (edit.type()) { // Create* ops case Edit::TOpCreateThebesLayer: { MOZ_LAYERS_LOG(("[ParentSide] CreateThebesLayer")); nsRefPtr<ThebesLayerComposite> layer = layer_manager()->CreateThebesLayerComposite(); AsLayerComposite(edit.get_OpCreateThebesLayer())->Bind(layer); break; } case Edit::TOpCreateContainerLayer: { MOZ_LAYERS_LOG(("[ParentSide] CreateContainerLayer")); nsRefPtr<ContainerLayer> layer = layer_manager()->CreateContainerLayerComposite(); AsLayerComposite(edit.get_OpCreateContainerLayer())->Bind(layer); break; } case Edit::TOpCreateImageLayer: { MOZ_LAYERS_LOG(("[ParentSide] CreateImageLayer")); nsRefPtr<ImageLayerComposite> layer = layer_manager()->CreateImageLayerComposite(); AsLayerComposite(edit.get_OpCreateImageLayer())->Bind(layer); break; } case Edit::TOpCreateColorLayer: { MOZ_LAYERS_LOG(("[ParentSide] CreateColorLayer")); nsRefPtr<ColorLayerComposite> layer = layer_manager()->CreateColorLayerComposite(); AsLayerComposite(edit.get_OpCreateColorLayer())->Bind(layer); break; } case Edit::TOpCreateCanvasLayer: { MOZ_LAYERS_LOG(("[ParentSide] CreateCanvasLayer")); nsRefPtr<CanvasLayerComposite> layer = layer_manager()->CreateCanvasLayerComposite(); AsLayerComposite(edit.get_OpCreateCanvasLayer())->Bind(layer); break; } case Edit::TOpCreateRefLayer: { MOZ_LAYERS_LOG(("[ParentSide] CreateRefLayer")); nsRefPtr<RefLayerComposite> layer = layer_manager()->CreateRefLayerComposite(); AsLayerComposite(edit.get_OpCreateRefLayer())->Bind(layer); break; } // Attributes case Edit::TOpSetLayerAttributes: { MOZ_LAYERS_LOG(("[ParentSide] SetLayerAttributes")); const OpSetLayerAttributes& osla = edit.get_OpSetLayerAttributes(); Layer* layer = AsLayerComposite(osla)->AsLayer(); const LayerAttributes& attrs = osla.attrs(); const CommonLayerAttributes& common = attrs.common(); layer->SetVisibleRegion(common.visibleRegion()); layer->SetContentFlags(common.contentFlags()); layer->SetOpacity(common.opacity()); layer->SetClipRect(common.useClipRect() ? &common.clipRect() : NULL); layer->SetBaseTransform(common.transform().value()); layer->SetPostScale(common.postXScale(), common.postYScale()); layer->SetIsFixedPosition(common.isFixedPosition()); layer->SetFixedPositionAnchor(common.fixedPositionAnchor()); layer->SetFixedPositionMargins(common.fixedPositionMargin()); if (PLayerParent* maskLayer = common.maskLayerParent()) { layer->SetMaskLayer(cast(maskLayer)->AsLayer()); } else { layer->SetMaskLayer(NULL); } layer->SetAnimations(common.animations()); typedef SpecificLayerAttributes Specific; const SpecificLayerAttributes& specific = attrs.specific(); switch (specific.type()) { case Specific::Tnull_t: break; case Specific::TThebesLayerAttributes: { MOZ_LAYERS_LOG(("[ParentSide] thebes layer")); ThebesLayerComposite* thebesLayer = static_cast<ThebesLayerComposite*>(layer); const ThebesLayerAttributes& attrs = specific.get_ThebesLayerAttributes(); thebesLayer->SetValidRegion(attrs.validRegion()); break; } case Specific::TContainerLayerAttributes: { MOZ_LAYERS_LOG(("[ParentSide] container layer")); ContainerLayer* containerLayer = static_cast<ContainerLayer*>(layer); const ContainerLayerAttributes& attrs = specific.get_ContainerLayerAttributes(); containerLayer->SetFrameMetrics(attrs.metrics()); containerLayer->SetPreScale(attrs.preXScale(), attrs.preYScale()); containerLayer->SetInheritedScale(attrs.inheritedXScale(), attrs.inheritedYScale()); break; } case Specific::TColorLayerAttributes: MOZ_LAYERS_LOG(("[ParentSide] color layer")); static_cast<ColorLayer*>(layer)->SetColor( specific.get_ColorLayerAttributes().color().value()); break; case Specific::TCanvasLayerAttributes: MOZ_LAYERS_LOG(("[ParentSide] canvas layer")); static_cast<CanvasLayer*>(layer)->SetFilter( specific.get_CanvasLayerAttributes().filter()); static_cast<CanvasLayerComposite*>(layer)->SetBounds( specific.get_CanvasLayerAttributes().bounds()); break; case Specific::TRefLayerAttributes: MOZ_LAYERS_LOG(("[ParentSide] ref layer")); static_cast<RefLayer*>(layer)->SetReferentId( specific.get_RefLayerAttributes().id()); break; case Specific::TImageLayerAttributes: { MOZ_LAYERS_LOG(("[ParentSide] image layer")); ImageLayer* imageLayer = static_cast<ImageLayer*>(layer); const ImageLayerAttributes& attrs = specific.get_ImageLayerAttributes(); imageLayer->SetFilter(attrs.filter()); imageLayer->SetScaleToSize(attrs.scaleToSize(), attrs.scaleMode()); break; } default: NS_RUNTIMEABORT("not reached"); } break; } case Edit::TOpSetColoredBorders: { if (edit.get_OpSetColoredBorders().enabled()) { mLayerManager->GetCompositor()->EnableColoredBorders(); } else { mLayerManager->GetCompositor()->DisableColoredBorders(); } break; } // Tree ops case Edit::TOpSetRoot: { MOZ_LAYERS_LOG(("[ParentSide] SetRoot")); mRoot = AsLayerComposite(edit.get_OpSetRoot())->AsContainer(); break; } case Edit::TOpInsertAfter: { MOZ_LAYERS_LOG(("[ParentSide] InsertAfter")); const OpInsertAfter& oia = edit.get_OpInsertAfter(); ShadowContainer(oia)->AsContainer()->InsertAfter( ShadowChild(oia)->AsLayer(), ShadowAfter(oia)->AsLayer()); break; } case Edit::TOpAppendChild: { MOZ_LAYERS_LOG(("[ParentSide] AppendChild")); const OpAppendChild& oac = edit.get_OpAppendChild(); ShadowContainer(oac)->AsContainer()->InsertAfter( ShadowChild(oac)->AsLayer(), NULL); break; } case Edit::TOpRemoveChild: { MOZ_LAYERS_LOG(("[ParentSide] RemoveChild")); const OpRemoveChild& orc = edit.get_OpRemoveChild(); Layer* childLayer = ShadowChild(orc)->AsLayer(); ShadowContainer(orc)->AsContainer()->RemoveChild(childLayer); break; } case Edit::TOpRepositionChild: { MOZ_LAYERS_LOG(("[ParentSide] RepositionChild")); const OpRepositionChild& orc = edit.get_OpRepositionChild(); ShadowContainer(orc)->AsContainer()->RepositionChild( ShadowChild(orc)->AsLayer(), ShadowAfter(orc)->AsLayer()); break; } case Edit::TOpRaiseToTopChild: { MOZ_LAYERS_LOG(("[ParentSide] RaiseToTopChild")); const OpRaiseToTopChild& rtc = edit.get_OpRaiseToTopChild(); ShadowContainer(rtc)->AsContainer()->RepositionChild( ShadowChild(rtc)->AsLayer(), NULL); break; } case Edit::TCompositableOperation: { ReceiveCompositableUpdate(edit.get_CompositableOperation(), replyv); break; } case Edit::TOpAttachCompositable: { const OpAttachCompositable& op = edit.get_OpAttachCompositable(); Attach(cast(op.layerParent()), cast(op.compositableParent())); break; } case Edit::TOpAttachAsyncCompositable: { const OpAttachAsyncCompositable& op = edit.get_OpAttachAsyncCompositable(); CompositableParent* compositableParent = CompositableMap::Get(op.containerID()); MOZ_ASSERT(compositableParent, "CompositableParent not found in the map"); Attach(cast(op.layerParent()), compositableParent); compositableParent->SetCompositorID(mLayerManager->GetCompositor()->GetCompositorID()); break; } default: NS_RUNTIMEABORT("not reached"); } } layer_manager()->EndTransaction(NULL, NULL, LayerManager::END_NO_IMMEDIATE_REDRAW); if (reply) { reply->SetCapacity(replyv.size()); if (replyv.size() > 0) { reply->AppendElements(&replyv.front(), replyv.size()); } } // Ensure that any pending operations involving back and front // buffers have completed, so that neither process stomps on the // other's buffer contents. LayerManagerComposite::PlatformSyncBeforeReplyUpdate(); mShadowLayersManager->ShadowLayersUpdated(this, targetConfig, isFirstPaint); #ifdef COMPOSITOR_PERFORMANCE_WARNING int compositeTime = (int)(mozilla::TimeStamp::Now() - updateStart).ToMilliseconds(); if (compositeTime > 15) { printf_stderr("Compositor: Layers update took %i ms (blocking gecko).\n", compositeTime); } #endif return true; }
void BasicShadowableCanvasLayer::Paint(gfxContext* aContext, Layer* aMaskLayer) { if (!HasShadow()) { BasicCanvasLayer::Paint(aContext, aMaskLayer); return; } if (!IsDirty()) return; if (mGLContext && !mForceReadback && BasicManager()->GetParentBackendType() == mozilla::layers::LAYERS_OPENGL) { TextureImage::TextureShareType flags; // if process type is default, then it is single-process (non-e10s) if (XRE_GetProcessType() == GeckoProcessType_Default) flags = TextureImage::ThreadShared; else flags = TextureImage::ProcessShared; SharedTextureHandle handle = GetSharedBackBufferHandle(); if (!handle) { handle = mGLContext->CreateSharedHandle(flags); if (handle) { mBackBuffer = SharedTextureDescriptor(flags, handle, mBounds.Size(), false); } } if (handle) { mGLContext->MakeCurrent(); mGLContext->UpdateSharedHandle(flags, handle); // call Painted() to reset our dirty 'bit' Painted(); FireDidTransactionCallback(); BasicManager()->PaintedCanvas(BasicManager()->Hold(this), mNeedsYFlip, mBackBuffer); // Move SharedTextureHandle ownership to ShadowLayer mBackBuffer = SurfaceDescriptor(); return; } } bool isOpaque = (GetContentFlags() & CONTENT_OPAQUE); if (!IsSurfaceDescriptorValid(mBackBuffer) || isOpaque != mBufferIsOpaque) { DestroyBackBuffer(); mBufferIsOpaque = isOpaque; gfxIntSize size(mBounds.width, mBounds.height); gfxASurface::gfxContentType type = isOpaque ? gfxASurface::CONTENT_COLOR : gfxASurface::CONTENT_COLOR_ALPHA; if (!BasicManager()->AllocBuffer(size, type, &mBackBuffer)) { NS_RUNTIMEABORT("creating CanvasLayer back buffer failed!"); } } AutoOpenSurface autoBackSurface(OPEN_READ_WRITE, mBackBuffer); if (aMaskLayer) { static_cast<BasicImplData*>(aMaskLayer->ImplData()) ->Paint(aContext, nullptr); } UpdateSurface(autoBackSurface.Get(), nullptr); FireDidTransactionCallback(); BasicManager()->PaintedCanvas(BasicManager()->Hold(this), mNeedsYFlip, mBackBuffer); }
/* See https://bugzilla.gnome.org/show_bug.cgi?id=629608#c8 * * GDK implements X11 error traps to ignore X11 errors. * Unfortunatelly We don't know which X11 events can be ignored * so we have to utilize the Gdk error handler to avoid * false alarms in Gtk3. */ static void GdkErrorHandler(const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data) { if (strstr(message, "X Window System error")) { XErrorEvent event; nsDependentCString buffer(message); char *endptr; /* Parse Gdk X Window error message which has this format: * (Details: serial XXXX error_code XXXX request_code XXXX (XXXX) minor_code XXXX) */ NS_NAMED_LITERAL_CSTRING(serialString, "(Details: serial "); int32_t start = buffer.Find(serialString); if (start == kNotFound) NS_RUNTIMEABORT(message); start += serialString.Length(); errno = 0; event.serial = strtol(buffer.BeginReading() + start, &endptr, 10); if (errno) NS_RUNTIMEABORT(message); NS_NAMED_LITERAL_CSTRING(errorCodeString, " error_code "); if (!StringBeginsWith(Substring(endptr, buffer.EndReading()), errorCodeString)) NS_RUNTIMEABORT(message); errno = 0; event.error_code = strtol(endptr + errorCodeString.Length(), &endptr, 10); if (errno) NS_RUNTIMEABORT(message); NS_NAMED_LITERAL_CSTRING(requestCodeString, " request_code "); if (!StringBeginsWith(Substring(endptr, buffer.EndReading()), requestCodeString)) NS_RUNTIMEABORT(message); errno = 0; event.request_code = strtol(endptr + requestCodeString.Length(), &endptr, 10); if (errno) NS_RUNTIMEABORT(message); NS_NAMED_LITERAL_CSTRING(minorCodeString, " minor_code "); start = buffer.Find(minorCodeString, endptr - buffer.BeginReading()); if (!start) NS_RUNTIMEABORT(message); errno = 0; event.minor_code = strtol(buffer.BeginReading() + start + minorCodeString.Length(), nullptr, 10); if (errno) NS_RUNTIMEABORT(message); event.display = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); // Gdk does not provide resource ID event.resourceid = 0; X11Error(event.display, &event); } else { g_log_default_handler(log_domain, log_level, message, user_data); NS_RUNTIMEABORT(message); } }
void BasicShadowCanvasLayer::Initialize(const Data& aData) { NS_RUNTIMEABORT("Incompatibe surface type"); }
void BasicCompositor::DrawQuad(const gfx::Rect& aRect, const gfx::Rect& aClipRect, const EffectChain &aEffectChain, gfx::Float aOpacity, const gfx::Matrix4x4 &aTransform) { RefPtr<DrawTarget> buffer = mRenderTarget->mDrawTarget; // For 2D drawing, |dest| and |buffer| are the same surface. For 3D drawing, // |dest| is a temporary surface. RefPtr<DrawTarget> dest = buffer; buffer->PushClipRect(aClipRect); AutoRestoreTransform autoRestoreTransform(dest); Matrix newTransform; Rect transformBounds; gfx3DMatrix new3DTransform; IntPoint offset = mRenderTarget->GetOrigin(); if (aTransform.Is2D()) { newTransform = aTransform.As2D(); } else { // Create a temporary surface for the transform. dest = gfxPlatform::GetPlatform()->CreateOffscreenContentDrawTarget(RoundOut(aRect).Size(), SurfaceFormat::B8G8R8A8); if (!dest) { return; } dest->SetTransform(Matrix::Translation(-aRect.x, -aRect.y)); // Get the bounds post-transform. new3DTransform = To3DMatrix(aTransform); gfxRect bounds = new3DTransform.TransformBounds(ThebesRect(aRect)); bounds.IntersectRect(bounds, gfxRect(offset.x, offset.y, buffer->GetSize().width, buffer->GetSize().height)); transformBounds = ToRect(bounds); transformBounds.RoundOut(); // Propagate the coordinate offset to our 2D draw target. newTransform = Matrix::Translation(transformBounds.x, transformBounds.y); // When we apply the 3D transformation, we do it against a temporary // surface, so undo the coordinate offset. new3DTransform = gfx3DMatrix::Translation(aRect.x, aRect.y, 0) * new3DTransform; } newTransform.PostTranslate(-offset.x, -offset.y); buffer->SetTransform(newTransform); RefPtr<SourceSurface> sourceMask; Matrix maskTransform; if (aEffectChain.mSecondaryEffects[EffectTypes::MASK]) { EffectMask *effectMask = static_cast<EffectMask*>(aEffectChain.mSecondaryEffects[EffectTypes::MASK].get()); sourceMask = effectMask->mMaskTexture->AsSourceBasic()->GetSurface(dest); MOZ_ASSERT(effectMask->mMaskTransform.Is2D(), "How did we end up with a 3D transform here?!"); MOZ_ASSERT(!effectMask->mIs3D); maskTransform = effectMask->mMaskTransform.As2D(); maskTransform.PreTranslate(-offset.x, -offset.y); } switch (aEffectChain.mPrimaryEffect->mType) { case EffectTypes::SOLID_COLOR: { EffectSolidColor* effectSolidColor = static_cast<EffectSolidColor*>(aEffectChain.mPrimaryEffect.get()); FillRectWithMask(dest, aRect, effectSolidColor->mColor, DrawOptions(aOpacity), sourceMask, &maskTransform); break; } case EffectTypes::RGB: { TexturedEffect* texturedEffect = static_cast<TexturedEffect*>(aEffectChain.mPrimaryEffect.get()); TextureSourceBasic* source = texturedEffect->mTexture->AsSourceBasic(); if (texturedEffect->mPremultiplied) { DrawSurfaceWithTextureCoords(dest, aRect, source->GetSurface(dest), texturedEffect->mTextureCoords, texturedEffect->mFilter, aOpacity, sourceMask, &maskTransform); } else { RefPtr<DataSourceSurface> srcData = source->GetSurface(dest)->GetDataSurface(); // Yes, we re-create the premultiplied data every time. // This might be better with a cache, eventually. RefPtr<DataSourceSurface> premultData = gfxUtils::CreatePremultipliedDataSurface(srcData); DrawSurfaceWithTextureCoords(dest, aRect, premultData, texturedEffect->mTextureCoords, texturedEffect->mFilter, aOpacity, sourceMask, &maskTransform); } break; } case EffectTypes::YCBCR: { NS_RUNTIMEABORT("Can't (easily) support component alpha with BasicCompositor!"); break; } case EffectTypes::RENDER_TARGET: { EffectRenderTarget* effectRenderTarget = static_cast<EffectRenderTarget*>(aEffectChain.mPrimaryEffect.get()); RefPtr<BasicCompositingRenderTarget> surface = static_cast<BasicCompositingRenderTarget*>(effectRenderTarget->mRenderTarget.get()); RefPtr<SourceSurface> sourceSurf = surface->mDrawTarget->Snapshot(); DrawSurfaceWithTextureCoords(dest, aRect, sourceSurf, effectRenderTarget->mTextureCoords, effectRenderTarget->mFilter, aOpacity, sourceMask, &maskTransform); break; } case EffectTypes::COMPONENT_ALPHA: { NS_RUNTIMEABORT("Can't (easily) support component alpha with BasicCompositor!"); break; } default: { NS_RUNTIMEABORT("Invalid effect type!"); break; } } if (!aTransform.Is2D()) { dest->Flush(); RefPtr<SourceSurface> snapshot = dest->Snapshot(); RefPtr<DataSourceSurface> source = snapshot->GetDataSurface(); RefPtr<DataSourceSurface> temp = Factory::CreateDataSourceSurface(RoundOut(transformBounds).Size(), SurfaceFormat::B8G8R8A8, true); if (NS_WARN_IF(!temp)) { return; } SkiaTransform(temp, source, new3DTransform, transformBounds.TopLeft()); transformBounds.MoveTo(0, 0); buffer->DrawSurface(temp, transformBounds, transformBounds); } buffer->PopClip(); }
void LogicError(const char* aMsg) { NS_RUNTIMEABORT(aMsg); }
already_AddRefed<DrawTarget> LayerManagerComposite::CreateOptimalMaskDrawTarget(const IntSize &aSize) { NS_RUNTIMEABORT("Should only be called on the drawing side"); return nullptr; }
void ActorIdReadError(const char* aActorDescription) { nsPrintfCString message("Error deserializing id for %s", aActorDescription); NS_RUNTIMEABORT(message.get()); }
void ClientLayerManager::ForwardTransaction(bool aScheduleComposite) { TimeStamp start = TimeStamp::Now(); if (mForwarder->GetSyncObject()) { mForwarder->GetSyncObject()->FinalizeFrame(); } mPhase = PHASE_FORWARD; mLatestTransactionId = mTransactionIdAllocator->GetTransactionId(); TimeStamp transactionStart; if (!mTransactionIdAllocator->GetTransactionStart().IsNull()) { transactionStart = mTransactionIdAllocator->GetTransactionStart(); } else { transactionStart = mTransactionStart; } // forward this transaction's changeset to our LayerManagerComposite bool sent; AutoInfallibleTArray<EditReply, 10> replies; if (mForwarder->EndTransaction(&replies, mRegionToClear, mLatestTransactionId, aScheduleComposite, mPaintSequenceNumber, mIsRepeatTransaction, transactionStart, &sent)) { for (nsTArray<EditReply>::size_type i = 0; i < replies.Length(); ++i) { const EditReply& reply = replies[i]; switch (reply.type()) { case EditReply::TOpContentBufferSwap: { MOZ_LAYERS_LOG(("[LayersForwarder] DoubleBufferSwap")); const OpContentBufferSwap& obs = reply.get_OpContentBufferSwap(); CompositableClient* compositable = CompositableClient::FromIPDLActor(obs.compositableChild()); ContentClientRemote* contentClient = static_cast<ContentClientRemote*>(compositable); MOZ_ASSERT(contentClient); contentClient->SwapBuffers(obs.frontUpdatedRegion()); break; } default: NS_RUNTIMEABORT("not reached"); } } if (sent) { mNeedsComposite = false; } } else if (HasShadowManager()) { NS_WARNING("failed to forward Layers transaction"); } if (!sent) { // Clear the transaction id so that it doesn't get returned // unless we forwarded to somewhere that doesn't actually // have a compositor. mTransactionIdAllocator->RevokeTransactionId(mLatestTransactionId); } mForwarder->RemoveTexturesIfNecessary(); mForwarder->SendPendingAsyncMessges(); mPhase = PHASE_NONE; // this may result in Layers being deleted, which results in // PLayer::Send__delete__() and DeallocShmem() mKeepAlive.Clear(); TabChild* window = mWidget->GetOwningTabChild(); if (window) { TimeStamp end = TimeStamp::Now(); window->DidRequestComposite(start, end); } }
void UnionTypeReadError(const char* aUnionName) { nsPrintfCString message("error deserializing type of union %s", aUnionName); NS_RUNTIMEABORT(message.get()); }
bool ShadowLayersParent::RecvUpdate(const InfallibleTArray<Edit>& cset, InfallibleTArray<EditReply>* reply) { MOZ_LAYERS_LOG(("[ParentSide] recieved txn with %d edits", cset.Length())); if (mDestroyed || layer_manager()->IsDestroyed()) { return true; } EditReplyVector replyv; layer_manager()->BeginTransactionWithTarget(NULL); for (EditArray::index_type i = 0; i < cset.Length(); ++i) { const Edit& edit = cset[i]; switch (edit.type()) { // Create* ops case Edit::TOpCreateThebesLayer: { MOZ_LAYERS_LOG(("[ParentSide] CreateThebesLayer")); nsRefPtr<ShadowThebesLayer> layer = layer_manager()->CreateShadowThebesLayer(); layer->SetAllocator(this); AsShadowLayer(edit.get_OpCreateThebesLayer())->Bind(layer); break; } case Edit::TOpCreateContainerLayer: { MOZ_LAYERS_LOG(("[ParentSide] CreateContainerLayer")); nsRefPtr<ContainerLayer> layer = layer_manager()->CreateShadowContainerLayer(); AsShadowLayer(edit.get_OpCreateContainerLayer())->Bind(layer); break; } case Edit::TOpCreateImageLayer: { MOZ_LAYERS_LOG(("[ParentSide] CreateImageLayer")); nsRefPtr<ShadowImageLayer> layer = layer_manager()->CreateShadowImageLayer(); layer->SetAllocator(this); AsShadowLayer(edit.get_OpCreateImageLayer())->Bind(layer); break; } case Edit::TOpCreateColorLayer: { MOZ_LAYERS_LOG(("[ParentSide] CreateColorLayer")); nsRefPtr<ShadowColorLayer> layer = layer_manager()->CreateShadowColorLayer(); AsShadowLayer(edit.get_OpCreateColorLayer())->Bind(layer); break; } case Edit::TOpCreateCanvasLayer: { MOZ_LAYERS_LOG(("[ParentSide] CreateCanvasLayer")); nsRefPtr<ShadowCanvasLayer> layer = layer_manager()->CreateShadowCanvasLayer(); layer->SetAllocator(this); AsShadowLayer(edit.get_OpCreateCanvasLayer())->Bind(layer); break; } case Edit::TOpCreateThebesBuffer: { MOZ_LAYERS_LOG(("[ParentSide] CreateThebesBuffer")); const OpCreateThebesBuffer& otb = edit.get_OpCreateThebesBuffer(); ShadowThebesLayer* thebes = static_cast<ShadowThebesLayer*>( AsShadowLayer(otb)->AsLayer()); thebes->SetFrontBuffer(otb.initialFront(), otb.frontValidRegion(), otb.xResolution(), otb.yResolution()); break; } case Edit::TOpCreateCanvasBuffer: { MOZ_LAYERS_LOG(("[ParentSide] CreateCanvasBuffer")); const OpCreateCanvasBuffer& ocb = edit.get_OpCreateCanvasBuffer(); ShadowCanvasLayer* canvas = static_cast<ShadowCanvasLayer*>( AsShadowLayer(ocb)->AsLayer()); canvas->Init(ocb.initialFront(), ocb.size()); break; } case Edit::TOpCreateImageBuffer: { MOZ_LAYERS_LOG(("[ParentSide] CreateImageBuffer")); const OpCreateImageBuffer ocb = edit.get_OpCreateImageBuffer(); ShadowImageLayer* image = static_cast<ShadowImageLayer*>( AsShadowLayer(ocb)->AsLayer()); image->Init(ocb.initialFront(), ocb.size()); break; } case Edit::TOpDestroyThebesFrontBuffer: { MOZ_LAYERS_LOG(("[ParentSide] DestroyThebesFrontBuffer")); const OpDestroyThebesFrontBuffer& odfb = edit.get_OpDestroyThebesFrontBuffer(); ShadowThebesLayer* thebes = static_cast<ShadowThebesLayer*>( AsShadowLayer(odfb)->AsLayer()); thebes->DestroyFrontBuffer(); break; } case Edit::TOpDestroyCanvasFrontBuffer: { MOZ_LAYERS_LOG(("[ParentSide] DestroyCanvasFrontBuffer")); const OpDestroyCanvasFrontBuffer& odfb = edit.get_OpDestroyCanvasFrontBuffer(); ShadowCanvasLayer* canvas = static_cast<ShadowCanvasLayer*>( AsShadowLayer(odfb)->AsLayer()); canvas->DestroyFrontBuffer(); break; } case Edit::TOpDestroyImageFrontBuffer: { MOZ_LAYERS_LOG(("[ParentSide] DestroyImageFrontBuffer")); const OpDestroyImageFrontBuffer& odfb = edit.get_OpDestroyImageFrontBuffer(); ShadowImageLayer* image = static_cast<ShadowImageLayer*>( AsShadowLayer(odfb)->AsLayer()); image->DestroyFrontBuffer(); break; } // Attributes case Edit::TOpSetLayerAttributes: { MOZ_LAYERS_LOG(("[ParentSide] SetLayerAttributes")); const OpSetLayerAttributes& osla = edit.get_OpSetLayerAttributes(); Layer* layer = AsShadowLayer(osla)->AsLayer(); const LayerAttributes& attrs = osla.attrs(); const CommonLayerAttributes& common = attrs.common(); layer->SetVisibleRegion(common.visibleRegion()); layer->SetContentFlags(common.contentFlags()); layer->SetOpacity(common.opacity()); layer->SetClipRect(common.useClipRect() ? &common.clipRect() : NULL); layer->SetTransform(common.transform()); layer->SetTileSourceRect(common.useTileSourceRect() ? &common.tileSourceRect() : NULL); layer->SetIsFixedPosition(common.isFixedPosition()); typedef SpecificLayerAttributes Specific; const SpecificLayerAttributes& specific = attrs.specific(); switch (specific.type()) { case Specific::Tnull_t: break; case Specific::TThebesLayerAttributes: { MOZ_LAYERS_LOG(("[ParentSide] thebes layer")); ShadowThebesLayer* thebesLayer = static_cast<ShadowThebesLayer*>(layer); const ThebesLayerAttributes& attrs = specific.get_ThebesLayerAttributes(); thebesLayer->SetValidRegion(attrs.validRegion()); thebesLayer->SetResolution(attrs.xResolution(), attrs.yResolution()); break; } case Specific::TContainerLayerAttributes: MOZ_LAYERS_LOG(("[ParentSide] container layer")); static_cast<ContainerLayer*>(layer)->SetFrameMetrics( specific.get_ContainerLayerAttributes().metrics()); break; case Specific::TColorLayerAttributes: MOZ_LAYERS_LOG(("[ParentSide] color layer")); static_cast<ColorLayer*>(layer)->SetColor( specific.get_ColorLayerAttributes().color()); break; case Specific::TCanvasLayerAttributes: MOZ_LAYERS_LOG(("[ParentSide] canvas layer")); static_cast<CanvasLayer*>(layer)->SetFilter( specific.get_CanvasLayerAttributes().filter()); break; case Specific::TImageLayerAttributes: MOZ_LAYERS_LOG(("[ParentSide] image layer")); static_cast<ImageLayer*>(layer)->SetFilter( specific.get_ImageLayerAttributes().filter()); break; default: NS_RUNTIMEABORT("not reached"); } break; } // Tree ops case Edit::TOpSetRoot: { MOZ_LAYERS_LOG(("[ParentSide] SetRoot")); mRoot = AsShadowLayer(edit.get_OpSetRoot())->AsContainer(); break; } case Edit::TOpInsertAfter: { MOZ_LAYERS_LOG(("[ParentSide] InsertAfter")); const OpInsertAfter& oia = edit.get_OpInsertAfter(); ShadowContainer(oia)->AsContainer()->InsertAfter( ShadowChild(oia)->AsLayer(), ShadowAfter(oia)->AsLayer()); break; } case Edit::TOpAppendChild: { MOZ_LAYERS_LOG(("[ParentSide] AppendChild")); const OpAppendChild& oac = edit.get_OpAppendChild(); ShadowContainer(oac)->AsContainer()->InsertAfter( ShadowChild(oac)->AsLayer(), NULL); break; } case Edit::TOpRemoveChild: { MOZ_LAYERS_LOG(("[ParentSide] RemoveChild")); const OpRemoveChild& orc = edit.get_OpRemoveChild(); Layer* childLayer = ShadowChild(orc)->AsLayer(); ShadowContainer(orc)->AsContainer()->RemoveChild(childLayer); break; } case Edit::TOpPaintThebesBuffer: { MOZ_LAYERS_LOG(("[ParentSide] Paint ThebesLayer")); const OpPaintThebesBuffer& op = edit.get_OpPaintThebesBuffer(); ShadowLayerParent* shadow = AsShadowLayer(op); ShadowThebesLayer* thebes = static_cast<ShadowThebesLayer*>(shadow->AsLayer()); const ThebesBuffer& newFront = op.newFrontBuffer(); ThebesBuffer newBack; nsIntRegion newValidRegion; float newXResolution, newYResolution; OptionalThebesBuffer readonlyFront; nsIntRegion frontUpdatedRegion; thebes->Swap(newFront, op.updatedRegion(), &newBack, &newValidRegion, &newXResolution, &newYResolution, &readonlyFront, &frontUpdatedRegion); replyv.push_back( OpThebesBufferSwap( shadow, NULL, newBack, newValidRegion, newXResolution, newYResolution, readonlyFront, frontUpdatedRegion)); break; } case Edit::TOpPaintCanvas: { MOZ_LAYERS_LOG(("[ParentSide] Paint CanvasLayer")); const OpPaintCanvas& op = edit.get_OpPaintCanvas(); ShadowLayerParent* shadow = AsShadowLayer(op); ShadowCanvasLayer* canvas = static_cast<ShadowCanvasLayer*>(shadow->AsLayer()); SurfaceDescriptor newFront = op.newFrontBuffer(); SurfaceDescriptor newBack; canvas->Swap(op.newFrontBuffer(), &newBack); if (newFront == newBack) { newFront = SurfaceDescriptor(); } canvas->Updated(); replyv.push_back(OpBufferSwap(shadow, NULL, newBack)); break; } case Edit::TOpPaintImage: { MOZ_LAYERS_LOG(("[ParentSide] Paint ImageLayer")); const OpPaintImage& op = edit.get_OpPaintImage(); ShadowLayerParent* shadow = AsShadowLayer(op); ShadowImageLayer* image = static_cast<ShadowImageLayer*>(shadow->AsLayer()); SurfaceDescriptor newFront = op.newFrontBuffer(); SurfaceDescriptor newBack; image->Swap(op.newFrontBuffer(), &newBack); if (newFront == newBack) { newFront = SurfaceDescriptor(); } replyv.push_back(OpBufferSwap(shadow, NULL, newBack)); break; } default: NS_RUNTIMEABORT("not reached"); } } layer_manager()->EndTransaction(NULL, NULL); reply->SetCapacity(replyv.size()); if (replyv.size() > 0) { reply->AppendElements(&replyv.front(), replyv.size()); } // Ensure that any pending operations involving back and front // buffers have completed, so that neither process stomps on the // other's buffer contents. ShadowLayerManager::PlatformSyncBeforeReplyUpdate(); Frame()->ShadowLayersUpdated(); return true; }
void ArrayLengthReadError(const char* aElementName) { nsPrintfCString message("error deserializing length of %s[]", aElementName); NS_RUNTIMEABORT(message.get()); }
void ShadowCanvasLayerD3D9::Initialize(const Data& aData) { NS_RUNTIMEABORT("Non-shadow layer API unexpectedly used for shadow layer"); }
bool CompositorOGL::Initialize() { ScopedGfxFeatureReporter reporter("GL Layers", true); // Do not allow double initialization NS_ABORT_IF_FALSE(mGLContext == nullptr, "Don't reinitialize CompositorOGL"); mGLContext = CreateContext(); #ifdef MOZ_WIDGET_ANDROID if (!mGLContext) NS_RUNTIMEABORT("We need a context on Android"); #endif if (!mGLContext) return false; mGLContext->SetFlipped(true); MakeCurrent(); mHasBGRA = mGLContext->IsExtensionSupported(gl::GLContext::EXT_texture_format_BGRA8888) || mGLContext->IsExtensionSupported(gl::GLContext::EXT_bgra); mGLContext->fBlendFuncSeparate(LOCAL_GL_ONE, LOCAL_GL_ONE_MINUS_SRC_ALPHA, LOCAL_GL_ONE, LOCAL_GL_ONE); mGLContext->fEnable(LOCAL_GL_BLEND); mPrograms.AppendElements(NumProgramTypes); for (int type = 0; type < NumProgramTypes; ++type) { AddPrograms(static_cast<ShaderProgramType>(type)); } // initialise a common shader to check that we can actually compile a shader if (!mPrograms[RGBALayerProgramType].mVariations[MaskNone]->Initialize()) { return false; } if (mGLContext->WorkAroundDriverBugs()) { /** * We'll test the ability here to bind NPOT textures to a framebuffer, if * this fails we'll try ARB_texture_rectangle. */ GLenum textureTargets[] = { LOCAL_GL_TEXTURE_2D, LOCAL_GL_NONE }; if (mGLContext->IsGLES2()) { textureTargets[1] = LOCAL_GL_TEXTURE_RECTANGLE_ARB; } mFBOTextureTarget = LOCAL_GL_NONE; GLuint testFBO = 0; mGLContext->fGenFramebuffers(1, &testFBO); GLuint testTexture = 0; for (uint32_t i = 0; i < ArrayLength(textureTargets); i++) { GLenum target = textureTargets[i]; if (!target) continue; mGLContext->fGenTextures(1, &testTexture); mGLContext->fBindTexture(target, testTexture); mGLContext->fTexParameteri(target, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_NEAREST); mGLContext->fTexParameteri(target, LOCAL_GL_TEXTURE_MAG_FILTER, LOCAL_GL_NEAREST); mGLContext->fTexImage2D(target, 0, LOCAL_GL_RGBA, 5, 3, /* sufficiently NPOT */ 0, LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_BYTE, nullptr); // unbind this texture, in preparation for binding it to the FBO mGLContext->fBindTexture(target, 0); mGLContext->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, testFBO); mGLContext->fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER, LOCAL_GL_COLOR_ATTACHMENT0, target, testTexture, 0); if (mGLContext->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER) == LOCAL_GL_FRAMEBUFFER_COMPLETE) { mFBOTextureTarget = target; mGLContext->fDeleteTextures(1, &testTexture); break; } mGLContext->fDeleteTextures(1, &testTexture); } if (testFBO) { mGLContext->fDeleteFramebuffers(1, &testFBO); } if (mFBOTextureTarget == LOCAL_GL_NONE) { /* Unable to find a texture target that works with FBOs and NPOT textures */ return false; } } else { // not trying to work around driver bugs, so TEXTURE_2D should just work mFBOTextureTarget = LOCAL_GL_TEXTURE_2D; } // back to default framebuffer, to avoid confusion mGLContext->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, 0); if (mFBOTextureTarget == LOCAL_GL_TEXTURE_RECTANGLE_ARB) { /* If we're using TEXTURE_RECTANGLE, then we must have the ARB * extension -- the EXT variant does not provide support for * texture rectangle access inside GLSL (sampler2DRect, * texture2DRect). */ if (!mGLContext->IsExtensionSupported(gl::GLContext::ARB_texture_rectangle)) return false; } /* Create a simple quad VBO */ mGLContext->fGenBuffers(1, &mQuadVBO); mGLContext->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, mQuadVBO); GLfloat vertices[] = { /* First quad vertices */ 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, /* Then quad texcoords */ 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, /* Then flipped quad texcoords */ 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, }; mGLContext->fBufferData(LOCAL_GL_ARRAY_BUFFER, sizeof(vertices), vertices, LOCAL_GL_STATIC_DRAW); mGLContext->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, 0); nsCOMPtr<nsIConsoleService> console(do_GetService(NS_CONSOLESERVICE_CONTRACTID)); if (console) { nsString msg; msg += NS_LITERAL_STRING("OpenGL LayerManager Initialized Succesfully.\nVersion: "); msg += NS_ConvertUTF8toUTF16( nsDependentCString((const char*)mGLContext->fGetString(LOCAL_GL_VERSION))); msg += NS_LITERAL_STRING("\nVendor: "); msg += NS_ConvertUTF8toUTF16( nsDependentCString((const char*)mGLContext->fGetString(LOCAL_GL_VENDOR))); msg += NS_LITERAL_STRING("\nRenderer: "); msg += NS_ConvertUTF8toUTF16( nsDependentCString((const char*)mGLContext->fGetString(LOCAL_GL_RENDERER))); msg += NS_LITERAL_STRING("\nFBO Texture Target: "); if (mFBOTextureTarget == LOCAL_GL_TEXTURE_2D) msg += NS_LITERAL_STRING("TEXTURE_2D"); else msg += NS_LITERAL_STRING("TEXTURE_RECTANGLE"); console->LogStringMessage(msg.get()); } if (NS_IsMainThread()) { // NOTE: This must match the code in ReadDrawFPSPref::Run(). Preferences::AddBoolVarCache(&sDrawFPS, "layers.acceleration.draw-fps"); } else { // We have to dispatch an event to the main thread to read the pref. NS_DispatchToMainThread(new ReadDrawFPSPref()); } reporter.SetSuccessful(); return true; }