Пример #1
0
static IntRect
GetTileRectD3D11(uint32_t aID, IntSize aSize, uint32_t aMaxSize)
{
  uint32_t horizontalTiles = GetRequiredTilesD3D11(aSize.width, aMaxSize);
  uint32_t verticalTiles = GetRequiredTilesD3D11(aSize.height, aMaxSize);

  uint32_t verticalTile = aID / horizontalTiles;
  uint32_t horizontalTile = aID % horizontalTiles;

  return IntRect(horizontalTile * aMaxSize,
                 verticalTile * aMaxSize,
                 horizontalTile < (horizontalTiles - 1) ? aMaxSize : aSize.width % aMaxSize,
                 verticalTile < (verticalTiles - 1) ? aMaxSize : aSize.height % aMaxSize);
}
Пример #2
0
IntRect
DeprecatedTextureHostShmemD3D11::GetTileRect(uint32_t aID) const
{
    uint32_t maxSize = GetMaxTextureSizeForFeatureLevel(mDevice->GetFeatureLevel());
    uint32_t horizontalTiles = GetRequiredTilesD3D11(mSize.width, maxSize);
    uint32_t verticalTiles = GetRequiredTilesD3D11(mSize.height, maxSize);

    uint32_t verticalTile = aID / horizontalTiles;
    uint32_t horizontalTile = aID % horizontalTiles;

    return IntRect(horizontalTile * maxSize,
                   verticalTile * maxSize,
                   horizontalTile < (horizontalTiles - 1) ? maxSize : mSize.width % maxSize,
                   verticalTile < (verticalTiles - 1) ? maxSize : mSize.height % maxSize);
}
Пример #3
0
bool
DataTextureSourceD3D11::Update(DataSourceSurface* aSurface,
                               nsIntRegion* aDestRegion,
                               IntPoint* aSrcOffset)
{
  // Incremental update with a source offset is only used on Mac so it is not
  // clear that we ever will need to support it for D3D.
  MOZ_ASSERT(!aSrcOffset);
  MOZ_ASSERT(aSurface);

  HRESULT hr;

  if (!mCompositor || !mCompositor->GetDevice()) {
    return false;
  }

  uint32_t bpp = BytesPerPixel(aSurface->GetFormat());
  DXGI_FORMAT dxgiFormat = SurfaceFormatToDXGIFormat(aSurface->GetFormat());

  mSize = aSurface->GetSize();
  mFormat = aSurface->GetFormat();

  CD3D11_TEXTURE2D_DESC desc(dxgiFormat, mSize.width, mSize.height, 1, 1);

  int32_t maxSize = mCompositor->GetMaxTextureSize();
  if ((mSize.width <= maxSize && mSize.height <= maxSize) ||
      (mFlags & TextureFlags::DISALLOW_BIGIMAGE)) {

    if (mTexture) {
      D3D11_TEXTURE2D_DESC currentDesc;
      mTexture->GetDesc(&currentDesc);

      // Make sure there's no size mismatch, if there is, recreate.
      if (currentDesc.Width != mSize.width || currentDesc.Height != mSize.height ||
          currentDesc.Format != dxgiFormat) {
        mTexture = nullptr;
        // Make sure we upload the whole surface.
        aDestRegion = nullptr;
      }
    }

    if (!mTexture) {
      hr = mCompositor->GetDevice()->CreateTexture2D(&desc, nullptr, byRef(mTexture));
      mIsTiled = false;
      if (FAILED(hr) || !mTexture) {
        Reset();
        return false;
      }
    }

    DataSourceSurface::MappedSurface map;
    aSurface->Map(DataSourceSurface::MapType::READ, &map);

    if (aDestRegion) {
      nsIntRegionRectIterator iter(*aDestRegion);
      const nsIntRect *iterRect;
      while ((iterRect = iter.Next())) {
        D3D11_BOX box;
        box.front = 0;
        box.back = 1;
        box.left = iterRect->x;
        box.top = iterRect->y;
        box.right = iterRect->XMost();
        box.bottom = iterRect->YMost();

        void* data = map.mData + map.mStride * iterRect->y + BytesPerPixel(aSurface->GetFormat()) * iterRect->x;

        mCompositor->GetDC()->UpdateSubresource(mTexture, 0, &box, data, map.mStride, map.mStride * mSize.height);
      }
    } else {
      mCompositor->GetDC()->UpdateSubresource(mTexture, 0, nullptr, aSurface->GetData(),
                                              aSurface->Stride(), aSurface->Stride() * mSize.height);
    }

    aSurface->Unmap();
  } else {
    mIsTiled = true;
    uint32_t tileCount = GetRequiredTilesD3D11(mSize.width, maxSize) *
                         GetRequiredTilesD3D11(mSize.height, maxSize);

    mTileTextures.resize(tileCount);
    mTexture = nullptr;

    for (uint32_t i = 0; i < tileCount; i++) {
      IntRect tileRect = GetTileRect(i);

      desc.Width = tileRect.width;
      desc.Height = tileRect.height;
      desc.Usage = D3D11_USAGE_IMMUTABLE;

      D3D11_SUBRESOURCE_DATA initData;
      initData.pSysMem = aSurface->GetData() +
                         tileRect.y * aSurface->Stride() +
                         tileRect.x * bpp;
      initData.SysMemPitch = aSurface->Stride();

      hr = mCompositor->GetDevice()->CreateTexture2D(&desc, &initData, byRef(mTileTextures[i]));
      if (FAILED(hr) || !mTileTextures[i]) {
        Reset();
        return false;
      }
    }
  }
  return true;
}
Пример #4
0
void
DeprecatedTextureHostShmemD3D11::UpdateImpl(const SurfaceDescriptor& aImage,
        nsIntRegion* aRegion,
        nsIntPoint* aOffset)
{
    MOZ_ASSERT(aImage.type() == SurfaceDescriptor::TShmem ||
               aImage.type() == SurfaceDescriptor::TMemoryImage);

    AutoOpenSurface openSurf(OPEN_READ_ONLY, aImage);

    nsRefPtr<gfxImageSurface> surf = openSurf.GetAsImage();

    gfx::IntSize size = gfx::ToIntSize(surf->GetSize());

    uint32_t bpp = 0;

    DXGI_FORMAT dxgiFormat;
    switch (surf->Format()) {
    case gfxImageFormatRGB24:
        mFormat = FORMAT_B8G8R8X8;
        dxgiFormat = DXGI_FORMAT_B8G8R8X8_UNORM;
        bpp = 4;
        break;
    case gfxImageFormatARGB32:
        mFormat = FORMAT_B8G8R8A8;
        dxgiFormat = DXGI_FORMAT_B8G8R8A8_UNORM;
        bpp = 4;
        break;
    case gfxImageFormatA8:
        mFormat = FORMAT_A8;
        dxgiFormat = DXGI_FORMAT_A8_UNORM;
        bpp = 1;
        break;
    default:
        NS_ERROR("Bad image format");
    }

    mSize = size;

    CD3D11_TEXTURE2D_DESC desc(dxgiFormat, size.width, size.height,
                               1, 1, D3D11_BIND_SHADER_RESOURCE,
                               D3D11_USAGE_IMMUTABLE);

    int32_t maxSize = GetMaxTextureSizeForFeatureLevel(mDevice->GetFeatureLevel());
    if (size.width <= maxSize && size.height <= maxSize) {
        D3D11_SUBRESOURCE_DATA initData;
        initData.pSysMem = surf->Data();
        initData.SysMemPitch = surf->Stride();

        mDevice->CreateTexture2D(&desc, &initData, byRef(mTextures[0]));
        mIsTiled = false;
    } else {
        mIsTiled = true;
        uint32_t tileCount = GetRequiredTilesD3D11(size.width, maxSize) *
                             GetRequiredTilesD3D11(size.height, maxSize);

        mTileTextures.resize(tileCount);

        for (uint32_t i = 0; i < tileCount; i++) {
            IntRect tileRect = GetTileRect(i);

            desc.Width = tileRect.width;
            desc.Height = tileRect.height;

            D3D11_SUBRESOURCE_DATA initData;
            initData.pSysMem = surf->Data() +
                               tileRect.y * surf->Stride() +
                               tileRect.x * bpp;
            initData.SysMemPitch = surf->Stride();

            mDevice->CreateTexture2D(&desc, &initData, byRef(mTileTextures[i]));
        }
    }
}