static TemporaryRef<const webgl::LinkedProgramInfo> QueryProgramInfo(WebGLProgram* prog, gl::GLContext* gl) { RefPtr<webgl::LinkedProgramInfo> info(new webgl::LinkedProgramInfo(prog)); GLuint maxAttribLenWithNull = 0; gl->fGetProgramiv(prog->mGLName, LOCAL_GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, (GLint*)&maxAttribLenWithNull); if (maxAttribLenWithNull < 1) maxAttribLenWithNull = 1; GLuint maxUniformLenWithNull = 0; gl->fGetProgramiv(prog->mGLName, LOCAL_GL_ACTIVE_UNIFORM_MAX_LENGTH, (GLint*)&maxUniformLenWithNull); if (maxUniformLenWithNull < 1) maxUniformLenWithNull = 1; #ifdef DUMP_SHADERVAR_MAPPINGS printf_stderr("maxAttribLenWithNull: %d\n", maxAttribLenWithNull); printf_stderr("maxUniformLenWithNull: %d\n", maxUniformLenWithNull); #endif // Attribs GLuint numActiveAttribs = 0; gl->fGetProgramiv(prog->mGLName, LOCAL_GL_ACTIVE_ATTRIBUTES, (GLint*)&numActiveAttribs); for (GLuint i = 0; i < numActiveAttribs; i++) { nsAutoCString mappedName; mappedName.SetLength(maxAttribLenWithNull - 1); GLsizei lengthWithoutNull = 0; GLint elemCount = 0; // `size` GLenum elemType = 0; // `type` gl->fGetActiveAttrib(prog->mGLName, i, mappedName.Length()+1, &lengthWithoutNull, &elemCount, &elemType, mappedName.BeginWriting()); mappedName.SetLength(lengthWithoutNull); // Collect ActiveInfos: // Attribs can't be arrays, so we can skip some of the mess we have in the Uniform // path. nsDependentCString userName; if (!prog->FindAttribUserNameByMappedName(mappedName, &userName)) userName.Rebind(mappedName, 0); #ifdef DUMP_SHADERVAR_MAPPINGS printf_stderr("[attrib %i] %s/%s\n", i, mappedName.BeginReading(), userName.BeginReading()); printf_stderr(" lengthWithoutNull: %d\n", lengthWithoutNull); #endif const bool isArray = false; AddActiveInfo(prog->Context(), elemCount, elemType, isArray, userName, mappedName, &info->activeAttribs, &info->attribMap); // Collect active locations: GLint loc = gl->fGetAttribLocation(prog->mGLName, mappedName.BeginReading()); if (loc == -1) MOZ_CRASH("Active attrib has no location."); info->activeAttribLocs.insert(loc); } // Uniforms const bool needsCheckForArrays = true; GLuint numActiveUniforms = 0; gl->fGetProgramiv(prog->mGLName, LOCAL_GL_ACTIVE_UNIFORMS, (GLint*)&numActiveUniforms); for (GLuint i = 0; i < numActiveUniforms; i++) { nsAutoCString mappedName; mappedName.SetLength(maxUniformLenWithNull - 1); GLsizei lengthWithoutNull = 0; GLint elemCount = 0; // `size` GLenum elemType = 0; // `type` gl->fGetActiveUniform(prog->mGLName, i, mappedName.Length()+1, &lengthWithoutNull, &elemCount, &elemType, mappedName.BeginWriting()); mappedName.SetLength(lengthWithoutNull); nsAutoCString baseMappedName; bool isArray; size_t arrayIndex; if (!ParseName(mappedName, &baseMappedName, &isArray, &arrayIndex)) MOZ_CRASH("Failed to parse `mappedName` received from driver."); // Note that for good drivers, `isArray` should already be correct. // However, if FindUniform succeeds, it will be validator-guaranteed correct. nsAutoCString baseUserName; if (!prog->FindUniformByMappedName(baseMappedName, &baseUserName, &isArray)) { baseUserName = baseMappedName; if (needsCheckForArrays && !isArray) { // By GLES 3, GetUniformLocation("foo[0]") should return -1 if `foo` is // not an array. Our current linux Try slaves return the location of `foo` // anyways, though. std::string mappedName = baseMappedName.BeginReading(); mappedName += "[0]"; GLint loc = gl->fGetUniformLocation(prog->mGLName, mappedName.c_str()); if (loc != -1) isArray = true; } } #ifdef DUMP_SHADERVAR_MAPPINGS printf_stderr("[uniform %i] %s/%i/%s/%s\n", i, mappedName.BeginReading(), (int)isArray, baseMappedName.BeginReading(), baseUserName.BeginReading()); printf_stderr(" lengthWithoutNull: %d\n", lengthWithoutNull); printf_stderr(" isArray: %d\n", (int)isArray); #endif AddActiveInfo(prog->Context(), elemCount, elemType, isArray, baseUserName, baseMappedName, &info->activeUniforms, &info->uniformMap); } return info.forget(); }
TileClient ClientTiledLayerBuffer::ValidateTile(TileClient aTile, const nsIntPoint& aTileOrigin, const nsIntRegion& aDirtyRegion) { PROFILER_LABEL("ClientTiledLayerBuffer", "ValidateTile"); #ifdef GFX_TILEDLAYER_PREF_WARNINGS if (aDirtyRegion.IsComplex()) { printf_stderr("Complex region\n"); } #endif if (aTile.IsPlaceholderTile()) { aTile.SetLayerManager(mManager); } // Discard our front and backbuffers if our contents changed. In this case // the calling code will already have taken care of invalidating the entire // layer. if (HasFormatChanged()) { aTile.DiscardBackBuffer(); aTile.DiscardFrontBuffer(); } bool createdTextureClient = false; nsIntRegion offsetDirtyRegion = aDirtyRegion.MovedBy(-aTileOrigin); bool usingSinglePaintBuffer = !!mSinglePaintDrawTarget; RefPtr<TextureClient> backBuffer = aTile.GetBackBuffer(offsetDirtyRegion, mManager->GetTexturePool(gfxPlatform::GetPlatform()->Optimal2DFormatForContent(GetContentType())), &createdTextureClient, !usingSinglePaintBuffer); if (!backBuffer->Lock(OPEN_READ_WRITE)) { NS_WARNING("Failed to lock tile TextureClient for updating."); aTile.DiscardFrontBuffer(); return aTile; } // We must not keep a reference to the DrawTarget after it has been unlocked, // make sure these are null'd before unlocking as destruction of the context // may cause the target to be flushed. RefPtr<DrawTarget> drawTarget = backBuffer->AsTextureClientDrawTarget()->GetAsDrawTarget(); drawTarget->SetTransform(Matrix()); RefPtr<gfxContext> ctxt = new gfxContext(drawTarget); if (usingSinglePaintBuffer) { // XXX Perhaps we should just copy the bounding rectangle here? RefPtr<gfx::SourceSurface> source = mSinglePaintDrawTarget->Snapshot(); nsIntRegionRectIterator it(aDirtyRegion); for (const nsIntRect* dirtyRect = it.Next(); dirtyRect != nullptr; dirtyRect = it.Next()) { #ifdef GFX_TILEDLAYER_PREF_WARNINGS printf_stderr(" break into subdirtyRect %i, %i, %i, %i\n", dirtyRect->x, dirtyRect->y, dirtyRect->width, dirtyRect->height); #endif gfx::Rect drawRect(dirtyRect->x - aTileOrigin.x, dirtyRect->y - aTileOrigin.y, dirtyRect->width, dirtyRect->height); drawRect.Scale(mResolution); gfx::IntRect copyRect(NS_roundf((dirtyRect->x - mSinglePaintBufferOffset.x) * mResolution), NS_roundf((dirtyRect->y - mSinglePaintBufferOffset.y) * mResolution), drawRect.width, drawRect.height); gfx::IntPoint copyTarget(NS_roundf(drawRect.x), NS_roundf(drawRect.y)); drawTarget->CopySurface(source, copyRect, copyTarget); // Mark the newly updated area as invalid in the front buffer aTile.mInvalidFront.Or(aTile.mInvalidFront, nsIntRect(copyTarget.x, copyTarget.y, copyRect.width, copyRect.height)); } // The new buffer is now validated, remove the dirty region from it. aTile.mInvalidBack.Sub(nsIntRect(0, 0, TILEDLAYERBUFFER_TILE_SIZE, TILEDLAYERBUFFER_TILE_SIZE), offsetDirtyRegion); } else { // Area of the full tile... nsIntRegion tileRegion = nsIntRect(aTileOrigin.x, aTileOrigin.y, TILEDLAYERBUFFER_TILE_SIZE, TILEDLAYERBUFFER_TILE_SIZE); // Intersect this area with the portion that's dirty. tileRegion = tileRegion.Intersect(aDirtyRegion); // Move invalid areas into layer space. aTile.mInvalidFront.MoveBy(aTileOrigin); aTile.mInvalidBack.MoveBy(aTileOrigin); // Add the area that's going to be redrawn to the invalid area of the // front region. aTile.mInvalidFront.Or(aTile.mInvalidFront, tileRegion); // Add invalid areas of the backbuffer to the area to redraw. tileRegion.Or(tileRegion, aTile.mInvalidBack); // Move invalid areas back into tile space. aTile.mInvalidFront.MoveBy(-aTileOrigin); // This will be validated now. aTile.mInvalidBack.SetEmpty(); nsIntRect bounds = tileRegion.GetBounds(); bounds.ScaleRoundOut(mResolution, mResolution); bounds.MoveBy(-aTileOrigin); if (GetContentType() != gfxContentType::COLOR) { drawTarget->ClearRect(Rect(bounds.x, bounds.y, bounds.width, bounds.height)); } ctxt->NewPath(); ctxt->Clip(gfxRect(bounds.x, bounds.y, bounds.width, bounds.height)); ctxt->Scale(mResolution, mResolution); ctxt->Translate(gfxPoint(-aTileOrigin.x, -aTileOrigin.y)); mCallback(mThebesLayer, ctxt, tileRegion.GetBounds(), DrawRegionClip::CLIP_NONE, nsIntRegion(), mCallbackData); } #ifdef GFX_TILEDLAYER_DEBUG_OVERLAY DrawDebugOverlay(drawTarget, aTileOrigin.x * mResolution, aTileOrigin.y * mResolution, GetTileLength(), GetTileLength()); #endif ctxt = nullptr; drawTarget = nullptr; backBuffer->Unlock(); aTile.Flip(); if (createdTextureClient) { if (!mCompositableClient->AddTextureClient(backBuffer)) { NS_WARNING("Failed to add tile TextureClient."); aTile.DiscardFrontBuffer(); aTile.DiscardBackBuffer(); return aTile; } } // Note, we don't call UpdatedTexture. The Updated function is called manually // by the TiledContentHost before composition. if (backBuffer->HasInternalBuffer()) { // If our new buffer has an internal buffer, we don't want to keep another // TextureClient around unnecessarily, so discard the back-buffer. aTile.DiscardBackBuffer(); } return aTile; }
void renderTraceEventEnd(const char *aComment, const char *aColor) { printf_stderr("%s RENDERTRACE %u fillrect #%s 0 0 0 0\n", aComment, (int)PR_IntervalNow(), aColor); }
static NTSTATUS NTAPI patched_LdrLoadDll (PWCHAR filePath, PULONG flags, PUNICODE_STRING moduleFileName, PHANDLE handle) { // We have UCS2 (UTF16?), we want ASCII, but we also just want the filename portion #define DLLNAME_MAX 128 char dllName[DLLNAME_MAX+1]; wchar_t *dll_part; DllBlockInfo *info; int len = moduleFileName->Length / 2; wchar_t *fname = moduleFileName->Buffer; // The filename isn't guaranteed to be null terminated, but in practice // it always will be; ensure that this is so, and bail if not. // This is done instead of the more robust approach because of bug 527122, // where lots of weird things were happening when we tried to make a copy. if (moduleFileName->MaximumLength < moduleFileName->Length+2 || fname[len] != 0) { #ifdef DEBUG printf_stderr("LdrLoadDll: non-null terminated string found!\n"); #endif goto continue_loading; } dll_part = wcsrchr(fname, L'\\'); if (dll_part) { dll_part = dll_part + 1; len -= dll_part - fname; } else { dll_part = fname; } #ifdef DEBUG_very_verbose printf_stderr("LdrLoadDll: dll_part '%S' %d\n", dll_part, len); #endif // if it's too long, then, we assume we won't want to block it, // since DLLNAME_MAX should be at least long enough to hold the longest // entry in our blocklist. if (len > DLLNAME_MAX) { #ifdef DEBUG printf_stderr("LdrLoadDll: len too long! %d\n", len); #endif goto continue_loading; } // copy over to our char byte buffer, lowercasing ASCII as we go for (int i = 0; i < len; i++) { wchar_t c = dll_part[i]; if (c > 0x7f) { // welp, it's not ascii; if we need to add non-ascii things to // our blocklist, we'll have to remove this limitation. goto continue_loading; } // ensure that dll name is all lowercase if (c >= 'A' && c <= 'Z') c += 'a' - 'A'; dllName[i] = (char) c; } dllName[len] = 0; #ifdef DEBUG_very_verbose printf_stderr("LdrLoadDll: dll name '%s'\n", dllName); #endif // then compare to everything on the blocklist info = &sWindowsDllBlocklist[0]; while (info->name) { if (strcmp(info->name, dllName) == 0) break; info++; } if (info->name) { bool load_ok = false; #ifdef DEBUG_very_verbose printf_stderr("LdrLoadDll: info->name: '%s'\n", info->name); #endif if (info->maxVersion != ALL_VERSIONS) { // figure out the length of the string that we need DWORD pathlen = SearchPathW(filePath, fname, L".dll", 0, NULL, NULL); if (pathlen == 0) { // uh, we couldn't find the DLL at all, so... printf_stderr("LdrLoadDll: Blocking load of '%s' (SearchPathW didn't find it?)\n", dllName); return STATUS_DLL_NOT_FOUND; } wchar_t *full_fname = (wchar_t*) malloc(sizeof(wchar_t)*(pathlen+1)); if (!full_fname) { // couldn't allocate memory? return STATUS_DLL_NOT_FOUND; } // now actually grab it SearchPathW(filePath, fname, L".dll", pathlen+1, full_fname, NULL); DWORD zero; DWORD infoSize = GetFileVersionInfoSizeW(full_fname, &zero); // If we failed to get the version information, we block. if (infoSize != 0) { nsAutoArrayPtr<unsigned char> infoData(new unsigned char[infoSize]); VS_FIXEDFILEINFO *vInfo; UINT vInfoLen; if (GetFileVersionInfoW(full_fname, 0, infoSize, infoData) && VerQueryValueW(infoData, L"\\", (LPVOID*) &vInfo, &vInfoLen)) { unsigned long long fVersion = ((unsigned long long)vInfo->dwFileVersionMS) << 32 | ((unsigned long long)vInfo->dwFileVersionLS); // finally do the version check, and if it's greater than our block // version, keep loading if (fVersion > info->maxVersion) load_ok = true; } } free(full_fname); } if (!load_ok) { printf_stderr("LdrLoadDll: Blocking load of '%s' -- see http://www.mozilla.com/en-US/blocklist/\n", dllName); return STATUS_DLL_NOT_FOUND; } } continue_loading: #ifdef DEBUG_very_verbose printf_stderr("LdrLoadDll: continuing load... ('%S')\n", moduleFileName->Buffer); #endif NS_SetHasLoadedNewDLLs(); return stub_LdrLoadDll(filePath, flags, moduleFileName, handle); }
void ClientTiledLayerBuffer::PaintThebes(const nsIntRegion& aNewValidRegion, const nsIntRegion& aPaintRegion, LayerManager::DrawThebesLayerCallback aCallback, void* aCallbackData) { mCallback = aCallback; mCallbackData = aCallbackData; #ifdef GFX_TILEDLAYER_PREF_WARNINGS long start = PR_IntervalNow(); #endif // If this region is empty XMost() - 1 will give us a negative value. NS_ASSERTION(!aPaintRegion.GetBounds().IsEmpty(), "Empty paint region\n"); bool useSinglePaintBuffer = UseSinglePaintBuffer(); // XXX The single-tile case doesn't work at the moment, see bug 850396 /* if (useSinglePaintBuffer) { // Check if the paint only spans a single tile. If that's // the case there's no point in using a single paint buffer. nsIntRect paintBounds = aPaintRegion.GetBounds(); useSinglePaintBuffer = GetTileStart(paintBounds.x) != GetTileStart(paintBounds.XMost() - 1) || GetTileStart(paintBounds.y) != GetTileStart(paintBounds.YMost() - 1); } */ if (useSinglePaintBuffer) { nsRefPtr<gfxContext> ctxt; const nsIntRect bounds = aPaintRegion.GetBounds(); { PROFILER_LABEL("ClientTiledLayerBuffer", "PaintThebesSingleBufferAlloc"); gfxImageFormat format = gfxPlatform::GetPlatform()->OptimalFormatForContent( GetContentType()); mSinglePaintDrawTarget = gfxPlatform::GetPlatform()->CreateOffscreenContentDrawTarget( gfx::IntSize(ceilf(bounds.width * mResolution), ceilf(bounds.height * mResolution)), gfx::ImageFormatToSurfaceFormat(format)); ctxt = new gfxContext(mSinglePaintDrawTarget); mSinglePaintBufferOffset = nsIntPoint(bounds.x, bounds.y); } ctxt->NewPath(); ctxt->Scale(mResolution, mResolution); ctxt->Translate(gfxPoint(-bounds.x, -bounds.y)); #ifdef GFX_TILEDLAYER_PREF_WARNINGS if (PR_IntervalNow() - start > 3) { printf_stderr("Slow alloc %i\n", PR_IntervalNow() - start); } start = PR_IntervalNow(); #endif PROFILER_LABEL("ClientTiledLayerBuffer", "PaintThebesSingleBufferDraw"); mCallback(mThebesLayer, ctxt, aPaintRegion, DrawRegionClip::CLIP_NONE, nsIntRegion(), mCallbackData); } #ifdef GFX_TILEDLAYER_PREF_WARNINGS if (PR_IntervalNow() - start > 30) { const nsIntRect bounds = aPaintRegion.GetBounds(); printf_stderr("Time to draw %i: %i, %i, %i, %i\n", PR_IntervalNow() - start, bounds.x, bounds.y, bounds.width, bounds.height); if (aPaintRegion.IsComplex()) { printf_stderr("Complex region\n"); nsIntRegionRectIterator it(aPaintRegion); for (const nsIntRect* rect = it.Next(); rect != nullptr; rect = it.Next()) { printf_stderr(" rect %i, %i, %i, %i\n", rect->x, rect->y, rect->width, rect->height); } } } start = PR_IntervalNow(); #endif PROFILER_LABEL("ClientTiledLayerBuffer", "PaintThebesUpdate"); Update(aNewValidRegion, aPaintRegion); #ifdef GFX_TILEDLAYER_PREF_WARNINGS if (PR_IntervalNow() - start > 10) { const nsIntRect bounds = aPaintRegion.GetBounds(); printf_stderr("Time to tile %i: %i, %i, %i, %i\n", PR_IntervalNow() - start, bounds.x, bounds.y, bounds.width, bounds.height); } #endif mLastPaintOpaque = mThebesLayer->CanUseOpaqueSurface(); mCallback = nullptr; mCallbackData = nullptr; mSinglePaintDrawTarget = nullptr; }
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() || 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(); 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(); AsShadowLayer(edit.get_OpCreateCanvasLayer())->Bind(layer); break; } case Edit::TOpCreateRefLayer: { MOZ_LAYERS_LOG(("[ParentSide] CreateRefLayer")); nsRefPtr<ShadowRefLayer> layer = layer_manager()->CreateShadowRefLayer(); 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()); 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")); 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()); 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<ShadowCanvasLayer*>(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()); 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::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; } case Edit::TOpPaintTiledLayerBuffer: { MOZ_LAYERS_LOG(("[ParentSide] Paint TiledLayerBuffer")); const OpPaintTiledLayerBuffer& op = edit.get_OpPaintTiledLayerBuffer(); ShadowLayerParent* shadow = AsShadowLayer(op); LayerComposite* compositeLayer = shadow->AsLayer()->AsLayerComposite(); compositeLayer->EnsureBuffer(BUFFER_TILED); TiledLayerComposer* tileComposer = compositeLayer->AsTiledLayerComposer(); NS_ASSERTION(tileComposer, "compositeLayer is not a tile composer"); BasicTiledLayerBuffer* p = reinterpret_cast<BasicTiledLayerBuffer*>(op.tiledLayerBuffer()); tileComposer->PaintedTiledLayerBuffer(p); 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. 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; }
static already_AddRefed<const webgl::LinkedProgramInfo> QueryProgramInfo(WebGLProgram* prog, gl::GLContext* gl) { WebGLContext* const webgl = prog->mContext; RefPtr<webgl::LinkedProgramInfo> info(new webgl::LinkedProgramInfo(prog)); GLuint maxAttribLenWithNull = 0; gl->fGetProgramiv(prog->mGLName, LOCAL_GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, (GLint*)&maxAttribLenWithNull); if (maxAttribLenWithNull < 1) maxAttribLenWithNull = 1; GLuint maxUniformLenWithNull = 0; gl->fGetProgramiv(prog->mGLName, LOCAL_GL_ACTIVE_UNIFORM_MAX_LENGTH, (GLint*)&maxUniformLenWithNull); if (maxUniformLenWithNull < 1) maxUniformLenWithNull = 1; GLuint maxUniformBlockLenWithNull = 0; if (gl->IsSupported(gl::GLFeature::uniform_buffer_object)) { gl->fGetProgramiv(prog->mGLName, LOCAL_GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH, (GLint*)&maxUniformBlockLenWithNull); if (maxUniformBlockLenWithNull < 1) maxUniformBlockLenWithNull = 1; } GLuint maxTransformFeedbackVaryingLenWithNull = 0; if (gl->IsSupported(gl::GLFeature::transform_feedback2)) { gl->fGetProgramiv(prog->mGLName, LOCAL_GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH, (GLint*)&maxTransformFeedbackVaryingLenWithNull); if (maxTransformFeedbackVaryingLenWithNull < 1) maxTransformFeedbackVaryingLenWithNull = 1; } #ifdef DUMP_SHADERVAR_MAPPINGS printf_stderr("maxAttribLenWithNull: %d\n", maxAttribLenWithNull); printf_stderr("maxUniformLenWithNull: %d\n", maxUniformLenWithNull); printf_stderr("maxUniformBlockLenWithNull: %d\n", maxUniformBlockLenWithNull); #endif // Attribs GLuint numActiveAttribs = 0; gl->fGetProgramiv(prog->mGLName, LOCAL_GL_ACTIVE_ATTRIBUTES, (GLint*)&numActiveAttribs); for (GLuint i = 0; i < numActiveAttribs; i++) { nsAutoCString mappedName; mappedName.SetLength(maxAttribLenWithNull - 1); GLsizei lengthWithoutNull = 0; GLint elemCount = 0; // `size` GLenum elemType = 0; // `type` gl->fGetActiveAttrib(prog->mGLName, i, mappedName.Length()+1, &lengthWithoutNull, &elemCount, &elemType, mappedName.BeginWriting()); GLenum error = gl->fGetError(); if (error != LOCAL_GL_NO_ERROR) { gfxCriticalNote << "Failed to do glGetActiveAttrib: " << error; } mappedName.SetLength(lengthWithoutNull); // Attribs can't be arrays, so we can skip some of the mess we have in the Uniform // path. nsDependentCString userName; if (!prog->FindAttribUserNameByMappedName(mappedName, &userName)) userName.Rebind(mappedName, 0); /////// const GLint loc = gl->fGetAttribLocation(prog->mGLName, mappedName.BeginReading()); if (loc == -1) { MOZ_ASSERT(mappedName == "gl_InstanceID", "Active attrib should have a location."); continue; } #ifdef DUMP_SHADERVAR_MAPPINGS printf_stderr("[attrib %i: %i] %s/%s\n", i, loc, mappedName.BeginReading(), userName.BeginReading()); printf_stderr(" lengthWithoutNull: %d\n", lengthWithoutNull); #endif /////// const bool isArray = false; const RefPtr<WebGLActiveInfo> activeInfo = new WebGLActiveInfo(webgl, elemCount, elemType, isArray, userName, mappedName); const webgl::AttribInfo attrib = {activeInfo, uint32_t(loc)}; info->attribs.push_back(attrib); } // Uniforms const bool needsCheckForArrays = gl->WorkAroundDriverBugs(); GLuint numActiveUniforms = 0; gl->fGetProgramiv(prog->mGLName, LOCAL_GL_ACTIVE_UNIFORMS, (GLint*)&numActiveUniforms); for (GLuint i = 0; i < numActiveUniforms; i++) { nsAutoCString mappedName; mappedName.SetLength(maxUniformLenWithNull - 1); GLsizei lengthWithoutNull = 0; GLint elemCount = 0; // `size` GLenum elemType = 0; // `type` gl->fGetActiveUniform(prog->mGLName, i, mappedName.Length()+1, &lengthWithoutNull, &elemCount, &elemType, mappedName.BeginWriting()); mappedName.SetLength(lengthWithoutNull); /////// nsAutoCString baseMappedName; bool isArray; size_t arrayIndex; if (!ParseName(mappedName, &baseMappedName, &isArray, &arrayIndex)) MOZ_CRASH("GFX: Failed to parse `mappedName` received from driver."); // Note that for good drivers, `isArray` should already be correct. // However, if FindUniform succeeds, it will be validator-guaranteed correct. /////// nsAutoCString baseUserName; if (!prog->FindUniformByMappedName(baseMappedName, &baseUserName, &isArray)) { // Validator likely missing. baseUserName = baseMappedName; if (needsCheckForArrays && !isArray) { // By GLES 3, GetUniformLocation("foo[0]") should return -1 if `foo` is // not an array. Our current linux Try slaves return the location of `foo` // anyways, though. std::string mappedNameStr = baseMappedName.BeginReading(); mappedNameStr += "[0]"; GLint loc = gl->fGetUniformLocation(prog->mGLName, mappedNameStr.c_str()); if (loc != -1) isArray = true; } } /////// #ifdef DUMP_SHADERVAR_MAPPINGS printf_stderr("[uniform %i] %s/%i/%s/%s\n", i, mappedName.BeginReading(), (int)isArray, baseMappedName.BeginReading(), baseUserName.BeginReading()); printf_stderr(" lengthWithoutNull: %d\n", lengthWithoutNull); printf_stderr(" isArray: %d\n", (int)isArray); #endif /////// const RefPtr<WebGLActiveInfo> activeInfo = new WebGLActiveInfo(webgl, elemCount, elemType, isArray, baseUserName, baseMappedName); auto* uniform = new webgl::UniformInfo(activeInfo); info->uniforms.push_back(uniform); if (uniform->mSamplerTexList) { info->uniformSamplers.push_back(uniform); } } // Uniform Blocks // (no sampler types allowed!) if (gl->IsSupported(gl::GLFeature::uniform_buffer_object)) { GLuint numActiveUniformBlocks = 0; gl->fGetProgramiv(prog->mGLName, LOCAL_GL_ACTIVE_UNIFORM_BLOCKS, (GLint*)&numActiveUniformBlocks); for (GLuint i = 0; i < numActiveUniformBlocks; i++) { nsAutoCString mappedName; mappedName.SetLength(maxUniformBlockLenWithNull - 1); GLint lengthWithoutNull; gl->fGetActiveUniformBlockiv(prog->mGLName, i, LOCAL_GL_UNIFORM_BLOCK_NAME_LENGTH, &lengthWithoutNull); gl->fGetActiveUniformBlockName(prog->mGLName, i, maxUniformBlockLenWithNull, &lengthWithoutNull, mappedName.BeginWriting()); mappedName.SetLength(lengthWithoutNull); nsAutoCString baseMappedName; bool isArray; size_t arrayIndex; if (!ParseName(mappedName, &baseMappedName, &isArray, &arrayIndex)) MOZ_CRASH("GFX: Failed to parse `mappedName` received from driver."); nsAutoCString baseUserName; if (!prog->FindUniformBlockByMappedName(baseMappedName, &baseUserName, &isArray)) { baseUserName = baseMappedName; if (needsCheckForArrays && !isArray) { std::string mappedNameStr = baseMappedName.BeginReading(); mappedNameStr += "[0]"; GLuint loc = gl->fGetUniformBlockIndex(prog->mGLName, mappedNameStr.c_str()); if (loc != LOCAL_GL_INVALID_INDEX) isArray = true; } } //// GLuint dataSize = 0; gl->fGetActiveUniformBlockiv(prog->mGLName, i, LOCAL_GL_UNIFORM_BLOCK_DATA_SIZE, (GLint*)&dataSize); #ifdef DUMP_SHADERVAR_MAPPINGS printf_stderr("[uniform block %i] %s/%i/%s/%s\n", i, mappedName.BeginReading(), (int)isArray, baseMappedName.BeginReading(), baseUserName.BeginReading()); printf_stderr(" lengthWithoutNull: %d\n", lengthWithoutNull); printf_stderr(" isArray: %d\n", (int)isArray); #endif auto* block = new webgl::UniformBlockInfo(webgl, baseUserName, baseMappedName, dataSize); info->uniformBlocks.push_back(block); } } // Transform feedback varyings if (gl->IsSupported(gl::GLFeature::transform_feedback2)) { GLuint numTransformFeedbackVaryings = 0; gl->fGetProgramiv(prog->mGLName, LOCAL_GL_TRANSFORM_FEEDBACK_VARYINGS, (GLint*)&numTransformFeedbackVaryings); for (GLuint i = 0; i < numTransformFeedbackVaryings; i++) { nsAutoCString mappedName; mappedName.SetLength(maxTransformFeedbackVaryingLenWithNull - 1); GLint lengthWithoutNull; GLsizei elemCount; GLenum elemType; gl->fGetTransformFeedbackVarying(prog->mGLName, i, maxTransformFeedbackVaryingLenWithNull, &lengthWithoutNull, &elemCount, &elemType, mappedName.BeginWriting()); mappedName.SetLength(lengthWithoutNull); //// nsAutoCString baseMappedName; bool isArray; size_t arrayIndex; if (!ParseName(mappedName, &baseMappedName, &isArray, &arrayIndex)) MOZ_CRASH("GFX: Failed to parse `mappedName` received from driver."); nsAutoCString baseUserName; if (!prog->FindVaryingByMappedName(mappedName, &baseUserName, &isArray)) { baseUserName = baseMappedName; if (needsCheckForArrays && !isArray) { std::string mappedNameStr = baseMappedName.BeginReading(); mappedNameStr += "[0]"; GLuint loc = gl->fGetUniformBlockIndex(prog->mGLName, mappedNameStr.c_str()); if (loc != LOCAL_GL_INVALID_INDEX) isArray = true; } } //// const RefPtr<WebGLActiveInfo> activeInfo = new WebGLActiveInfo(webgl, elemCount, elemType, isArray, baseUserName, mappedName); info->transformFeedbackVaryings.push_back(activeInfo); } } // Frag outputs prog->EnumerateFragOutputs(info->fragDataMap); return info.forget(); }
void LayerManagerComposite::Render(const nsIntRegion& aInvalidRegion) { PROFILER_LABEL("LayerManagerComposite", "Render", js::ProfileEntry::Category::GRAPHICS); if (mDestroyed) { NS_WARNING("Call on destroyed layer manager"); return; } // At this time, it doesn't really matter if these preferences change // during the execution of the function; we should be safe in all // permutations. However, may as well just get the values onces and // then use them, just in case the consistency becomes important in // the future. bool invertVal = gfxPrefs::LayersEffectInvert(); bool grayscaleVal = gfxPrefs::LayersEffectGrayscale(); float contrastVal = gfxPrefs::LayersEffectContrast(); bool haveLayerEffects = (invertVal || grayscaleVal || contrastVal != 0.0); // Set LayerScope begin/end frame LayerScopeAutoFrame frame(PR_Now()); // Dump to console if (gfxPrefs::LayersDump()) { this->Dump(); } else if (profiler_feature_active("layersdump")) { std::stringstream ss; Dump(ss); profiler_log(ss.str().c_str()); } // Dump to LayerScope Viewer if (LayerScope::CheckSendable()) { // Create a LayersPacket, dump Layers into it and transfer the // packet('s ownership) to LayerScope. auto packet = MakeUnique<layerscope::Packet>(); layerscope::LayersPacket* layersPacket = packet->mutable_layers(); this->Dump(layersPacket); LayerScope::SendLayerDump(Move(packet)); } /** Our more efficient but less powerful alter ego, if one is available. */ RefPtr<Composer2D> composer2D; composer2D = mCompositor->GetWidget()->GetComposer2D(); // We can't use composert2D if we have layer effects if (!mTarget && !haveLayerEffects && gfxPrefs::Composer2DCompositionEnabled() && composer2D && composer2D->HasHwc() && composer2D->TryRenderWithHwc(mRoot, mCompositor->GetWidget(), mGeometryChanged)) { LayerScope::SetHWComposed(); if (mFPS) { double fps = mFPS->mCompositionFps.AddFrameAndGetFps(TimeStamp::Now()); if (gfxPrefs::LayersDrawFPS()) { printf_stderr("HWComposer: FPS is %g\n", fps); } } mCompositor->EndFrameForExternalComposition(Matrix()); mLastFrameMissedHWC = false; return; } else if (!mTarget && !haveLayerEffects) { mLastFrameMissedHWC = !!composer2D; } { PROFILER_LABEL("LayerManagerComposite", "PreRender", js::ProfileEntry::Category::GRAPHICS); if (!mCompositor->GetWidget()->PreRender(this)) { return; } } ParentLayerIntRect clipRect; Rect bounds(mRenderBounds.x, mRenderBounds.y, mRenderBounds.width, mRenderBounds.height); Rect actualBounds; CompositorBench(mCompositor, bounds); if (mRoot->GetClipRect()) { clipRect = *mRoot->GetClipRect(); Rect rect(clipRect.x, clipRect.y, clipRect.width, clipRect.height); mCompositor->BeginFrame(aInvalidRegion, &rect, bounds, nullptr, &actualBounds); } else { gfx::Rect rect; mCompositor->BeginFrame(aInvalidRegion, nullptr, bounds, &rect, &actualBounds); clipRect = ParentLayerIntRect(rect.x, rect.y, rect.width, rect.height); } if (actualBounds.IsEmpty()) { mCompositor->GetWidget()->PostRender(this); return; } // Allow widget to render a custom background. mCompositor->GetWidget()->DrawWindowUnderlay(this, IntRect(actualBounds.x, actualBounds.y, actualBounds.width, actualBounds.height)); RefPtr<CompositingRenderTarget> previousTarget; if (haveLayerEffects) { previousTarget = PushGroupForLayerEffects(); } else { mTwoPassTmpTarget = nullptr; } // Render our layers. RootLayer()->Prepare(ViewAs<RenderTargetPixel>(clipRect, PixelCastJustification::RenderTargetIsParentLayerForRoot)); RootLayer()->RenderLayer(clipRect.ToUnknownRect()); if (!mRegionToClear.IsEmpty()) { nsIntRegionRectIterator iter(mRegionToClear); const IntRect *r; while ((r = iter.Next())) { mCompositor->ClearRect(Rect(r->x, r->y, r->width, r->height)); } } if (mTwoPassTmpTarget) { MOZ_ASSERT(haveLayerEffects); PopGroupForLayerEffects(previousTarget, clipRect.ToUnknownRect(), grayscaleVal, invertVal, contrastVal); } // Allow widget to render a custom foreground. mCompositor->GetWidget()->DrawWindowOverlay( this, LayoutDeviceIntRect(actualBounds.x, actualBounds.y, actualBounds.width, actualBounds.height)); // Debugging RenderDebugOverlay(actualBounds); { PROFILER_LABEL("LayerManagerComposite", "EndFrame", js::ProfileEntry::Category::GRAPHICS); mCompositor->EndFrame(); mCompositor->SetDispAcquireFence(mRoot, mCompositor->GetWidget()); // Call after EndFrame() } if (composer2D) { composer2D->Render(mCompositor->GetWidget()); } mCompositor->GetWidget()->PostRender(this); RecordFrame(); }
bool LayerTransactionParent::RecvUpdate(const InfallibleTArray<Edit>& cset, const uint64_t& aTransactionId, const TargetConfig& targetConfig, const bool& isFirstPaint, const bool& scheduleComposite, const uint32_t& paintSequenceNumber, InfallibleTArray<EditReply>* reply) { profiler_tracing("Paint", "Composite", TRACING_INTERVAL_START); PROFILER_LABEL("LayerTransactionParent", "RecvUpdate", js::ProfileEntry::Category::GRAPHICS); #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; } if (mLayerManager && mLayerManager->GetCompositor() && !targetConfig.naturalBounds().IsEmpty()) { mLayerManager->GetCompositor()->SetScreenRotation(targetConfig.rotation()); } EditReplyVector replyv; { AutoResolveRefLayers resolve(mShadowLayersManager->GetCompositionManager(this)); 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())); layer->SetMixBlendMode((gfx::CompositionOp)common.mixBlendMode()); layer->SetForceIsolatedGroup(common.forceIsolatedGroup()); 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->SetScrollHandoffParentId(attrs.scrollParentId()); containerLayer->SetPreScale(attrs.preXScale(), attrs.preYScale()); containerLayer->SetInheritedScale(attrs.inheritedXScale(), attrs.inheritedYScale()); containerLayer->SetBackgroundColor(attrs.backgroundColor().value()); 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) { return false; } if (newRoot->GetParent()) { // newRoot is not a root! 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: { if (!ReceiveCompositableUpdate(edit.get_CompositableOperation(), replyv)) { return false; } break; } case Edit::TOpAttachCompositable: { const OpAttachCompositable& op = edit.get_OpAttachCompositable(); CompositableHost* host = CompositableHost::FromIPDLActor(op.compositableParent()); if (!Attach(cast(op.layerParent()), host, false)) { return false; } host->SetCompositorID(mLayerManager->GetCompositor()->GetCompositorID()); break; } case Edit::TOpAttachAsyncCompositable: { const OpAttachAsyncCompositable& op = edit.get_OpAttachAsyncCompositable(); PCompositableParent* compositableParent = CompositableMap::Get(op.containerID()); if (!compositableParent) { NS_ERROR("CompositableParent not found in the map"); return false; } CompositableHost* host = CompositableHost::FromIPDLActor(compositableParent); if (!Attach(cast(op.layerParent()), host, true)) { return false; } host->SetCompositorID(mLayerManager->GetCompositor()->GetCompositorID()); break; } default: NS_RUNTIMEABORT("not reached"); } } mShadowLayersManager->ShadowLayersUpdated(this, aTransactionId, targetConfig, isFirstPaint, scheduleComposite, paintSequenceNumber); { AutoResolveRefLayers resolve(mShadowLayersManager->GetCompositionManager(this)); 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()); } } if (!IsSameProcess()) { // 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(); } #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 GLLibraryEGL::EnsureInitialized(bool forceAccel) { if (mInitialized) { return true; } mozilla::ScopedGfxFeatureReporter reporter("EGL"); #ifdef MOZ_B2G if (!sCurrentContext.init()) MOZ_CRASH("GFX: Tls init failed"); #endif #ifdef XP_WIN if (!mEGLLibrary) { // On Windows, the GLESv2, EGL and DXSDK libraries are shipped with libxul and // we should look for them there. We have to load the libs in this // order, because libEGL.dll depends on libGLESv2.dll which depends on the DXSDK // libraries. This matters especially for WebRT apps which are in a different directory. // See bug 760323 and bug 749459 // Also note that we intentionally leak the libs we load. do { // Windows 8.1 has d3dcompiler_47.dll in the system directory. // Try it first. Note that _46 will never be in the system // directory and we ship with at least _43. So there is no point // trying _46 and _43 in the system directory. if (LoadLibrarySystem32(L"d3dcompiler_47.dll")) break; #ifdef MOZ_D3DCOMPILER_VISTA_DLL if (LoadLibraryForEGLOnWindows(NS_LITERAL_STRING(NS_STRINGIFY(MOZ_D3DCOMPILER_VISTA_DLL)))) break; #endif #ifdef MOZ_D3DCOMPILER_XP_DLL if (LoadLibraryForEGLOnWindows(NS_LITERAL_STRING(NS_STRINGIFY(MOZ_D3DCOMPILER_XP_DLL)))) break; #endif MOZ_ASSERT(false, "d3dcompiler DLL loading failed."); } while (false); LoadLibraryForEGLOnWindows(NS_LITERAL_STRING("libGLESv2.dll")); mEGLLibrary = LoadLibraryForEGLOnWindows(NS_LITERAL_STRING("libEGL.dll")); if (!mEGLLibrary) return false; } #else // !Windows // On non-Windows (Android) we use system copies of libEGL. We look for // the APITrace lib, libEGL.so, and libEGL.so.1 in that order. #if defined(ANDROID) if (!mEGLLibrary) mEGLLibrary = LoadApitraceLibrary(); #endif if (!mEGLLibrary) { printf_stderr("Attempting load of libEGL.so\n"); mEGLLibrary = PR_LoadLibrary("libEGL.so"); } #if defined(XP_UNIX) if (!mEGLLibrary) { mEGLLibrary = PR_LoadLibrary("libEGL.so.1"); } #endif if (!mEGLLibrary) { NS_WARNING("Couldn't load EGL LIB."); return false; } #endif // !Windows #define SYMBOL(name) \ { (PRFuncPtr*) &mSymbols.f##name, { "egl" #name, nullptr } } GLLibraryLoader::SymLoadStruct earlySymbols[] = { SYMBOL(GetDisplay), SYMBOL(Terminate), SYMBOL(GetCurrentSurface), SYMBOL(GetCurrentContext), SYMBOL(MakeCurrent), SYMBOL(DestroyContext), SYMBOL(CreateContext), SYMBOL(DestroySurface), SYMBOL(CreateWindowSurface), SYMBOL(CreatePbufferSurface), SYMBOL(CreatePixmapSurface), SYMBOL(BindAPI), SYMBOL(Initialize), SYMBOL(ChooseConfig), SYMBOL(GetError), SYMBOL(GetConfigs), SYMBOL(GetConfigAttrib), SYMBOL(WaitNative), SYMBOL(GetProcAddress), SYMBOL(SwapBuffers), SYMBOL(CopyBuffers), SYMBOL(QueryString), SYMBOL(QueryContext), SYMBOL(BindTexImage), SYMBOL(ReleaseTexImage), SYMBOL(QuerySurface), { nullptr, { nullptr } } }; if (!GLLibraryLoader::LoadSymbols(mEGLLibrary, &earlySymbols[0])) { NS_WARNING("Couldn't find required entry points in EGL library (early init)"); return false; } GLLibraryLoader::SymLoadStruct optionalSymbols[] = { // On Android 4.3 and up, certain features like ANDROID_native_fence_sync // can only be queried by using a special eglQueryString. { (PRFuncPtr*) &mSymbols.fQueryStringImplementationANDROID, { "_Z35eglQueryStringImplementationANDROIDPvi", nullptr } }, { nullptr, { nullptr } } }; // Do not warn about the failure to load this - see bug 1092191 Unused << GLLibraryLoader::LoadSymbols(mEGLLibrary, &optionalSymbols[0], nullptr, nullptr, false); #if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 18 MOZ_RELEASE_ASSERT(mSymbols.fQueryStringImplementationANDROID, "Couldn't find eglQueryStringImplementationANDROID"); #endif InitClientExtensions(); const auto lookupFunction = (GLLibraryLoader::PlatformLookupFunction)mSymbols.fGetProcAddress; // Client exts are ready. (But not display exts!) if (IsExtensionSupported(ANGLE_platform_angle_d3d)) { GLLibraryLoader::SymLoadStruct d3dSymbols[] = { { (PRFuncPtr*)&mSymbols.fGetPlatformDisplayEXT, { "eglGetPlatformDisplayEXT", nullptr } }, { nullptr, { nullptr } } }; bool success = GLLibraryLoader::LoadSymbols(mEGLLibrary, &d3dSymbols[0], lookupFunction); if (!success) { NS_ERROR("EGL supports ANGLE_platform_angle_d3d without exposing its functions!"); MarkExtensionUnsupported(ANGLE_platform_angle_d3d); mSymbols.fGetPlatformDisplayEXT = nullptr; } } // Check the ANGLE support the system has nsCOMPtr<nsIGfxInfo> gfxInfo = do_GetService("@mozilla.org/gfx/info;1"); mIsANGLE = IsExtensionSupported(ANGLE_platform_angle); EGLDisplay chosenDisplay = nullptr; if (IsExtensionSupported(ANGLE_platform_angle_d3d)) { bool accelAngleSupport = IsAccelAngleSupported(gfxInfo); bool shouldTryAccel = forceAccel || accelAngleSupport; bool shouldTryWARP = !shouldTryAccel; if (gfxPrefs::WebGLANGLEForceWARP()) { shouldTryWARP = true; shouldTryAccel = false; } // Fallback to a WARP display if non-WARP is blacklisted, or if WARP is forced. if (shouldTryWARP) { chosenDisplay = GetAndInitWARPDisplay(*this, EGL_DEFAULT_DISPLAY); if (chosenDisplay) { mIsWARP = true; } } if (!chosenDisplay) { // If falling back to WARP did not work and we don't want to try // using HW accelerated ANGLE, then fail. if (!shouldTryAccel) { NS_ERROR("Fallback WARP ANGLE context failed to initialize."); return false; } // Hardware accelerated ANGLE path chosenDisplay = GetAndInitDisplayForAccelANGLE(*this); } } else { chosenDisplay = GetAndInitDisplay(*this, EGL_DEFAULT_DISPLAY); } if (!chosenDisplay) { NS_WARNING("Failed to initialize a display."); return false; } mEGLDisplay = chosenDisplay; InitDisplayExtensions(); //////////////////////////////////// // Alright, load display exts. if (IsExtensionSupported(KHR_lock_surface)) { GLLibraryLoader::SymLoadStruct lockSymbols[] = { { (PRFuncPtr*) &mSymbols.fLockSurface, { "eglLockSurfaceKHR", nullptr } }, { (PRFuncPtr*) &mSymbols.fUnlockSurface, { "eglUnlockSurfaceKHR", nullptr } }, { nullptr, { nullptr } } }; bool success = GLLibraryLoader::LoadSymbols(mEGLLibrary, &lockSymbols[0], lookupFunction); if (!success) { NS_ERROR("EGL supports KHR_lock_surface without exposing its functions!"); MarkExtensionUnsupported(KHR_lock_surface); mSymbols.fLockSurface = nullptr; mSymbols.fUnlockSurface = nullptr; } } if (IsExtensionSupported(ANGLE_surface_d3d_texture_2d_share_handle)) { GLLibraryLoader::SymLoadStruct d3dSymbols[] = { { (PRFuncPtr*) &mSymbols.fQuerySurfacePointerANGLE, { "eglQuerySurfacePointerANGLE", nullptr } }, { nullptr, { nullptr } } }; bool success = GLLibraryLoader::LoadSymbols(mEGLLibrary, &d3dSymbols[0], lookupFunction); if (!success) { NS_ERROR("EGL supports ANGLE_surface_d3d_texture_2d_share_handle without exposing its functions!"); MarkExtensionUnsupported(ANGLE_surface_d3d_texture_2d_share_handle); mSymbols.fQuerySurfacePointerANGLE = nullptr; } } if (IsExtensionSupported(KHR_fence_sync)) { GLLibraryLoader::SymLoadStruct syncSymbols[] = { { (PRFuncPtr*) &mSymbols.fCreateSync, { "eglCreateSyncKHR", nullptr } }, { (PRFuncPtr*) &mSymbols.fDestroySync, { "eglDestroySyncKHR", nullptr } }, { (PRFuncPtr*) &mSymbols.fClientWaitSync, { "eglClientWaitSyncKHR", nullptr } }, { (PRFuncPtr*) &mSymbols.fGetSyncAttrib, { "eglGetSyncAttribKHR", nullptr } }, { nullptr, { nullptr } } }; bool success = GLLibraryLoader::LoadSymbols(mEGLLibrary, &syncSymbols[0], lookupFunction); if (!success) { NS_ERROR("EGL supports KHR_fence_sync without exposing its functions!"); MarkExtensionUnsupported(KHR_fence_sync); mSymbols.fCreateSync = nullptr; mSymbols.fDestroySync = nullptr; mSymbols.fClientWaitSync = nullptr; mSymbols.fGetSyncAttrib = nullptr; } } if (IsExtensionSupported(KHR_image) || IsExtensionSupported(KHR_image_base)) { GLLibraryLoader::SymLoadStruct imageSymbols[] = { { (PRFuncPtr*) &mSymbols.fCreateImage, { "eglCreateImageKHR", nullptr } }, { (PRFuncPtr*) &mSymbols.fDestroyImage, { "eglDestroyImageKHR", nullptr } }, { nullptr, { nullptr } } }; bool success = GLLibraryLoader::LoadSymbols(mEGLLibrary, &imageSymbols[0], lookupFunction); if (!success) { NS_ERROR("EGL supports KHR_image(_base) without exposing its functions!"); MarkExtensionUnsupported(KHR_image); MarkExtensionUnsupported(KHR_image_base); MarkExtensionUnsupported(KHR_image_pixmap); mSymbols.fCreateImage = nullptr; mSymbols.fDestroyImage = nullptr; } } else { MarkExtensionUnsupported(KHR_image_pixmap); } if (IsExtensionSupported(ANDROID_native_fence_sync)) { GLLibraryLoader::SymLoadStruct nativeFenceSymbols[] = { { (PRFuncPtr*) &mSymbols.fDupNativeFenceFDANDROID, { "eglDupNativeFenceFDANDROID", nullptr } }, { nullptr, { nullptr } } }; bool success = GLLibraryLoader::LoadSymbols(mEGLLibrary, &nativeFenceSymbols[0], lookupFunction); if (!success) { NS_ERROR("EGL supports ANDROID_native_fence_sync without exposing its functions!"); MarkExtensionUnsupported(ANDROID_native_fence_sync); mSymbols.fDupNativeFenceFDANDROID = nullptr; } } mInitialized = true; reporter.SetSuccessful(); return true; }