Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/gfx/layers/GLImages.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "GLImages.h"
8
#include "GLContext.h"
9
#include "GLContextProvider.h"
10
#include "ScopedGLHelpers.h"
11
#include "GLImages.h"
12
#include "GLBlitHelper.h"
13
#include "GLReadTexImageHelper.h"
14
#include "GLLibraryEGL.h"
15
16
using namespace mozilla;
17
using namespace mozilla::gl;
18
19
namespace mozilla {
20
namespace layers {
21
22
static RefPtr<GLContext> sSnapshotContext;
23
24
already_AddRefed<gfx::SourceSurface>
25
GLImage::GetAsSourceSurface()
26
0
{
27
0
  MOZ_ASSERT(NS_IsMainThread(), "Should be on the main thread");
28
0
29
0
  if (!sSnapshotContext) {
30
0
    nsCString discardFailureId;
31
0
    sSnapshotContext = GLContextProvider::CreateHeadless(CreateContextFlags::NONE,
32
0
                                                         &discardFailureId);
33
0
    if (!sSnapshotContext) {
34
0
      NS_WARNING("Failed to create snapshot GLContext");
35
0
      return nullptr;
36
0
    }
37
0
  }
38
0
39
0
  sSnapshotContext->MakeCurrent();
40
0
  ScopedTexture scopedTex(sSnapshotContext);
41
0
  ScopedBindTexture boundTex(sSnapshotContext, scopedTex.Texture());
42
0
43
0
  gfx::IntSize size = GetSize();
44
0
  sSnapshotContext->fTexImage2D(LOCAL_GL_TEXTURE_2D, 0, LOCAL_GL_RGBA,
45
0
                                size.width, size.height, 0,
46
0
                                LOCAL_GL_RGBA,
47
0
                                LOCAL_GL_UNSIGNED_BYTE,
48
0
                                nullptr);
49
0
50
0
  ScopedFramebufferForTexture autoFBForTex(sSnapshotContext, scopedTex.Texture());
51
0
  if (!autoFBForTex.IsComplete()) {
52
0
      gfxCriticalError() << "GetAsSourceSurface: ScopedFramebufferForTexture failed.";
53
0
      return nullptr;
54
0
  }
55
0
56
0
  const gl::OriginPos destOrigin = gl::OriginPos::TopLeft;
57
0
  {
58
0
    const ScopedBindFramebuffer bindFB(sSnapshotContext, autoFBForTex.FB());
59
0
    if (!sSnapshotContext->BlitHelper()->BlitImageToFramebuffer(this, size, destOrigin)) {
60
0
      return nullptr;
61
0
    }
62
0
  }
63
0
64
0
  RefPtr<gfx::DataSourceSurface> source =
65
0
        gfx::Factory::CreateDataSourceSurface(size, gfx::SurfaceFormat::B8G8R8A8);
66
0
  if (NS_WARN_IF(!source)) {
67
0
    return nullptr;
68
0
  }
69
0
70
0
  ScopedBindFramebuffer bind(sSnapshotContext, autoFBForTex.FB());
71
0
  ReadPixelsIntoDataSurface(sSnapshotContext, source);
72
0
  return source.forget();
73
0
}
74
75
#ifdef MOZ_WIDGET_ANDROID
76
SurfaceTextureImage::SurfaceTextureImage(AndroidSurfaceTextureHandle aHandle,
77
                                         const gfx::IntSize& aSize,
78
                                         bool aContinuous,
79
                                         gl::OriginPos aOriginPos)
80
 : GLImage(ImageFormat::SURFACE_TEXTURE),
81
   mHandle(aHandle),
82
   mSize(aSize),
83
   mContinuous(aContinuous),
84
   mOriginPos(aOriginPos)
85
{
86
  MOZ_ASSERT(mHandle);
87
}
88
#endif
89
90
} // namespace layers
91
} // namespace mozilla