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>
|
|
|
|
#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;
|
2012-06-08 00:52:54 +00:00
|
|
|
class FramebufferSurface;
|
2012-07-25 05:46:10 +00:00
|
|
|
class LayerBase;
|
|
|
|
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,
|
|
|
|
NUM_DISPLAY_TYPES = HWC_NUM_DISPLAY_TYPES,
|
|
|
|
DISPLAY_VIRTUAL = HWC_NUM_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
|
|
|
};
|
|
|
|
|
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,
|
|
|
|
bool isSecure,
|
|
|
|
const wp<IBinder>& displayToken,
|
2012-08-03 03:11:05 +00:00
|
|
|
const sp<ANativeWindow>& nativeWindow,
|
|
|
|
const sp<FramebufferSurface>& framebufferSurface,
|
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
|
|
|
|
|
|
|
void setVisibleLayersSortedByZ(const Vector< sp<LayerBase> >& layers);
|
2012-08-27 23:28:24 +00:00
|
|
|
const Vector< sp<LayerBase> >& 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; }
|
2012-09-04 22:05:38 +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
|
|
|
|
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;
|
|
|
|
|
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; }
|
|
|
|
|
2012-09-04 22:05:38 +00:00
|
|
|
static EGLBoolean makeCurrent(EGLDisplay dpy,
|
|
|
|
const sp<const DisplayDevice>& hw, EGLContext ctx);
|
2012-08-01 02:01:53 +00:00
|
|
|
|
2012-09-28 08:00:47 +00:00
|
|
|
static void setViewportAndProjection(const sp<const DisplayDevice>& hw);
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------
|
|
|
|
* Debugging
|
|
|
|
*/
|
|
|
|
uint32_t getPageFlipCount() const;
|
2012-09-18 08:38:00 +00:00
|
|
|
void dump(String8& result, char* buffer, size_t SIZE) 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
|
|
|
void init(EGLConfig config);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
2012-08-02 21:01:42 +00:00
|
|
|
|
2012-07-12 21:25:33 +00:00
|
|
|
// set if mNativeWindow is a FramebufferSurface
|
|
|
|
sp<FramebufferSurface> mFramebufferSurface;
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
EGLDisplay mDisplay;
|
|
|
|
EGLSurface mSurface;
|
|
|
|
EGLContext mContext;
|
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
|
|
|
|
Vector< sp<LayerBase> > 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);
|
|
|
|
|
|
|
|
void updateGeometryTransform();
|
|
|
|
|
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
|