зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1033607 - Get rid of Thebes backed gfxContexts in Gonk Widget code by killing of a bunch of non-OMTC code. r=mattwoodrow
This commit is contained in:
Родитель
7065a5f7a1
Коммит
3a2550a20b
|
@ -15,120 +15,27 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <linux/fb.h>
|
||||
#include <linux/kd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <vector>
|
||||
#include "Framebuffer.h"
|
||||
|
||||
#include "android/log.h"
|
||||
#include <fcntl.h>
|
||||
#include <linux/fb.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include "Framebuffer.h"
|
||||
#include "gfxContext.h"
|
||||
#include "gfxImageSurface.h"
|
||||
#include "gfxUtils.h"
|
||||
#include "nsSize.h"
|
||||
#include "mozilla/FileUtils.h"
|
||||
#include "nsTArray.h"
|
||||
#include "nsRegion.h"
|
||||
|
||||
#define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "Gonk" , ## args)
|
||||
#define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "Gonk" , ## args)
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
namespace Framebuffer {
|
||||
|
||||
static int sFd = -1;
|
||||
static size_t sMappedSize;
|
||||
static struct fb_var_screeninfo sVi;
|
||||
static size_t sActiveBuffer;
|
||||
typedef vector<nsRefPtr<gfxImageSurface> > BufferVector;
|
||||
BufferVector* sBuffers;
|
||||
static gfxIntSize *sScreenSize = nullptr;
|
||||
|
||||
BufferVector& Buffers() { return *sBuffers; }
|
||||
|
||||
bool
|
||||
SetGraphicsMode()
|
||||
{
|
||||
ScopedClose fd(open("/dev/tty0", O_RDWR | O_SYNC));
|
||||
if (0 > fd.get()) {
|
||||
// This is non-fatal; post-Cupcake kernels don't have tty0.
|
||||
LOG("No /dev/tty0?");
|
||||
} else if (ioctl(fd.get(), KDSETMODE, (void*) KD_GRAPHICS)) {
|
||||
LOG("Error setting graphics mode on /dev/tty0");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
Open()
|
||||
{
|
||||
if (0 <= sFd)
|
||||
return true;
|
||||
|
||||
if (!SetGraphicsMode())
|
||||
return false;
|
||||
|
||||
ScopedClose fd(open("/dev/graphics/fb0", O_RDWR));
|
||||
if (0 > fd.get()) {
|
||||
LOG("Error opening framebuffer device");
|
||||
return false;
|
||||
}
|
||||
|
||||
struct fb_fix_screeninfo fi;
|
||||
if (0 > ioctl(fd.get(), FBIOGET_FSCREENINFO, &fi)) {
|
||||
LOG("Error getting fixed screeninfo");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (0 > ioctl(fd.get(), FBIOGET_VSCREENINFO, &sVi)) {
|
||||
LOG("Error getting variable screeninfo");
|
||||
return false;
|
||||
}
|
||||
|
||||
sMappedSize = fi.smem_len;
|
||||
void* mem = mmap(0, sMappedSize, PROT_READ | PROT_WRITE, MAP_SHARED,
|
||||
fd.rwget(), 0);
|
||||
if (MAP_FAILED == mem) {
|
||||
LOG("Error mmap'ing framebuffer");
|
||||
return false;
|
||||
}
|
||||
|
||||
sFd = fd.get();
|
||||
fd.forget();
|
||||
|
||||
// The android porting doc requires a /dev/graphics/fb0 device
|
||||
// that's double buffered with r5g6b5 format. Hence the
|
||||
// hard-coded numbers here.
|
||||
gfxImageFormat format = gfxImageFormat::RGB16_565;
|
||||
if (!sScreenSize) {
|
||||
sScreenSize = new gfxIntSize(sVi.xres, sVi.yres);
|
||||
}
|
||||
long stride = fi.line_length;
|
||||
size_t numFrameBytes = stride * sScreenSize->height;
|
||||
|
||||
sBuffers = new BufferVector(2);
|
||||
unsigned char* data = static_cast<unsigned char*>(mem);
|
||||
for (size_t i = 0; i < 2; ++i, data += numFrameBytes) {
|
||||
memset(data, 0, numFrameBytes);
|
||||
Buffers()[i] = new gfxImageSurface(data, *sScreenSize, stride, format);
|
||||
}
|
||||
|
||||
// Clear the framebuffer to a known state.
|
||||
Present(nsIntRect());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
GetSize(nsIntSize *aScreenSize) {
|
||||
// If the framebuffer has been opened, we should always have the size.
|
||||
|
@ -153,54 +60,5 @@ GetSize(nsIntSize *aScreenSize) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
Close()
|
||||
{
|
||||
if (0 > sFd)
|
||||
return;
|
||||
|
||||
munmap(Buffers()[0]->Data(), sMappedSize);
|
||||
delete sBuffers;
|
||||
sBuffers = nullptr;
|
||||
delete sScreenSize;
|
||||
sScreenSize = nullptr;
|
||||
|
||||
close(sFd);
|
||||
sFd = -1;
|
||||
}
|
||||
|
||||
gfxASurface*
|
||||
BackBuffer()
|
||||
{
|
||||
return Buffers()[!sActiveBuffer];
|
||||
}
|
||||
|
||||
static gfxASurface*
|
||||
FrontBuffer()
|
||||
{
|
||||
return Buffers()[sActiveBuffer];
|
||||
}
|
||||
|
||||
void
|
||||
Present(const nsIntRegion& aUpdated)
|
||||
{
|
||||
sActiveBuffer = !sActiveBuffer;
|
||||
|
||||
sVi.yres_virtual = sVi.yres * 2;
|
||||
sVi.yoffset = sActiveBuffer * sVi.yres;
|
||||
sVi.bits_per_pixel = 16;
|
||||
if (ioctl(sFd, FBIOPUT_VSCREENINFO, &sVi) < 0) {
|
||||
LOG("Error presenting front buffer");
|
||||
}
|
||||
|
||||
nsRefPtr<gfxContext> ctx = new gfxContext(BackBuffer());
|
||||
gfxUtils::PathFromRegion(ctx, aUpdated);
|
||||
ctx->Clip();
|
||||
ctx->SetSource(FrontBuffer());
|
||||
ctx->SetOperator(gfxContext::OPERATOR_SOURCE);
|
||||
ctx->Paint(1.0);
|
||||
}
|
||||
|
||||
} // namespace Framebuffer
|
||||
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -15,48 +15,14 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
class gfxASurface;
|
||||
class nsIntRegion;
|
||||
class nsIntSize;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
namespace Framebuffer {
|
||||
|
||||
//
|
||||
// The general usage of Framebuffer is
|
||||
//
|
||||
// -- in initialization code --
|
||||
// Open();
|
||||
//
|
||||
// -- ready to paint next frame --
|
||||
// nsRefPtr<gfxASurface> backBuffer = BackBuffer();
|
||||
// // ...
|
||||
// Paint(backBuffer);
|
||||
// // ...
|
||||
// Present();
|
||||
//
|
||||
|
||||
// Return true if the fbdev was successfully opened. If this fails,
|
||||
// the result of all further calls is undefined. Open() is idempotent.
|
||||
bool Open();
|
||||
|
||||
// After Close(), the result of all further calls is undefined.
|
||||
// Close() is idempotent, and Open() can be called again after
|
||||
// Close().
|
||||
void Close();
|
||||
|
||||
// Return true if the fbdev was successfully opened or the size was
|
||||
// already cached.
|
||||
bool GetSize(nsIntSize *aScreenSize);
|
||||
|
||||
// Return the buffer to be drawn into, that will be the next frame.
|
||||
gfxASurface* BackBuffer();
|
||||
|
||||
// Swap the front buffer for the back buffer. |aUpdated| is the
|
||||
// region of the back buffer that was repainted.
|
||||
void Present(const nsIntRegion& aUpdated);
|
||||
|
||||
} // namespace Framebuffer
|
||||
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -68,14 +68,10 @@ static uint32_t sScreenRotation;
|
|||
static uint32_t sPhysicalScreenRotation;
|
||||
static nsIntRect sVirtualBounds;
|
||||
|
||||
static nsRefPtr<GLContext> sGLContext;
|
||||
static nsTArray<nsWindow *> sTopWindows;
|
||||
static nsWindow *gFocusedWindow = nullptr;
|
||||
static bool sFramebufferOpen;
|
||||
static bool sUsingOMTC;
|
||||
static bool sUsingHwc;
|
||||
static bool sScreenInitialized;
|
||||
static nsRefPtr<gfxASurface> sOMTCSurface;
|
||||
|
||||
namespace {
|
||||
|
||||
|
@ -160,15 +156,11 @@ nsWindow::nsWindow()
|
|||
// to know the color depth, which asks our native window.
|
||||
// This has to happen after other init has finished.
|
||||
gfxPlatform::GetPlatform();
|
||||
sUsingOMTC = ShouldUseOffMainThreadCompositing();
|
||||
|
||||
if (!ShouldUseOffMainThreadCompositing()) {
|
||||
MOZ_CRASH("How can we render apps, then?");
|
||||
}
|
||||
//Update sUsingHwc whenever layers.composer2d.enabled changes
|
||||
Preferences::AddBoolVarCache(&sUsingHwc, "layers.composer2d.enabled");
|
||||
|
||||
if (sUsingOMTC) {
|
||||
sOMTCSurface = new gfxImageSurface(gfxIntSize(1, 1),
|
||||
gfxImageFormat::RGB24);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -201,35 +193,6 @@ nsWindow::DoDraw(void)
|
|||
LayerManager* lm = targetWindow->GetLayerManager();
|
||||
if (mozilla::layers::LayersBackend::LAYERS_CLIENT == lm->GetBackendType()) {
|
||||
// No need to do anything, the compositor will handle drawing
|
||||
} else if (mozilla::layers::LayersBackend::LAYERS_BASIC == lm->GetBackendType()) {
|
||||
MOZ_ASSERT(sFramebufferOpen || sUsingOMTC);
|
||||
nsRefPtr<gfxASurface> targetSurface;
|
||||
|
||||
if(sUsingOMTC)
|
||||
targetSurface = sOMTCSurface;
|
||||
else
|
||||
targetSurface = Framebuffer::BackBuffer();
|
||||
|
||||
{
|
||||
nsRefPtr<gfxContext> ctx = new gfxContext(targetSurface);
|
||||
gfxUtils::PathFromRegion(ctx, sVirtualBounds);
|
||||
ctx->Clip();
|
||||
|
||||
// No double-buffering needed.
|
||||
AutoLayerManagerSetup setupLayerManager(
|
||||
targetWindow, ctx, mozilla::layers::BufferMode::BUFFER_NONE,
|
||||
ScreenRotation(EffectiveScreenRotation()));
|
||||
|
||||
listener = targetWindow->GetWidgetListener();
|
||||
if (listener) {
|
||||
listener->PaintWindow(targetWindow, sVirtualBounds);
|
||||
}
|
||||
}
|
||||
|
||||
if (!sUsingOMTC) {
|
||||
targetSurface->Flush();
|
||||
Framebuffer::Present(sVirtualBounds);
|
||||
}
|
||||
} else {
|
||||
NS_RUNTIMEABORT("Unexpected layer manager type");
|
||||
}
|
||||
|
@ -537,12 +500,7 @@ nsWindow::GetLayerManager(PLayerTransactionChild* aShadowManager,
|
|||
if (mLayerManager) {
|
||||
// This layer manager might be used for painting outside of DoDraw(), so we need
|
||||
// to set the correct rotation on it.
|
||||
if (mLayerManager->GetBackendType() == LayersBackend::LAYERS_BASIC) {
|
||||
BasicLayerManager* manager =
|
||||
static_cast<BasicLayerManager*>(mLayerManager.get());
|
||||
manager->SetDefaultTargetConfiguration(mozilla::layers::BufferMode::BUFFER_NONE,
|
||||
ScreenRotation(EffectiveScreenRotation()));
|
||||
} else if (mLayerManager->GetBackendType() == LayersBackend::LAYERS_CLIENT) {
|
||||
if (mLayerManager->GetBackendType() == LayersBackend::LAYERS_CLIENT) {
|
||||
ClientLayerManager* manager =
|
||||
static_cast<ClientLayerManager*>(mLayerManager.get());
|
||||
manager->SetDefaultTargetConfiguration(mozilla::layers::BufferMode::BUFFER_NONE,
|
||||
|
@ -561,38 +519,13 @@ nsWindow::GetLayerManager(PLayerTransactionChild* aShadowManager,
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
if (sUsingOMTC) {
|
||||
CreateCompositor();
|
||||
if (mCompositorParent) {
|
||||
uint64_t rootLayerTreeId = mCompositorParent->RootLayerTreeId();
|
||||
CompositorParent::SetControllerForLayerTree(rootLayerTreeId, new ParentProcessController());
|
||||
CompositorParent::GetAPZCTreeManager(rootLayerTreeId)->SetDPI(GetDPI());
|
||||
}
|
||||
if (mLayerManager)
|
||||
return mLayerManager;
|
||||
CreateCompositor();
|
||||
if (mCompositorParent) {
|
||||
uint64_t rootLayerTreeId = mCompositorParent->RootLayerTreeId();
|
||||
CompositorParent::SetControllerForLayerTree(rootLayerTreeId, new ParentProcessController());
|
||||
CompositorParent::GetAPZCTreeManager(rootLayerTreeId)->SetDPI(GetDPI());
|
||||
}
|
||||
|
||||
if (mUseLayersAcceleration) {
|
||||
DebugOnly<nsIntRect> fbBounds = gScreenBounds;
|
||||
if (!sGLContext) {
|
||||
sGLContext = GLContextProvider::CreateForWindow(this);
|
||||
}
|
||||
|
||||
MOZ_ASSERT(fbBounds.value == gScreenBounds);
|
||||
}
|
||||
|
||||
// Fall back to software rendering.
|
||||
sFramebufferOpen = Framebuffer::Open();
|
||||
if (sFramebufferOpen) {
|
||||
LOG("Falling back to framebuffer software rendering");
|
||||
} else {
|
||||
LOGE("Failed to mmap fb(?!?), aborting ...");
|
||||
NS_RUNTIMEABORT("Can't open GL context and can't fall back on /dev/graphics/fb0 ...");
|
||||
}
|
||||
|
||||
mLayerManager = new ClientLayerManager(this);
|
||||
mUseLayersAcceleration = false;
|
||||
|
||||
MOZ_ASSERT(mLayerManager);
|
||||
return mLayerManager;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче