minui: Remove the default and copy ctors for GRSurface.

As well as all the derived classes. Instances must be created with
Create(). A default copy ctor would mess up the ownership of the
mapped or allocated buffer in these classes, so that has been explicitly
removed.

Test: mmma -j bootable/recovery
Test: Run recovery_unit_test on marlin.
Test: `Run graphics test` on blueline.
Change-Id: I69ce001a9ec9e3ac851edb6ec4d3fa11f4aaea08
This commit is contained in:
Tao Bao 2018-10-24 07:59:49 -07:00
parent 1b18cf56e2
commit 710bc535f4
3 changed files with 10 additions and 12 deletions

View file

@ -102,15 +102,15 @@ std::unique_ptr<GRSurfaceDrm> GRSurfaceDrm::Create(int drm_fd, int width, int he
return nullptr; return nullptr;
} }
std::unique_ptr<GRSurfaceDrm> surface = std::make_unique<GRSurfaceDrm>(drm_fd); // Cannot use std::make_unique to access non-public ctor.
surface->handle = create_dumb.handle; auto surface = std::unique_ptr<GRSurfaceDrm>(new GRSurfaceDrm(
width, height, create_dumb.pitch, create_dumb.bpp / 8, drm_fd, create_dumb.handle));
uint32_t handles[4], pitches[4], offsets[4]; uint32_t handles[4], pitches[4], offsets[4];
handles[0] = surface->handle; handles[0] = surface->handle;
pitches[0] = create_dumb.pitch; pitches[0] = create_dumb.pitch;
offsets[0] = 0; offsets[0] = 0;
if (drmModeAddFB2(drm_fd, width, height, format, handles, pitches, offsets, &surface->fb_id, 0) != if (drmModeAddFB2(drm_fd, width, height, format, handles, pitches, offsets, &surface->fb_id, 0) !=
0) { 0) {
perror("Failed to drmModeAddFB2"); perror("Failed to drmModeAddFB2");
@ -124,10 +124,6 @@ std::unique_ptr<GRSurfaceDrm> GRSurfaceDrm::Create(int drm_fd, int width, int he
return nullptr; return nullptr;
} }
surface->height = height;
surface->width = width;
surface->row_bytes = create_dumb.pitch;
surface->pixel_bytes = create_dumb.bpp / 8;
auto mmapped = mmap(nullptr, surface->height * surface->row_bytes, PROT_READ | PROT_WRITE, auto mmapped = mmap(nullptr, surface->height * surface->row_bytes, PROT_READ | PROT_WRITE,
MAP_SHARED, drm_fd, map_dumb.offset); MAP_SHARED, drm_fd, map_dumb.offset);
if (mmapped == MAP_FAILED) { if (mmapped == MAP_FAILED) {

View file

@ -20,7 +20,6 @@
#include <memory> #include <memory>
#include <android-base/macros.h>
#include <xf86drmMode.h> #include <xf86drmMode.h>
#include "graphics.h" #include "graphics.h"
@ -28,7 +27,6 @@
class GRSurfaceDrm : public GRSurface { class GRSurfaceDrm : public GRSurface {
public: public:
explicit GRSurfaceDrm(int drm_fd) : drm_fd_(drm_fd) {}
~GRSurfaceDrm() override; ~GRSurfaceDrm() override;
// Creates a GRSurfaceDrm instance. // Creates a GRSurfaceDrm instance.
@ -41,13 +39,14 @@ class GRSurfaceDrm : public GRSurface {
private: private:
friend class MinuiBackendDrm; friend class MinuiBackendDrm;
GRSurfaceDrm(int width, int height, int row_bytes, int pixel_bytes, int drm_fd, uint32_t handle)
: GRSurface(width, height, row_bytes, pixel_bytes), drm_fd_(drm_fd), handle(handle) {}
const int drm_fd_; const int drm_fd_;
uint32_t fb_id{ 0 }; uint32_t fb_id{ 0 };
uint32_t handle{ 0 }; uint32_t handle{ 0 };
uint8_t* mmapped_buffer_{ nullptr }; uint8_t* mmapped_buffer_{ nullptr };
DISALLOW_COPY_AND_ASSIGN(GRSurfaceDrm);
}; };
class MinuiBackendDrm : public MinuiBackend { class MinuiBackendDrm : public MinuiBackend {

View file

@ -24,13 +24,14 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <android-base/macros.h>
// //
// Graphics. // Graphics.
// //
class GRSurface { class GRSurface {
public: public:
GRSurface() = default;
virtual ~GRSurface(); virtual ~GRSurface();
// Creates and returns a GRSurface instance that's sufficient for storing an image of the given // Creates and returns a GRSurface instance that's sufficient for storing an image of the given
@ -58,6 +59,8 @@ class GRSurface {
private: private:
uint8_t* data_{ nullptr }; uint8_t* data_{ nullptr };
DISALLOW_COPY_AND_ASSIGN(GRSurface);
}; };
struct GRFont { struct GRFont {