Make pixelRatio constant across a Map object lifetime

also moves framebuffer size out of TransformState into its own object
This commit is contained in:
Konstantin Käfer
2015-07-01 12:39:21 +02:00
parent 3a07cb2f1e
commit 675ddddee7
40 changed files with 308 additions and 214 deletions

View File

@@ -17,9 +17,12 @@ namespace android {
class NativeMapView : public mbgl::View, private mbgl::util::noncopyable {
public:
NativeMapView(JNIEnv *env, jobject obj);
NativeMapView(JNIEnv *env, jobject obj, float pixelRatio);
virtual ~NativeMapView();
float getPixelRatio() const override;
std::array<uint16_t, 2> getSize() const override;
std::array<uint16_t, 2> getFramebufferSize() const override;
void activate() override;
void deactivate() override;
void notify() override;
@@ -48,6 +51,9 @@ public:
void onInvalidate();
void resizeView(int width, int height);
void resizeFramebuffer(int width, int height);
private:
EGLConfig chooseConfig(const EGLConfig configs[], EGLint numConfigs);
@@ -73,6 +79,12 @@ private:
bool fpsEnabled = false;
double fps = 0.0;
int width = 0;
int height = 0;
int fbWidth = 0;
int fbHeight = 0;
const float pixelRatio;
// Ensure these are initialised last
mbgl::SQLiteCache fileCache;
mbgl::DefaultFileSource fileSource;

View File

@@ -113,7 +113,6 @@ public:
void resetNorth();
// Size
void resize(uint16_t width, uint16_t height, float ratio = 1);
uint16_t getWidth() const;
uint16_t getHeight() const;

View File

@@ -9,6 +9,7 @@ using UpdateType = uint32_t;
enum class Update : UpdateType {
Nothing = 0,
Dimensions = 1 << 1,
DefaultTransitionDuration = 1 << 2,
Classes = 1 << 3,
Zoom = 1 << 4,

View File

@@ -30,6 +30,21 @@ enum MapChange : uint8_t {
class View {
public:
// Called from the main thread directly after initialization. Must always return the same value,
// i.e. it may not change over time.
virtual float getPixelRatio() const = 0;
// Called from the main thread when the View signaled a dimension change. Must return the
// logical dimension of this map in pixels.
virtual std::array<uint16_t, 2> getSize() const = 0;
// Called from the main thread for every frame that is being rendered. Must return the absolute
// dimensions of the current framebuffer. Typically, this is the logical width scaled by the
// pixel ratio, but in case the view was moved to display with a different pixel ratio, it can
// also be different from that rule.
virtual std::array<uint16_t, 2> getFramebufferSize() const = 0;
// Called from the main thread when this View is associated with a Map object.
virtual void initialize(Map *map_);
// Called from the render thread. Makes the GL context active in the current
@@ -43,9 +58,6 @@ public:
virtual void notify() = 0;
// Called from the render thread. The implementation should resize the framebuffer.
virtual void resize(uint16_t width, uint16_t height, float pixelRatio);
// Called from the render thread. The implementation must trigger a rerender.
// (map->renderSync() from the main thread must be called as a result of this)
virtual void invalidate() = 0;

View File

@@ -15,6 +15,10 @@ public:
GLFWView(bool fullscreen = false);
~GLFWView();
float getPixelRatio() const override;
std::array<uint16_t, 2> getSize() const override;
std::array<uint16_t, 2> getFramebufferSize() const override;
void initialize(mbgl::Map *map) override;
void activate() override;
void deactivate() override;
@@ -24,7 +28,8 @@ public:
static void onKey(GLFWwindow *window, int key, int scancode, int action, int mods);
static void onScroll(GLFWwindow *window, double xoffset, double yoffset);
static void onResize(GLFWwindow *window, int width, int height);
static void onWindowResize(GLFWwindow *window, int width, int height);
static void onFramebufferResize(GLFWwindow *window, int width, int height);
static void onMouseClick(GLFWwindow *window, int button, int action, int modifiers);
static void onMouseMove(GLFWwindow *window, double x, double y);
@@ -57,6 +62,9 @@ private:
int width = 1024;
int height = 768;
int fbWidth;
int fbHeight;
float pixelRatio;
double lastX = 0, lastY = 0;

View File

@@ -25,18 +25,23 @@ class HeadlessDisplay;
class HeadlessView : public View {
public:
HeadlessView(uint16_t width = 256, uint16_t height = 256, float pixelRatio = 1);
HeadlessView(std::shared_ptr<HeadlessDisplay> display, uint16_t width = 256, uint16_t height = 256, float pixelRatio = 1);
HeadlessView(float pixelRatio, uint16_t width = 256, uint16_t height = 256);
HeadlessView(std::shared_ptr<HeadlessDisplay> display, float pixelRatio, uint16_t width = 256, uint16_t height = 256);
~HeadlessView();
float getPixelRatio() const override;
std::array<uint16_t, 2> getSize() const override;
std::array<uint16_t, 2> getFramebufferSize() const override;
void activate() override;
void deactivate() override;
void notify() override;
void resize(uint16_t width, uint16_t height, float pixelRatio) override;
void invalidate() override;
void swap() override;
std::unique_ptr<StillImage> readStillImage() override;
void resize(uint16_t width, uint16_t height);
private:
void createContext();
void loadExtensions();
@@ -45,18 +50,8 @@ private:
private:
std::shared_ptr<HeadlessDisplay> display;
struct Dimensions {
inline Dimensions(uint16_t width = 0, uint16_t height = 0, float pixelRatio = 0);
inline uint16_t pixelWidth() const { return width * pixelRatio; }
inline uint16_t pixelHeight() const { return height * pixelRatio; }
uint16_t width = 0;
uint16_t height = 0;
float pixelRatio = 0;
};
Dimensions dimensions;
const float pixelRatio;
std::array<uint16_t, 2> dimensions;
#if MBGL_USE_CGL
CGLContextObj glContext = nullptr;