Example #1
0
bool
ShadowImageLayerOGL::Init(const SharedImage& aFront)
{
  if (aFront.type() == SharedImage::TSurfaceDescriptor) {
    SurfaceDescriptor desc = aFront.get_SurfaceDescriptor();
    nsRefPtr<gfxASurface> surf =
      ShadowLayerForwarder::OpenDescriptor(desc);
    mSize = surf->GetSize();
    mTexImage = gl()->CreateTextureImage(nsIntSize(mSize.width, mSize.height),
                                         surf->GetContentType(),
                                         LOCAL_GL_CLAMP_TO_EDGE,
                                         mForceSingleTile
                                          ? TextureImage::ForceSingleTile
                                          : TextureImage::NoFlags);
    return true;
  } else {
    YUVImage yuv = aFront.get_YUVImage();

    nsRefPtr<gfxSharedImageSurface> surfY =
      gfxSharedImageSurface::Open(yuv.Ydata());
    nsRefPtr<gfxSharedImageSurface> surfU =
      gfxSharedImageSurface::Open(yuv.Udata());
    nsRefPtr<gfxSharedImageSurface> surfV =
      gfxSharedImageSurface::Open(yuv.Vdata());

    mSize = surfY->GetSize();
    mCbCrSize = surfU->GetSize();

    if (!mYUVTexture[0].IsAllocated()) {
      mYUVTexture[0].Allocate(gl());
      mYUVTexture[1].Allocate(gl());
      mYUVTexture[2].Allocate(gl());
    }

    NS_ASSERTION(mYUVTexture[0].IsAllocated() &&
                 mYUVTexture[1].IsAllocated() &&
                 mYUVTexture[2].IsAllocated(),
                 "Texture allocation failed!");

    gl()->MakeCurrent();
    SetClamping(gl(), mYUVTexture[0].GetTextureID());
    SetClamping(gl(), mYUVTexture[1].GetTextureID());
    SetClamping(gl(), mYUVTexture[2].GetTextureID());
    return true;
  }
  return false;
}
void ShadowImageLayerOGL::UploadSharedYUVToTexture(const YUVImage& yuv)
{
  AutoOpenSurface asurfY(OPEN_READ_ONLY, yuv.Ydata());
  AutoOpenSurface asurfU(OPEN_READ_ONLY, yuv.Udata());
  AutoOpenSurface asurfV(OPEN_READ_ONLY, yuv.Vdata());
  nsRefPtr<gfxImageSurface> surfY = asurfY.GetAsImage();
  nsRefPtr<gfxImageSurface> surfU = asurfU.GetAsImage();
  nsRefPtr<gfxImageSurface> surfV = asurfV.GetAsImage();
  mPictureRect = yuv.picture();

  gfxIntSize size = surfY->GetSize();
  gfxIntSize CbCrSize = surfU->GetSize();
  if (size != mSize || mCbCrSize != CbCrSize || !mYUVTexture[0].IsAllocated()) {
    
    mSize = surfY->GetSize();
    mCbCrSize = surfU->GetSize();

    if (!mYUVTexture[0].IsAllocated()) {
      mYUVTexture[0].Allocate(gl());
      mYUVTexture[1].Allocate(gl());
      mYUVTexture[2].Allocate(gl());
    }

    NS_ASSERTION(mYUVTexture[0].IsAllocated() &&
                 mYUVTexture[1].IsAllocated() &&
                 mYUVTexture[2].IsAllocated(),
                 "Texture allocation failed!");

    gl()->MakeCurrent();
    SetClamping(gl(), mYUVTexture[0].GetTextureID());
    SetClamping(gl(), mYUVTexture[1].GetTextureID());
    SetClamping(gl(), mYUVTexture[2].GetTextureID());
  }

  PlanarYCbCrImage::Data data;
  data.mYChannel = surfY->Data();
  data.mYStride = surfY->Stride();
  data.mYSize = surfY->GetSize();
  data.mCbChannel = surfU->Data();
  data.mCrChannel = surfV->Data();
  data.mCbCrStride = surfU->Stride();
  data.mCbCrSize = surfU->GetSize();

  UploadYUVToTexture(gl(), data, &mYUVTexture[0], &mYUVTexture[1], &mYUVTexture[2]);
}