2009-03-04 03:31:44 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2012-08-02 21:01:42 +00:00
|
|
|
#ifndef ANDROID_DISPLAY_DEVICE_H
|
|
|
|
#define ANDROID_DISPLAY_DEVICE_H
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <ui/PixelFormat.h>
|
|
|
|
#include <ui/Region.h>
|
|
|
|
|
|
|
|
#include <EGL/egl.h>
|
2009-04-10 21:24:30 +00:00
|
|
|
#include <EGL/eglext.h>
|
|
|
|
|
2012-07-25 05:46:10 +00:00
|
|
|
#include <utils/Mutex.h>
|
2013-08-20 00:26:18 +00:00
|
|
|
#include <utils/String8.h>
|
2012-07-25 05:46:10 +00:00
|
|
|
#include <utils/Timers.h>
|
|
|
|
|
2012-08-23 00:16:19 +00:00
|
|
|
#include <hardware/hwcomposer_defs.h>
|
|
|
|
|
2012-06-21 00:51:20 +00:00
|
|
|
#include "Transform.h"
|
2010-06-26 01:02:21 +00:00
|
|
|
|
2012-08-05 04:39:11 +00:00
|
|
|
struct ANativeWindow;
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
namespace android {
|
|
|
|
|
2012-07-26 01:56:13 +00:00
|
|
|
class DisplayInfo;
|
2013-03-14 21:29:29 +00:00
|
|
|
class DisplaySurface;
|
2013-08-16 21:28:37 +00:00
|
|
|
class IGraphicBufferProducer;
|
2013-03-06 01:47:11 +00:00
|
|
|
class Layer;
|
2012-07-25 05:46:10 +00:00
|
|
|
class SurfaceFlinger;
|
2012-09-14 01:17:13 +00:00
|
|
|
class HWComposer;
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2012-08-05 08:23:51 +00:00
|
|
|
class DisplayDevice : public LightRefBase<DisplayDevice>
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-07-31 19:38:26 +00:00
|
|
|
// region in layer-stack space
|
|
|
|
mutable Region dirtyRegion;
|
|
|
|
// region in screen space
|
|
|
|
mutable Region swapRegion;
|
|
|
|
// region in screen space
|
|
|
|
Region undefinedRegion;
|
2012-04-04 05:09:52 +00:00
|
|
|
|
2012-08-27 23:28:24 +00:00
|
|
|
enum DisplayType {
|
|
|
|
DISPLAY_ID_INVALID = -1,
|
|
|
|
DISPLAY_PRIMARY = HWC_DISPLAY_PRIMARY,
|
|
|
|
DISPLAY_EXTERNAL = HWC_DISPLAY_EXTERNAL,
|
2013-08-16 21:28:37 +00:00
|
|
|
DISPLAY_VIRTUAL = HWC_DISPLAY_VIRTUAL,
|
|
|
|
NUM_BUILTIN_DISPLAY_TYPES = HWC_NUM_PHYSICAL_DISPLAY_TYPES,
|
2012-08-03 01:32:23 +00:00
|
|
|
};
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
enum {
|
2012-07-31 19:38:26 +00:00
|
|
|
PARTIAL_UPDATES = 0x00020000, // video driver feature
|
|
|
|
SWAP_RECTANGLE = 0x00080000,
|
2009-03-04 03:31:44 +00:00
|
|
|
};
|
|
|
|
|
2013-02-20 00:13:35 +00:00
|
|
|
enum {
|
|
|
|
NO_LAYER_STACK = 0xFFFFFFFF,
|
|
|
|
};
|
|
|
|
|
2012-08-01 06:09:07 +00:00
|
|
|
DisplayDevice(
|
2009-03-04 03:31:44 +00:00
|
|
|
const sp<SurfaceFlinger>& flinger,
|
2012-10-20 01:19:11 +00:00
|
|
|
DisplayType type,
|
2013-03-22 22:13:48 +00:00
|
|
|
int32_t hwcId, // negative for non-HWC-composited displays
|
2012-10-20 01:19:11 +00:00
|
|
|
bool isSecure,
|
|
|
|
const wp<IBinder>& displayToken,
|
2013-03-14 21:29:29 +00:00
|
|
|
const sp<DisplaySurface>& displaySurface,
|
2013-08-02 08:40:18 +00:00
|
|
|
const sp<IGraphicBufferProducer>& producer,
|
2012-07-12 21:25:33 +00:00
|
|
|
EGLConfig config);
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2012-08-05 08:23:51 +00:00
|
|
|
~DisplayDevice();
|
2012-08-03 01:32:23 +00:00
|
|
|
|
|
|
|
// whether this is a valid object. An invalid DisplayDevice is returned
|
|
|
|
// when an non existing id is requested
|
|
|
|
bool isValid() const;
|
|
|
|
|
2012-10-20 01:19:11 +00:00
|
|
|
// isSecure indicates whether this display can be trusted to display
|
|
|
|
// secure surfaces.
|
|
|
|
bool isSecure() const { return mIsSecure; }
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
// Flip the front and back buffers if the back buffer is "dirty". Might
|
|
|
|
// be instantaneous, might involve copying the frame buffer around.
|
|
|
|
void flip(const Region& dirty) const;
|
|
|
|
|
|
|
|
int getWidth() const;
|
|
|
|
int getHeight() const;
|
|
|
|
PixelFormat getFormat() const;
|
|
|
|
uint32_t getFlags() const;
|
2012-04-04 05:09:52 +00:00
|
|
|
|
2012-07-12 21:25:33 +00:00
|
|
|
EGLSurface getEGLSurface() const;
|
2012-07-11 20:48:17 +00:00
|
|
|
|
2013-03-06 01:47:11 +00:00
|
|
|
void setVisibleLayersSortedByZ(const Vector< sp<Layer> >& layers);
|
|
|
|
const Vector< sp<Layer> >& getVisibleLayersSortedByZ() const;
|
2012-07-11 20:48:17 +00:00
|
|
|
bool getSecureLayerVisible() const;
|
2012-08-16 23:28:27 +00:00
|
|
|
Region getDirtyRegion(bool repaintEverything) const;
|
2012-07-11 20:48:17 +00:00
|
|
|
|
2012-08-09 01:51:15 +00:00
|
|
|
void setLayerStack(uint32_t stack);
|
2012-09-05 02:30:46 +00:00
|
|
|
void setProjection(int orientation, const Rect& viewport, const Rect& frame);
|
2012-08-09 01:51:15 +00:00
|
|
|
|
2012-06-21 00:51:20 +00:00
|
|
|
int getOrientation() const { return mOrientation; }
|
|
|
|
const Transform& getTransform() const { return mGlobalTransform; }
|
2013-02-27 00:54:05 +00:00
|
|
|
const Rect getViewport() const { return mViewport; }
|
|
|
|
const Rect getFrame() const { return mFrame; }
|
2012-10-31 01:08:06 +00:00
|
|
|
const Rect& getScissor() const { return mScissor; }
|
2012-09-20 06:14:45 +00:00
|
|
|
bool needsFiltering() const { return mNeedsFiltering; }
|
2012-09-04 22:05:38 +00:00
|
|
|
|
2012-07-31 19:38:26 +00:00
|
|
|
uint32_t getLayerStack() const { return mLayerStack; }
|
2012-08-27 23:28:24 +00:00
|
|
|
int32_t getDisplayType() const { return mType; }
|
2012-08-22 06:34:09 +00:00
|
|
|
int32_t getHwcDisplayId() const { return mHwcDisplayId; }
|
2012-08-27 23:28:24 +00:00
|
|
|
const wp<IBinder>& getDisplayToken() const { return mDisplayToken; }
|
2012-07-31 19:38:26 +00:00
|
|
|
|
2013-08-20 23:35:32 +00:00
|
|
|
status_t beginFrame() const;
|
2013-04-07 06:12:29 +00:00
|
|
|
status_t prepareFrame(const HWComposer& hwc) const;
|
|
|
|
|
2012-09-14 01:17:13 +00:00
|
|
|
void swapBuffers(HWComposer& hwc) const;
|
2009-09-17 23:18:16 +00:00
|
|
|
status_t compositionComplete() const;
|
2013-02-20 00:13:35 +00:00
|
|
|
|
2012-09-14 01:17:13 +00:00
|
|
|
// called after h/w composer has completed its set() call
|
|
|
|
void onSwapBuffersCompleted(HWComposer& hwc) const;
|
|
|
|
|
2011-09-21 00:21:56 +00:00
|
|
|
Rect getBounds() const {
|
2012-06-21 00:51:20 +00:00
|
|
|
return Rect(mDisplayWidth, mDisplayHeight);
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
2011-09-21 00:21:56 +00:00
|
|
|
inline Rect bounds() const { return getBounds(); }
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2012-09-22 01:26:16 +00:00
|
|
|
void setDisplayName(const String8& displayName);
|
2012-09-18 01:27:17 +00:00
|
|
|
const String8& getDisplayName() const { return mDisplayName; }
|
|
|
|
|
2013-06-07 22:35:48 +00:00
|
|
|
EGLBoolean makeCurrent(EGLDisplay dpy, EGLContext ctx) const;
|
|
|
|
void setViewportAndProjection() const;
|
2012-09-28 08:00:47 +00:00
|
|
|
|
2012-08-02 21:01:42 +00:00
|
|
|
/* ------------------------------------------------------------------------
|
2012-09-18 01:27:17 +00:00
|
|
|
* blank / unblank management
|
2012-08-02 21:01:42 +00:00
|
|
|
*/
|
|
|
|
void releaseScreen() const;
|
|
|
|
void acquireScreen() const;
|
|
|
|
bool isScreenAcquired() const;
|
|
|
|
bool canDraw() const;
|
|
|
|
|
2013-03-25 21:43:23 +00:00
|
|
|
// release HWC resources (if any) for removable displays
|
|
|
|
void disconnect(HWComposer& hwc);
|
|
|
|
|
2012-08-02 21:01:42 +00:00
|
|
|
/* ------------------------------------------------------------------------
|
|
|
|
* Debugging
|
|
|
|
*/
|
|
|
|
uint32_t getPageFlipCount() const;
|
2013-04-22 14:55:35 +00:00
|
|
|
void dump(String8& result) const;
|
2012-08-02 21:01:42 +00:00
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
private:
|
2012-07-12 21:25:33 +00:00
|
|
|
/*
|
|
|
|
* Constants, set during initialization
|
|
|
|
*/
|
2011-08-01 23:32:21 +00:00
|
|
|
sp<SurfaceFlinger> mFlinger;
|
2012-08-27 23:28:24 +00:00
|
|
|
DisplayType mType;
|
2012-08-22 06:34:09 +00:00
|
|
|
int32_t mHwcDisplayId;
|
2012-08-27 23:28:24 +00:00
|
|
|
wp<IBinder> mDisplayToken;
|
2012-08-02 21:01:42 +00:00
|
|
|
|
2012-07-12 21:25:33 +00:00
|
|
|
// ANativeWindow this display is rendering into
|
2012-08-05 04:39:11 +00:00
|
|
|
sp<ANativeWindow> mNativeWindow;
|
2013-03-14 21:29:29 +00:00
|
|
|
sp<DisplaySurface> mDisplaySurface;
|
2012-07-12 21:25:33 +00:00
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
EGLDisplay mDisplay;
|
|
|
|
EGLSurface mSurface;
|
2012-06-21 00:51:20 +00:00
|
|
|
int mDisplayWidth;
|
|
|
|
int mDisplayHeight;
|
2009-03-04 03:31:44 +00:00
|
|
|
PixelFormat mFormat;
|
|
|
|
uint32_t mFlags;
|
2009-04-10 21:24:30 +00:00
|
|
|
mutable uint32_t mPageFlipCount;
|
2012-09-18 01:27:17 +00:00
|
|
|
String8 mDisplayName;
|
2012-10-20 01:19:11 +00:00
|
|
|
bool mIsSecure;
|
2012-04-26 23:11:59 +00:00
|
|
|
|
2012-07-12 21:25:33 +00:00
|
|
|
/*
|
|
|
|
* Can only accessed from the main thread, these members
|
|
|
|
* don't need synchronization.
|
|
|
|
*/
|
2012-08-02 21:01:42 +00:00
|
|
|
|
2012-07-11 20:48:17 +00:00
|
|
|
// list of visible layers on that display
|
2013-03-06 01:47:11 +00:00
|
|
|
Vector< sp<Layer> > mVisibleLayersSortedByZ;
|
2012-08-02 21:01:42 +00:00
|
|
|
|
2012-07-11 20:48:17 +00:00
|
|
|
// Whether we have a visible secure layer on this display
|
|
|
|
bool mSecureLayerVisible;
|
|
|
|
|
2012-08-02 21:01:42 +00:00
|
|
|
// Whether the screen is blanked;
|
|
|
|
mutable int mScreenAcquired;
|
|
|
|
|
2010-08-11 00:14:02 +00:00
|
|
|
|
2012-08-02 21:01:42 +00:00
|
|
|
/*
|
|
|
|
* Transaction state
|
|
|
|
*/
|
2012-09-04 22:05:38 +00:00
|
|
|
static status_t orientationToTransfrom(int orientation,
|
|
|
|
int w, int h, Transform* tr);
|
|
|
|
|
2012-07-31 19:38:26 +00:00
|
|
|
uint32_t mLayerStack;
|
2012-09-04 22:05:38 +00:00
|
|
|
int mOrientation;
|
2012-10-31 01:08:06 +00:00
|
|
|
// user-provided visible area of the layer stack
|
2012-09-04 22:05:38 +00:00
|
|
|
Rect mViewport;
|
2012-10-31 01:08:06 +00:00
|
|
|
// user-provided rectangle where mViewport gets mapped to
|
2012-09-04 22:05:38 +00:00
|
|
|
Rect mFrame;
|
2012-10-31 01:08:06 +00:00
|
|
|
// pre-computed scissor to apply to the display
|
|
|
|
Rect mScissor;
|
2012-09-04 22:05:38 +00:00
|
|
|
Transform mGlobalTransform;
|
2012-09-20 06:14:45 +00:00
|
|
|
bool mNeedsFiltering;
|
2009-03-04 03:31:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}; // namespace android
|
|
|
|
|
2012-08-02 21:01:42 +00:00
|
|
|
#endif // ANDROID_DISPLAY_DEVICE_H
|