Bug 1265824 - Pass the texture direct mapping info to all texture creating functions r=mattwoodrow

The client side can't get the GL context in CompositorOGL. So, it can't know
the texture direct mapping capability directly. This patch adds the texture
direct mapping info in TextureFactoryIdentifier. Then, the client side could
get the info form the TextureFactoryIdentifier.

MozReview-Commit-ID: KEazDVg0p9Y

--HG--
extra : rebase_source : 425159494772431283138bbaa4574c6201a2bc59
This commit is contained in:
Doug Thayer 2018-05-02 18:20:25 -07:00
parent 40c168f2fd
commit 1cfb8ec041
14 changed files with 92 additions and 12 deletions

View File

@ -105,8 +105,13 @@ static bool UsingX11Compositor()
} }
bool ComputeHasIntermediateBuffer(gfx::SurfaceFormat aFormat, bool ComputeHasIntermediateBuffer(gfx::SurfaceFormat aFormat,
LayersBackend aLayersBackend) LayersBackend aLayersBackend,
bool aSupportsTextureDirectMapping)
{ {
if (aSupportsTextureDirectMapping) {
return false;
}
return aLayersBackend != LayersBackend::LAYERS_BASIC return aLayersBackend != LayersBackend::LAYERS_BASIC
|| UsingX11Compositor() || UsingX11Compositor()
|| aFormat == gfx::SurfaceFormat::UNKNOWN; || aFormat == gfx::SurfaceFormat::UNKNOWN;
@ -168,7 +173,8 @@ BufferTextureData::CreateForYCbCrWithBufferSize(KnowsCompositor* aAllocator,
} }
bool hasIntermediateBuffer = aAllocator ? ComputeHasIntermediateBuffer(gfx::SurfaceFormat::YUV, bool hasIntermediateBuffer = aAllocator ? ComputeHasIntermediateBuffer(gfx::SurfaceFormat::YUV,
aAllocator->GetCompositorBackendType()) aAllocator->GetCompositorBackendType(),
aAllocator->SupportsTextureDirectMapping())
: true; : true;
// Initialize the metadata with something, even if it will have to be rewritten // Initialize the metadata with something, even if it will have to be rewritten
@ -210,7 +216,8 @@ BufferTextureData::CreateForYCbCr(KnowsCompositor* aAllocator,
bool hasIntermediateBuffer = bool hasIntermediateBuffer =
aAllocator aAllocator
? ComputeHasIntermediateBuffer(gfx::SurfaceFormat::YUV, ? ComputeHasIntermediateBuffer(gfx::SurfaceFormat::YUV,
aAllocator->GetCompositorBackendType()) aAllocator->GetCompositorBackendType(),
aAllocator->SupportsTextureDirectMapping())
: true; : true;
YCbCrDescriptor descriptor = YCbCrDescriptor(aYSize, aYStride, YCbCrDescriptor descriptor = YCbCrDescriptor(aYSize, aYStride,
@ -525,7 +532,9 @@ MemoryTextureData::Create(gfx::IntSize aSize, gfx::SurfaceFormat aFormat,
return nullptr; return nullptr;
} }
bool hasIntermediateBuffer = ComputeHasIntermediateBuffer(aFormat, aLayersBackend); bool hasIntermediateBuffer = ComputeHasIntermediateBuffer(aFormat,
aLayersBackend,
aAllocFlags & ALLOC_ALLOW_DIRECT_MAPPING);
GfxMemoryImageReporter::DidAlloc(buf); GfxMemoryImageReporter::DidAlloc(buf);
@ -601,7 +610,9 @@ ShmemTextureData::Create(gfx::IntSize aSize, gfx::SurfaceFormat aFormat,
return nullptr; return nullptr;
} }
bool hasIntermediateBuffer = ComputeHasIntermediateBuffer(aFormat, aLayersBackend); bool hasIntermediateBuffer = ComputeHasIntermediateBuffer(aFormat,
aLayersBackend,
aAllocFlags & ALLOC_ALLOW_DIRECT_MAPPING);
BufferDescriptor descriptor = RGBDescriptor(aSize, aFormat, hasIntermediateBuffer); BufferDescriptor descriptor = RGBDescriptor(aSize, aFormat, hasIntermediateBuffer);

View File

@ -17,7 +17,8 @@ namespace mozilla {
namespace layers { namespace layers {
bool ComputeHasIntermediateBuffer(gfx::SurfaceFormat aFormat, bool ComputeHasIntermediateBuffer(gfx::SurfaceFormat aFormat,
LayersBackend aLayersBackend); LayersBackend aLayersBackend,
bool aSupportsTextureDirectMapping);
class BufferTextureData : public TextureData class BufferTextureData : public TextureData
{ {

View File

@ -175,6 +175,7 @@ struct TextureFactoryIdentifier
LayersBackend mParentBackend; LayersBackend mParentBackend;
GeckoProcessType mParentProcessType; GeckoProcessType mParentProcessType;
int32_t mMaxTextureSize; int32_t mMaxTextureSize;
bool mSupportsTextureDirectMapping;
bool mCompositorUseANGLE; bool mCompositorUseANGLE;
bool mCompositorUseDComp; bool mCompositorUseDComp;
bool mSupportsTextureBlitting; bool mSupportsTextureBlitting;
@ -186,6 +187,7 @@ struct TextureFactoryIdentifier
explicit TextureFactoryIdentifier(LayersBackend aLayersBackend = LayersBackend::LAYERS_NONE, explicit TextureFactoryIdentifier(LayersBackend aLayersBackend = LayersBackend::LAYERS_NONE,
GeckoProcessType aParentProcessType = GeckoProcessType_Default, GeckoProcessType aParentProcessType = GeckoProcessType_Default,
int32_t aMaxTextureSize = 4096, int32_t aMaxTextureSize = 4096,
bool aSupportsTextureDirectMapping = false,
bool aCompositorUseANGLE = false, bool aCompositorUseANGLE = false,
bool aCompositorUseDComp = false, bool aCompositorUseDComp = false,
bool aSupportsTextureBlitting = false, bool aSupportsTextureBlitting = false,
@ -195,6 +197,7 @@ struct TextureFactoryIdentifier
: mParentBackend(aLayersBackend) : mParentBackend(aLayersBackend)
, mParentProcessType(aParentProcessType) , mParentProcessType(aParentProcessType)
, mMaxTextureSize(aMaxTextureSize) , mMaxTextureSize(aMaxTextureSize)
, mSupportsTextureDirectMapping(aSupportsTextureDirectMapping)
, mCompositorUseANGLE(aCompositorUseANGLE) , mCompositorUseANGLE(aCompositorUseANGLE)
, mCompositorUseDComp(aCompositorUseDComp) , mCompositorUseDComp(aCompositorUseDComp)
, mSupportsTextureBlitting(aSupportsTextureBlitting) , mSupportsTextureBlitting(aSupportsTextureBlitting)
@ -209,11 +212,13 @@ struct TextureFactoryIdentifier
mParentBackend == aOther.mParentBackend && mParentBackend == aOther.mParentBackend &&
mParentProcessType == aOther.mParentProcessType && mParentProcessType == aOther.mParentProcessType &&
mMaxTextureSize == aOther.mMaxTextureSize && mMaxTextureSize == aOther.mMaxTextureSize &&
mSupportsTextureDirectMapping == aOther.mSupportsTextureDirectMapping &&
mCompositorUseANGLE == aOther.mCompositorUseANGLE && mCompositorUseANGLE == aOther.mCompositorUseANGLE &&
mCompositorUseDComp == aOther.mCompositorUseDComp && mCompositorUseDComp == aOther.mCompositorUseDComp &&
mSupportsTextureBlitting == aOther.mSupportsTextureBlitting && mSupportsTextureBlitting == aOther.mSupportsTextureBlitting &&
mSupportsPartialUploads == aOther.mSupportsPartialUploads && mSupportsPartialUploads == aOther.mSupportsPartialUploads &&
mSupportsComponentAlpha == aOther.mSupportsComponentAlpha && mSupportsComponentAlpha == aOther.mSupportsComponentAlpha &&
mUsingAdvancedLayers == aOther.mUsingAdvancedLayers &&
mSyncHandle == aOther.mSyncHandle; mSyncHandle == aOther.mSyncHandle;
} }
}; };

View File

@ -762,10 +762,14 @@ ContentClientRemoteBuffer::CreateBufferInternal(const gfx::IntRect& aRect,
RefPtr<TextureClient> textureClientOnWhite; RefPtr<TextureClient> textureClientOnWhite;
if (aFlags & TextureFlags::COMPONENT_ALPHA) { if (aFlags & TextureFlags::COMPONENT_ALPHA) {
TextureAllocationFlags allocFlags = ALLOC_CLEAR_BUFFER_WHITE;
if (mForwarder->SupportsTextureDirectMapping()) {
allocFlags = TextureAllocationFlags(allocFlags | ALLOC_ALLOW_DIRECT_MAPPING);
}
textureClientOnWhite = textureClient->CreateSimilar( textureClientOnWhite = textureClient->CreateSimilar(
mForwarder->GetCompositorBackendType(), mForwarder->GetCompositorBackendType(),
aFlags | ExtraTextureFlags(), aFlags | ExtraTextureFlags(),
TextureAllocationFlags::ALLOC_CLEAR_BUFFER_WHITE allocFlags
); );
if (!textureClientOnWhite || !AddTextureClient(textureClientOnWhite)) { if (!textureClientOnWhite || !AddTextureClient(textureClientOnWhite)) {
return nullptr; return nullptr;

View File

@ -660,7 +660,9 @@ TextureClient::UpdateFromSurface(gfx::SourceSurface* aSurface)
already_AddRefed<TextureClient> already_AddRefed<TextureClient>
TextureClient::CreateSimilar(LayersBackend aLayersBackend, TextureFlags aFlags, TextureAllocationFlags aAllocFlags) const TextureClient::CreateSimilar(LayersBackend aLayersBackend,
TextureFlags aFlags,
TextureAllocationFlags aAllocFlags) const
{ {
MOZ_ASSERT(IsValid()); MOZ_ASSERT(IsValid());
@ -670,7 +672,10 @@ TextureClient::CreateSimilar(LayersBackend aLayersBackend, TextureFlags aFlags,
} }
LockActor(); LockActor();
TextureData* data = mData->CreateSimilar(mAllocator, aLayersBackend, aFlags, aAllocFlags); TextureData* data = mData->CreateSimilar(mAllocator,
aLayersBackend,
aFlags,
aAllocFlags);
UnlockActor(); UnlockActor();
if (!data) { if (!data) {
@ -1060,6 +1065,9 @@ TextureClient::CreateForDrawing(KnowsCompositor* aAllocator,
TextureAllocationFlags aAllocFlags) TextureAllocationFlags aAllocFlags)
{ {
LayersBackend layersBackend = aAllocator->GetCompositorBackendType(); LayersBackend layersBackend = aAllocator->GetCompositorBackendType();
if (aAllocator->SupportsTextureDirectMapping()) {
aAllocFlags = TextureAllocationFlags(aAllocFlags | ALLOC_ALLOW_DIRECT_MAPPING);
}
return TextureClient::CreateForDrawing(aAllocator->GetTextureForwarder(), return TextureClient::CreateForDrawing(aAllocator->GetTextureForwarder(),
aFormat, aSize, aFormat, aSize,
layersBackend, layersBackend,
@ -1226,6 +1234,16 @@ TextureClient::CreateForRawBufferAccess(KnowsCompositor* aAllocator,
TextureFlags aTextureFlags, TextureFlags aTextureFlags,
TextureAllocationFlags aAllocFlags) TextureAllocationFlags aAllocFlags)
{ {
// If we exceed the max texture size for the GPU, then just fall back to no
// texture direct mapping. If it becomes a problem we can implement tiling
// logic inside DirectMapTextureSource to allow this.
bool supportsTextureDirectMapping = aAllocator->SupportsTextureDirectMapping() &&
std::max(aSize.width, aSize.height) <= aAllocator->GetMaxTextureSize();
if (supportsTextureDirectMapping) {
aAllocFlags = TextureAllocationFlags(aAllocFlags | ALLOC_ALLOW_DIRECT_MAPPING);
} else {
aAllocFlags = TextureAllocationFlags(aAllocFlags & ~ALLOC_ALLOW_DIRECT_MAPPING);
}
return CreateForRawBufferAccess(aAllocator->GetTextureForwarder(), return CreateForRawBufferAccess(aAllocator->GetTextureForwarder(),
aFormat, aSize, aMoz2DBackend, aFormat, aSize, aMoz2DBackend,
aAllocator->GetCompositorBackendType(), aAllocator->GetCompositorBackendType(),

View File

@ -94,6 +94,10 @@ enum TextureAllocationFlags {
// The texture is going to be updated using UpdateFromSurface and needs to support // The texture is going to be updated using UpdateFromSurface and needs to support
// that call. // that call.
ALLOC_UPDATE_FROM_SURFACE = 1 << 7, ALLOC_UPDATE_FROM_SURFACE = 1 << 7,
// In practice, this means we support the APPLE_client_storage extension, meaning
// the buffer will not be internally copied by the graphics driver.
ALLOC_ALLOW_DIRECT_MAPPING = 1 << 8,
}; };
/** /**

View File

@ -39,6 +39,7 @@ ClearCallback(nsITimer *aTimer, void *aClosure)
} }
TextureClientPool::TextureClientPool(LayersBackend aLayersBackend, TextureClientPool::TextureClientPool(LayersBackend aLayersBackend,
bool aSupportsTextureDirectMapping,
int32_t aMaxTextureSize, int32_t aMaxTextureSize,
gfx::SurfaceFormat aFormat, gfx::SurfaceFormat aFormat,
gfx::IntSize aSize, gfx::IntSize aSize,
@ -60,6 +61,7 @@ TextureClientPool::TextureClientPool(LayersBackend aLayersBackend,
, mOutstandingClients(0) , mOutstandingClients(0)
, mSurfaceAllocator(aAllocator) , mSurfaceAllocator(aAllocator)
, mDestroyed(false) , mDestroyed(false)
, mSupportsTextureDirectMapping(aSupportsTextureDirectMapping)
{ {
TCP_LOG("TexturePool %p created with maximum unused texture clients %u\n", TCP_LOG("TexturePool %p created with maximum unused texture clients %u\n",
this, mInitialPoolSize); this, mInitialPoolSize);
@ -149,6 +151,12 @@ TextureClientPool::AllocateTextureClient()
TCP_LOG("TexturePool %p allocating TextureClient, outstanding %u\n", TCP_LOG("TexturePool %p allocating TextureClient, outstanding %u\n",
this, mOutstandingClients); this, mOutstandingClients);
TextureAllocationFlags allocFlags = ALLOC_DEFAULT;
if (mSupportsTextureDirectMapping) {
allocFlags = TextureAllocationFlags(allocFlags | ALLOC_ALLOW_DIRECT_MAPPING);
}
RefPtr<TextureClient> newClient; RefPtr<TextureClient> newClient;
if (gfxPrefs::ForceShmemTiles()) { if (gfxPrefs::ForceShmemTiles()) {
// gfx::BackendType::NONE means use the content backend // gfx::BackendType::NONE means use the content backend
@ -157,7 +165,7 @@ TextureClientPool::AllocateTextureClient()
mFormat, mSize, mFormat, mSize,
gfx::BackendType::NONE, gfx::BackendType::NONE,
mBackend, mBackend,
mFlags, ALLOC_DEFAULT); mFlags, allocFlags);
} else { } else {
newClient = newClient =
TextureClient::CreateForDrawing(mSurfaceAllocator, TextureClient::CreateForDrawing(mSurfaceAllocator,
@ -165,7 +173,7 @@ TextureClientPool::AllocateTextureClient()
mBackend, mBackend,
mMaxTextureSize, mMaxTextureSize,
BackendSelector::Content, BackendSelector::Content,
mFlags); mFlags, allocFlags);
} }
if (newClient) { if (newClient) {

View File

@ -46,6 +46,7 @@ class TextureClientPool final : public TextureClientAllocator
public: public:
TextureClientPool(LayersBackend aBackend, TextureClientPool(LayersBackend aBackend,
bool aSupportsTextureDirectMapping,
int32_t aMaxTextureSize, int32_t aMaxTextureSize,
gfx::SurfaceFormat aFormat, gfx::SurfaceFormat aFormat,
gfx::IntSize aSize, gfx::IntSize aSize,
@ -170,6 +171,8 @@ private:
// we won't accept returns of TextureClients anymore, and the refcounting // we won't accept returns of TextureClients anymore, and the refcounting
// should take care of their destruction. // should take care of their destruction.
bool mDestroyed; bool mDestroyed;
bool mSupportsTextureDirectMapping;
}; };
} // namespace layers } // namespace layers

View File

@ -936,6 +936,7 @@ CompositorBridgeChild::GetTexturePool(KnowsCompositor* aAllocator,
mTexturePools.AppendElement( mTexturePools.AppendElement(
new TextureClientPool(aAllocator->GetCompositorBackendType(), new TextureClientPool(aAllocator->GetCompositorBackendType(),
aAllocator->SupportsTextureDirectMapping(),
aAllocator->GetMaxTextureSize(), aAllocator->GetMaxTextureSize(),
aFormat, aFormat,
gfx::gfxVars::TileSize(), gfx::gfxVars::TileSize(),

View File

@ -102,6 +102,11 @@ public:
return mTextureFactoryIdentifier.mSupportsComponentAlpha; return mTextureFactoryIdentifier.mSupportsComponentAlpha;
} }
bool SupportsTextureDirectMapping() const
{
return mTextureFactoryIdentifier.mSupportsTextureDirectMapping;
}
bool SupportsD3D11() const bool SupportsD3D11() const
{ {
return GetCompositorBackendType() == layers::LayersBackend::LAYERS_D3D11 || return GetCompositorBackendType() == layers::LayersBackend::LAYERS_D3D11 ||

View File

@ -335,6 +335,7 @@ struct ParamTraits<mozilla::layers::TextureFactoryIdentifier>
WriteParam(aMsg, aParam.mParentBackend); WriteParam(aMsg, aParam.mParentBackend);
WriteParam(aMsg, aParam.mParentProcessType); WriteParam(aMsg, aParam.mParentProcessType);
WriteParam(aMsg, aParam.mMaxTextureSize); WriteParam(aMsg, aParam.mMaxTextureSize);
WriteParam(aMsg, aParam.mSupportsTextureDirectMapping);
WriteParam(aMsg, aParam.mCompositorUseANGLE); WriteParam(aMsg, aParam.mCompositorUseANGLE);
WriteParam(aMsg, aParam.mCompositorUseDComp); WriteParam(aMsg, aParam.mCompositorUseDComp);
WriteParam(aMsg, aParam.mSupportsTextureBlitting); WriteParam(aMsg, aParam.mSupportsTextureBlitting);
@ -349,6 +350,7 @@ struct ParamTraits<mozilla::layers::TextureFactoryIdentifier>
bool result = ReadParam(aMsg, aIter, &aResult->mParentBackend) && bool result = ReadParam(aMsg, aIter, &aResult->mParentBackend) &&
ReadParam(aMsg, aIter, &aResult->mParentProcessType) && ReadParam(aMsg, aIter, &aResult->mParentProcessType) &&
ReadParam(aMsg, aIter, &aResult->mMaxTextureSize) && ReadParam(aMsg, aIter, &aResult->mMaxTextureSize) &&
ReadParam(aMsg, aIter, &aResult->mSupportsTextureDirectMapping) &&
ReadParam(aMsg, aIter, &aResult->mCompositorUseANGLE) && ReadParam(aMsg, aIter, &aResult->mCompositorUseANGLE) &&
ReadParam(aMsg, aIter, &aResult->mCompositorUseDComp) && ReadParam(aMsg, aIter, &aResult->mCompositorUseDComp) &&
ReadParam(aMsg, aIter, &aResult->mSupportsTextureBlitting) && ReadParam(aMsg, aIter, &aResult->mSupportsTextureBlitting) &&

View File

@ -115,8 +115,11 @@ SharedPlanarYCbCrImage::AdoptData(const Data& aData)
uint32_t crOffset = aData.mCrChannel - base; uint32_t crOffset = aData.mCrChannel - base;
auto fwd = mCompositable->GetForwarder(); auto fwd = mCompositable->GetForwarder();
bool supportsTextureDirectMapping = fwd->SupportsTextureDirectMapping() &&
std::max(mSize.width, mSize.height) <= fwd->GetMaxTextureSize();
bool hasIntermediateBuffer = ComputeHasIntermediateBuffer( bool hasIntermediateBuffer = ComputeHasIntermediateBuffer(
gfx::SurfaceFormat::YUV, fwd->GetCompositorBackendType()); gfx::SurfaceFormat::YUV, fwd->GetCompositorBackendType(),
supportsTextureDirectMapping);
static_cast<BufferTextureData*>(mTextureClient->GetInternalData()) static_cast<BufferTextureData*>(mTextureClient->GetInternalData())
->SetDesciptor(YCbCrDescriptor(aData.mYSize, ->SetDesciptor(YCbCrDescriptor(aData.mYSize,

View File

@ -1920,6 +1920,18 @@ CompositorOGL::GetTemporaryTexture(GLenum aTarget, GLenum aUnit)
return mTexturePool->GetTexture(aTarget, aUnit); return mTexturePool->GetTexture(aTarget, aUnit);
} }
bool
CompositorOGL::SupportsTextureDirectMapping()
{
if (mGLContext) {
mGLContext->MakeCurrent();
return mGLContext->IsExtensionSupported(gl::GLContext::APPLE_client_storage) &&
mGLContext->IsExtensionSupported(gl::GLContext::APPLE_texture_range);
}
return false;
}
GLuint GLuint
PerUnitTexturePoolOGL::GetTexture(GLenum aTarget, GLenum aTextureUnit) PerUnitTexturePoolOGL::GetTexture(GLenum aTarget, GLenum aTextureUnit)
{ {

View File

@ -141,6 +141,7 @@ public:
TextureFactoryIdentifier(LayersBackend::LAYERS_OPENGL, TextureFactoryIdentifier(LayersBackend::LAYERS_OPENGL,
XRE_GetProcessType(), XRE_GetProcessType(),
GetMaxTextureSize(), GetMaxTextureSize(),
SupportsTextureDirectMapping(),
false, false,
mFBOTextureTarget == LOCAL_GL_TEXTURE_2D, mFBOTextureTarget == LOCAL_GL_TEXTURE_2D,
SupportsPartialTextureUpdate()); SupportsPartialTextureUpdate());
@ -273,6 +274,8 @@ private:
void PrepareViewport(CompositingRenderTargetOGL *aRenderTarget); void PrepareViewport(CompositingRenderTargetOGL *aRenderTarget);
bool SupportsTextureDirectMapping();
/** Widget associated with this compositor */ /** Widget associated with this compositor */
LayoutDeviceIntSize mWidgetSize; LayoutDeviceIntSize mWidgetSize;
RefPtr<GLContext> mGLContext; RefPtr<GLContext> mGLContext;