1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 ts=2 et 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/. */
7 #include "AndroidCompositorWidget.h"
9 #include "mozilla/gfx/Logging.h"
10 #include "mozilla/widget/PlatformWidgetTypes.h"
16 AndroidCompositorWidget::AndroidCompositorWidget(
17 const AndroidCompositorWidgetInitData
& aInitData
,
18 const layers::CompositorOptions
& aOptions
)
19 : CompositorWidget(aOptions
),
20 mWidgetId(aInitData
.widgetId()),
21 mNativeWindow(nullptr),
22 mFormat(WINDOW_FORMAT_RGBA_8888
),
23 mClientSize(aInitData
.clientSize()) {}
25 AndroidCompositorWidget::~AndroidCompositorWidget() {
27 ANativeWindow_release(mNativeWindow
);
31 already_AddRefed
<gfx::DrawTarget
>
32 AndroidCompositorWidget::StartRemoteDrawingInRegion(
33 const LayoutDeviceIntRegion
& aInvalidRegion
,
34 layers::BufferMode
* aBufferMode
) {
36 EGLNativeWindowType window
= GetEGLNativeWindow();
37 JNIEnv
* const env
= jni::GetEnvForThread();
39 ANativeWindow_fromSurface(env
, reinterpret_cast<jobject
>(window
));
41 mFormat
= ANativeWindow_getFormat(mNativeWindow
);
42 ANativeWindow_acquire(mNativeWindow
);
48 if (mFormat
!= WINDOW_FORMAT_RGBA_8888
&&
49 mFormat
!= WINDOW_FORMAT_RGBX_8888
) {
50 gfxCriticalNoteOnce
<< "Non supported format: " << mFormat
;
54 // XXX Handle inOutDirtyBounds
55 if (ANativeWindow_lock(mNativeWindow
, &mBuffer
, nullptr) != 0) {
60 gfx::SurfaceFormat format
= gfx::SurfaceFormat::R8G8B8A8
;
61 if (mFormat
== WINDOW_FORMAT_RGBX_8888
) {
62 format
= gfx::SurfaceFormat::R8G8B8X8
;
65 RefPtr
<gfx::DrawTarget
> dt
= gfx::Factory::CreateDrawTargetForData(
66 gfx::BackendType::SKIA
, static_cast<unsigned char*>(mBuffer
.bits
),
67 gfx::IntSize(mBuffer
.width
, mBuffer
.height
), mBuffer
.stride
* bpp
, format
,
73 void AndroidCompositorWidget::EndRemoteDrawingInRegion(
74 gfx::DrawTarget
* aDrawTarget
, const LayoutDeviceIntRegion
& aInvalidRegion
) {
75 ANativeWindow_unlockAndPost(mNativeWindow
);
78 bool AndroidCompositorWidget::OnResumeComposition() {
79 OnCompositorSurfaceChanged();
82 gfxCriticalError() << "OnResumeComposition called with null Surface";
89 EGLNativeWindowType
AndroidCompositorWidget::GetEGLNativeWindow() {
90 return (EGLNativeWindowType
)mSurface
.Get();
93 LayoutDeviceIntSize
AndroidCompositorWidget::GetClientSize() {
97 void AndroidCompositorWidget::NotifyClientSizeChanged(
98 const LayoutDeviceIntSize
& aClientSize
) {
100 LayoutDeviceIntSize(std::min(aClientSize
.width
, MOZ_WIDGET_MAX_SIZE
),
101 std::min(aClientSize
.height
, MOZ_WIDGET_MAX_SIZE
));
104 } // namespace widget
105 } // namespace mozilla