Commit 7b79fb02 authored by tomhudson's avatar tomhudson Committed by Commit bot

Limit manual control of platform painting

Platform painting should be through skia::ScopedPlatformPaint.
(Only one compositor callsite was calling Begin/End directly.)

Remove skia::EndPlatformPaint() and all device-specific implementations,
which were effectively noops.

Remove skia::BeginPlatformPaint(), and make all device-specific impls
protected.

BUG=598695
R=fmalita@chromium.org
TBR=danakj@chromium.org

Review URL: https://codereview.chromium.org/1839113002

Cr-Commit-Position: refs/heads/master@{#383820}
parent 194fbcf0
...@@ -180,10 +180,10 @@ void SoftwareOutputDeviceWin::EndPaint() { ...@@ -180,10 +180,10 @@ void SoftwareOutputDeviceWin::EndPaint() {
style |= WS_EX_LAYERED; style |= WS_EX_LAYERED;
SetWindowLong(hwnd_, GWL_EXSTYLE, style); SetWindowLong(hwnd_, GWL_EXSTYLE, style);
HDC dib_dc = skia::BeginPlatformPaint(contents_.get()); skia::ScopedPlatformPaint spp(contents_.get());
HDC dib_dc = spp.GetPlatformSurface();
::UpdateLayeredWindow(hwnd_, NULL, &position, &size, dib_dc, &zero, ::UpdateLayeredWindow(hwnd_, NULL, &position, &size, dib_dc, &zero,
RGB(0xFF, 0xFF, 0xFF), &blend, ULW_ALPHA); RGB(0xFF, 0xFF, 0xFF), &blend, ULW_ALPHA);
skia::EndPlatformPaint(contents_.get());
} else { } else {
HDC hdc = ::GetDC(hwnd_); HDC hdc = ::GetDC(hwnd_);
RECT src_rect = rect.ToRECT(); RECT src_rect = rect.ToRECT();
......
...@@ -46,6 +46,8 @@ typedef struct _cairo_surface cairo_surface_t; ...@@ -46,6 +46,8 @@ typedef struct _cairo_surface cairo_surface_t;
namespace skia { namespace skia {
class ScopedPlatformPaint;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// This is the Linux bitmap backing for Skia. We create a Cairo image surface // This is the Linux bitmap backing for Skia. We create a Cairo image surface
// to store the backing buffer. This buffer is BGRA in memory (on little-endian // to store the backing buffer. This buffer is BGRA in memory (on little-endian
...@@ -84,13 +86,13 @@ class BitmapPlatformDevice : public SkBitmapDevice, public PlatformDevice { ...@@ -84,13 +86,13 @@ class BitmapPlatformDevice : public SkBitmapDevice, public PlatformDevice {
const SkRegion& region, const SkRegion& region,
const SkClipStack&) override; const SkClipStack&) override;
// Overridden from PlatformDevice:
cairo_t* BeginPlatformPaint() override;
protected: protected:
SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) override; SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) override;
private: private:
// Overridden from PlatformDevice:
cairo_t* BeginPlatformPaint() override;
static BitmapPlatformDevice* Create(int width, int height, bool is_opaque, static BitmapPlatformDevice* Create(int width, int height, bool is_opaque,
cairo_surface_t* surface); cairo_surface_t* surface);
...@@ -119,6 +121,7 @@ class BitmapPlatformDevice : public SkBitmapDevice, public PlatformDevice { ...@@ -119,6 +121,7 @@ class BitmapPlatformDevice : public SkBitmapDevice, public PlatformDevice {
SkRegion clip_region_; SkRegion clip_region_;
DISALLOW_COPY_AND_ASSIGN(BitmapPlatformDevice); DISALLOW_COPY_AND_ASSIGN(BitmapPlatformDevice);
friend class ScopedPlatformPaint;
}; };
} // namespace skia } // namespace skia
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
namespace skia { namespace skia {
class ScopedPlatformPaint;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// For now we just use SkBitmap for SkBitmapDevice // For now we just use SkBitmap for SkBitmapDevice
// //
...@@ -40,13 +42,15 @@ class BitmapPlatformDevice : public SkBitmapDevice, public PlatformDevice { ...@@ -40,13 +42,15 @@ class BitmapPlatformDevice : public SkBitmapDevice, public PlatformDevice {
explicit BitmapPlatformDevice(const SkBitmap& other); explicit BitmapPlatformDevice(const SkBitmap& other);
~BitmapPlatformDevice() override; ~BitmapPlatformDevice() override;
PlatformSurface BeginPlatformPaint() override;
protected: protected:
SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) override; SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) override;
private: private:
PlatformSurface BeginPlatformPaint() override;
DISALLOW_COPY_AND_ASSIGN(BitmapPlatformDevice); DISALLOW_COPY_AND_ASSIGN(BitmapPlatformDevice);
friend class ScopedPlatformPaint;
}; };
} // namespace skia } // namespace skia
......
...@@ -200,7 +200,6 @@ BitmapPlatformDevice::BitmapPlatformDevice( ...@@ -200,7 +200,6 @@ BitmapPlatformDevice::BitmapPlatformDevice(
config_dirty_(true), // Want to load the config next time. config_dirty_(true), // Want to load the config next time.
transform_(SkMatrix::I()) { transform_(SkMatrix::I()) {
// The data object is already ref'ed for us by create(). // The data object is already ref'ed for us by create().
SkDEBUGCODE(begin_paint_count_ = 0);
if (hbitmap) { if (hbitmap) {
SetPlatformDevice(this, this); SetPlatformDevice(this, this);
// Initialize the clip region to the entire bitmap. // Initialize the clip region to the entire bitmap.
...@@ -214,21 +213,14 @@ BitmapPlatformDevice::BitmapPlatformDevice( ...@@ -214,21 +213,14 @@ BitmapPlatformDevice::BitmapPlatformDevice(
} }
BitmapPlatformDevice::~BitmapPlatformDevice() { BitmapPlatformDevice::~BitmapPlatformDevice() {
SkASSERT(begin_paint_count_ == 0);
if (hdc_) if (hdc_)
ReleaseBitmapDC(); ReleaseBitmapDC();
} }
HDC BitmapPlatformDevice::BeginPlatformPaint() { HDC BitmapPlatformDevice::BeginPlatformPaint() {
SkDEBUGCODE(begin_paint_count_++);
return GetBitmapDC(); return GetBitmapDC();
} }
void BitmapPlatformDevice::EndPlatformPaint() {
SkASSERT(begin_paint_count_--);
PlatformDevice::EndPlatformPaint();
}
void BitmapPlatformDevice::setMatrixClip(const SkMatrix& transform, void BitmapPlatformDevice::setMatrixClip(const SkMatrix& transform,
const SkRegion& region, const SkRegion& region,
const SkClipStack&) { const SkClipStack&) {
...@@ -285,7 +277,6 @@ void BitmapPlatformDevice::DrawToHDC(HDC dc, int x, int y, ...@@ -285,7 +277,6 @@ void BitmapPlatformDevice::DrawToHDC(HDC dc, int x, int y,
} }
LoadTransformToDC(source_dc, transform_); LoadTransformToDC(source_dc, transform_);
EndPlatformPaint();
if (created_dc) if (created_dc)
ReleaseBitmapDC(); ReleaseBitmapDC();
} }
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
namespace skia { namespace skia {
class ScopedPlatformPaint;
// A device is basically a wrapper around SkBitmap that provides a surface for // A device is basically a wrapper around SkBitmap that provides a surface for
// SkCanvas to draw into. Our device provides a surface Windows can also write // SkCanvas to draw into. Our device provides a surface Windows can also write
// to. BitmapPlatformDevice creates a bitmap using CreateDIBSection() in a // to. BitmapPlatformDevice creates a bitmap using CreateDIBSection() in a
...@@ -38,14 +40,8 @@ class SK_API BitmapPlatformDevice : public SkBitmapDevice, public PlatformDevice ...@@ -38,14 +40,8 @@ class SK_API BitmapPlatformDevice : public SkBitmapDevice, public PlatformDevice
~BitmapPlatformDevice() override; ~BitmapPlatformDevice() override;
// PlatformDevice overrides // Loads (lazily) the given transform and clipping region into the HDC. This
// Retrieves the bitmap DC, which is the memory DC for our bitmap data. The // is overridden from SkBaseDevice, where it is deprecated.
// bitmap DC is lazy created.
PlatformSurface BeginPlatformPaint() override;
void EndPlatformPaint() override;
// Loads the given transform and clipping region into the HDC. This is
// overridden from SkBaseDevice.
void setMatrixClip(const SkMatrix& transform, void setMatrixClip(const SkMatrix& transform,
const SkRegion& region, const SkRegion& region,
const SkClipStack&) override; const SkClipStack&) override;
...@@ -61,6 +57,11 @@ class SK_API BitmapPlatformDevice : public SkBitmapDevice, public PlatformDevice ...@@ -61,6 +57,11 @@ class SK_API BitmapPlatformDevice : public SkBitmapDevice, public PlatformDevice
SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) override; SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) override;
private: private:
// PlatformDevice override
// Retrieves the bitmap DC, which is the memory DC for our bitmap data. The
// bitmap DC may be lazily created.
PlatformSurface BeginPlatformPaint() override;
// Private constructor. // Private constructor.
BitmapPlatformDevice(HBITMAP hbitmap, const SkBitmap& bitmap); BitmapPlatformDevice(HBITMAP hbitmap, const SkBitmap& bitmap);
...@@ -103,11 +104,8 @@ class SK_API BitmapPlatformDevice : public SkBitmapDevice, public PlatformDevice ...@@ -103,11 +104,8 @@ class SK_API BitmapPlatformDevice : public SkBitmapDevice, public PlatformDevice
// when |hbitmap_| is NULL (will be a NOP). // when |hbitmap_| is NULL (will be a NOP).
void LoadConfig(); void LoadConfig();
#ifdef SK_DEBUG
int begin_paint_count_;
#endif
DISALLOW_COPY_AND_ASSIGN(BitmapPlatformDevice); DISALLOW_COPY_AND_ASSIGN(BitmapPlatformDevice);
friend class ScopedPlatformPaint;
}; };
} // namespace skia } // namespace skia
......
...@@ -65,20 +65,6 @@ bool SupportsPlatformPaint(const SkCanvas* canvas) { ...@@ -65,20 +65,6 @@ bool SupportsPlatformPaint(const SkCanvas* canvas) {
return GetPlatformDevice(GetTopDevice(*canvas)) != nullptr; return GetPlatformDevice(GetTopDevice(*canvas)) != nullptr;
} }
PlatformSurface BeginPlatformPaint(SkCanvas* canvas) {
PlatformDevice* platform_device = GetPlatformDevice(GetTopDevice(*canvas));
if (platform_device)
return platform_device->BeginPlatformPaint();
return 0;
}
void EndPlatformPaint(SkCanvas* canvas) {
PlatformDevice* platform_device = GetPlatformDevice(GetTopDevice(*canvas));
if (platform_device)
platform_device->EndPlatformPaint();
}
size_t PlatformCanvasStrideForWidth(unsigned width) { size_t PlatformCanvasStrideForWidth(unsigned width) {
return 4 * width; return 4 * width;
} }
...@@ -116,5 +102,12 @@ CGContextRef GetBitmapContext(const SkCanvas& canvas) { ...@@ -116,5 +102,12 @@ CGContextRef GetBitmapContext(const SkCanvas& canvas) {
#endif #endif
ScopedPlatformPaint::ScopedPlatformPaint(SkCanvas* canvas) :
canvas_(canvas),
platform_surface_(nullptr) {
PlatformDevice* platform_device = GetPlatformDevice(GetTopDevice(*canvas));
if (platform_device)
platform_surface_ = platform_device->BeginPlatformPaint();
}
} // namespace skia } // namespace skia
...@@ -145,27 +145,16 @@ SK_API bool GetWritablePixels(SkCanvas* canvas, SkPixmap* pixmap); ...@@ -145,27 +145,16 @@ SK_API bool GetWritablePixels(SkCanvas* canvas, SkPixmap* pixmap);
// return NULL PlatformSurface. // return NULL PlatformSurface.
SK_API bool SupportsPlatformPaint(const SkCanvas* canvas); SK_API bool SupportsPlatformPaint(const SkCanvas* canvas);
// These calls should surround calls to platform drawing routines, the // This object guards calls to platform drawing routines. The surface
// surface returned here can be used with the native platform routines. // returned from GetPlatformSurface() can be used with the native platform
// // routines.
// Call EndPlatformPaint when you are done and want to use skia operations
// after calling the platform-specific BeginPlatformPaint; this will
// synchronize the bitmap to OS if necessary.
SK_API PlatformSurface BeginPlatformPaint(SkCanvas* canvas);
SK_API void EndPlatformPaint(SkCanvas* canvas);
// Helper class for pairing calls to BeginPlatformPaint and EndPlatformPaint.
// Upon construction invokes BeginPlatformPaint, and upon destruction invokes
// EndPlatformPaint.
class SK_API ScopedPlatformPaint { class SK_API ScopedPlatformPaint {
public: public:
explicit ScopedPlatformPaint(SkCanvas* canvas) : canvas_(canvas) { explicit ScopedPlatformPaint(SkCanvas* canvas);
platform_surface_ = BeginPlatformPaint(canvas);
}
~ScopedPlatformPaint() { EndPlatformPaint(canvas_); }
// Returns the PlatformSurface to use for native platform drawing calls. // Returns the PlatformSurface to use for native platform drawing calls.
PlatformSurface GetPlatformSurface() { return platform_surface_; } PlatformSurface GetPlatformSurface() { return platform_surface_; }
private: private:
SkCanvas* canvas_; SkCanvas* canvas_;
PlatformSurface platform_surface_; PlatformSurface platform_surface_;
......
...@@ -23,6 +23,7 @@ class SkRegion; ...@@ -23,6 +23,7 @@ class SkRegion;
namespace skia { namespace skia {
class PlatformDevice; class PlatformDevice;
class ScopedPlatformPaint;
// The following routines provide accessor points for the functionality // The following routines provide accessor points for the functionality
// exported by the various PlatformDevice ports. // exported by the various PlatformDevice ports.
...@@ -61,14 +62,6 @@ class SK_API PlatformDevice { ...@@ -61,14 +62,6 @@ class SK_API PlatformDevice {
virtual CGContextRef GetBitmapContext() = 0; virtual CGContextRef GetBitmapContext() = 0;
#endif #endif
// The DC that corresponds to the bitmap, used for GDI operations drawing
// into the bitmap. This is possibly heavyweight, so it should be existant
// only during one pass of rendering.
virtual PlatformSurface BeginPlatformPaint();
// Finish a previous call to beginPlatformPaint.
virtual void EndPlatformPaint();
#if defined(OS_WIN) #if defined(OS_WIN)
// Loads a SkPath into the GDI context. The path can there after be used for // Loads a SkPath into the GDI context. The path can there after be used for
// clipping or as a stroke. Returns false if the path failed to be loaded. // clipping or as a stroke. Returns false if the path failed to be loaded.
...@@ -87,6 +80,7 @@ class SK_API PlatformDevice { ...@@ -87,6 +80,7 @@ class SK_API PlatformDevice {
#endif #endif
protected: protected:
#if defined(OS_WIN) #if defined(OS_WIN)
// Arrays must be inside structures. // Arrays must be inside structures.
struct CubicPoints { struct CubicPoints {
...@@ -102,6 +96,14 @@ class SK_API PlatformDevice { ...@@ -102,6 +96,14 @@ class SK_API PlatformDevice {
// Transforms SkPath's paths into a series of cubic path. // Transforms SkPath's paths into a series of cubic path.
static bool SkPathToCubicPaths(CubicPaths* paths, const SkPath& skpath); static bool SkPathToCubicPaths(CubicPaths* paths, const SkPath& skpath);
#endif #endif
private:
// The DC that corresponds to the bitmap, used for GDI operations drawing
// into the bitmap. This is possibly heavyweight, so it should be existant
// only during one pass of rendering.
virtual PlatformSurface BeginPlatformPaint();
friend class ScopedPlatformPaint;
}; };
} // namespace skia } // namespace skia
......
...@@ -10,8 +10,4 @@ PlatformSurface PlatformDevice::BeginPlatformPaint() { ...@@ -10,8 +10,4 @@ PlatformSurface PlatformDevice::BeginPlatformPaint() {
return NULL; return NULL;
} }
void PlatformDevice::EndPlatformPaint() {
// We don't need to do anything on Linux here.
}
} // namespace skia } // namespace skia
...@@ -10,8 +10,4 @@ CGContextRef PlatformDevice::BeginPlatformPaint() { ...@@ -10,8 +10,4 @@ CGContextRef PlatformDevice::BeginPlatformPaint() {
return GetBitmapContext(); return GetBitmapContext();
} }
void PlatformDevice::EndPlatformPaint() {
// Flushing will be done in onAccessBitmap.
}
} // namespace skia } // namespace skia
...@@ -15,11 +15,6 @@ PlatformSurface PlatformDevice::BeginPlatformPaint() { ...@@ -15,11 +15,6 @@ PlatformSurface PlatformDevice::BeginPlatformPaint() {
return 0; return 0;
} }
void PlatformDevice::EndPlatformPaint() {
// We don't clear the DC here since it will be likely to be used again.
// Flushing will be done in onAccessBitmap.
}
// static // static
bool PlatformDevice::LoadPathToDC(HDC context, const SkPath& path) { bool PlatformDevice::LoadPathToDC(HDC context, const SkPath& path) {
switch (path.getFillType()) { switch (path.getFillType()) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment