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() {
style |= WS_EX_LAYERED;
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,
RGB(0xFF, 0xFF, 0xFF), &blend, ULW_ALPHA);
skia::EndPlatformPaint(contents_.get());
} else {
HDC hdc = ::GetDC(hwnd_);
RECT src_rect = rect.ToRECT();
......
......@@ -46,6 +46,8 @@ typedef struct _cairo_surface cairo_surface_t;
namespace skia {
class ScopedPlatformPaint;
// -----------------------------------------------------------------------------
// 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
......@@ -84,13 +86,13 @@ class BitmapPlatformDevice : public SkBitmapDevice, public PlatformDevice {
const SkRegion& region,
const SkClipStack&) override;
// Overridden from PlatformDevice:
cairo_t* BeginPlatformPaint() override;
protected:
SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) override;
private:
// Overridden from PlatformDevice:
cairo_t* BeginPlatformPaint() override;
static BitmapPlatformDevice* Create(int width, int height, bool is_opaque,
cairo_surface_t* surface);
......@@ -119,6 +121,7 @@ class BitmapPlatformDevice : public SkBitmapDevice, public PlatformDevice {
SkRegion clip_region_;
DISALLOW_COPY_AND_ASSIGN(BitmapPlatformDevice);
friend class ScopedPlatformPaint;
};
} // namespace skia
......
......@@ -14,6 +14,8 @@
namespace skia {
class ScopedPlatformPaint;
// -----------------------------------------------------------------------------
// For now we just use SkBitmap for SkBitmapDevice
//
......@@ -40,13 +42,15 @@ class BitmapPlatformDevice : public SkBitmapDevice, public PlatformDevice {
explicit BitmapPlatformDevice(const SkBitmap& other);
~BitmapPlatformDevice() override;
PlatformSurface BeginPlatformPaint() override;
protected:
SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) override;
private:
PlatformSurface BeginPlatformPaint() override;
DISALLOW_COPY_AND_ASSIGN(BitmapPlatformDevice);
friend class ScopedPlatformPaint;
};
} // namespace skia
......
......@@ -200,7 +200,6 @@ BitmapPlatformDevice::BitmapPlatformDevice(
config_dirty_(true), // Want to load the config next time.
transform_(SkMatrix::I()) {
// The data object is already ref'ed for us by create().
SkDEBUGCODE(begin_paint_count_ = 0);
if (hbitmap) {
SetPlatformDevice(this, this);
// Initialize the clip region to the entire bitmap.
......@@ -214,21 +213,14 @@ BitmapPlatformDevice::BitmapPlatformDevice(
}
BitmapPlatformDevice::~BitmapPlatformDevice() {
SkASSERT(begin_paint_count_ == 0);
if (hdc_)
ReleaseBitmapDC();
}
HDC BitmapPlatformDevice::BeginPlatformPaint() {
SkDEBUGCODE(begin_paint_count_++);
return GetBitmapDC();
}
void BitmapPlatformDevice::EndPlatformPaint() {
SkASSERT(begin_paint_count_--);
PlatformDevice::EndPlatformPaint();
}
void BitmapPlatformDevice::setMatrixClip(const SkMatrix& transform,
const SkRegion& region,
const SkClipStack&) {
......@@ -285,7 +277,6 @@ void BitmapPlatformDevice::DrawToHDC(HDC dc, int x, int y,
}
LoadTransformToDC(source_dc, transform_);
EndPlatformPaint();
if (created_dc)
ReleaseBitmapDC();
}
......
......@@ -12,6 +12,8 @@
namespace skia {
class ScopedPlatformPaint;
// 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
// to. BitmapPlatformDevice creates a bitmap using CreateDIBSection() in a
......@@ -38,14 +40,8 @@ class SK_API BitmapPlatformDevice : public SkBitmapDevice, public PlatformDevice
~BitmapPlatformDevice() override;
// PlatformDevice overrides
// Retrieves the bitmap DC, which is the memory DC for our bitmap data. The
// 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.
// Loads (lazily) the given transform and clipping region into the HDC. This
// is overridden from SkBaseDevice, where it is deprecated.
void setMatrixClip(const SkMatrix& transform,
const SkRegion& region,
const SkClipStack&) override;
......@@ -61,6 +57,11 @@ class SK_API BitmapPlatformDevice : public SkBitmapDevice, public PlatformDevice
SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) override;
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.
BitmapPlatformDevice(HBITMAP hbitmap, const SkBitmap& bitmap);
......@@ -103,11 +104,8 @@ class SK_API BitmapPlatformDevice : public SkBitmapDevice, public PlatformDevice
// when |hbitmap_| is NULL (will be a NOP).
void LoadConfig();
#ifdef SK_DEBUG
int begin_paint_count_;
#endif
DISALLOW_COPY_AND_ASSIGN(BitmapPlatformDevice);
friend class ScopedPlatformPaint;
};
} // namespace skia
......
......@@ -65,20 +65,6 @@ bool SupportsPlatformPaint(const SkCanvas* canvas) {
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) {
return 4 * width;
}
......@@ -116,5 +102,12 @@ CGContextRef GetBitmapContext(const SkCanvas& canvas) {
#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
......@@ -145,27 +145,16 @@ SK_API bool GetWritablePixels(SkCanvas* canvas, SkPixmap* pixmap);
// return NULL PlatformSurface.
SK_API bool SupportsPlatformPaint(const SkCanvas* canvas);
// These calls should surround calls to platform drawing routines, the
// surface returned here 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.
// This object guards calls to platform drawing routines. The surface
// returned from GetPlatformSurface() can be used with the native platform
// routines.
class SK_API ScopedPlatformPaint {
public:
explicit ScopedPlatformPaint(SkCanvas* canvas) : canvas_(canvas) {
platform_surface_ = BeginPlatformPaint(canvas);
}
~ScopedPlatformPaint() { EndPlatformPaint(canvas_); }
explicit ScopedPlatformPaint(SkCanvas* canvas);
// Returns the PlatformSurface to use for native platform drawing calls.
PlatformSurface GetPlatformSurface() { return platform_surface_; }
private:
SkCanvas* canvas_;
PlatformSurface platform_surface_;
......
......@@ -23,6 +23,7 @@ class SkRegion;
namespace skia {
class PlatformDevice;
class ScopedPlatformPaint;
// The following routines provide accessor points for the functionality
// exported by the various PlatformDevice ports.
......@@ -61,14 +62,6 @@ class SK_API PlatformDevice {
virtual CGContextRef GetBitmapContext() = 0;
#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)
// 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.
......@@ -87,6 +80,7 @@ class SK_API PlatformDevice {
#endif
protected:
#if defined(OS_WIN)
// Arrays must be inside structures.
struct CubicPoints {
......@@ -102,6 +96,14 @@ class SK_API PlatformDevice {
// Transforms SkPath's paths into a series of cubic path.
static bool SkPathToCubicPaths(CubicPaths* paths, const SkPath& skpath);
#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
......
......@@ -10,8 +10,4 @@ PlatformSurface PlatformDevice::BeginPlatformPaint() {
return NULL;
}
void PlatformDevice::EndPlatformPaint() {
// We don't need to do anything on Linux here.
}
} // namespace skia
......@@ -10,8 +10,4 @@ CGContextRef PlatformDevice::BeginPlatformPaint() {
return GetBitmapContext();
}
void PlatformDevice::EndPlatformPaint() {
// Flushing will be done in onAccessBitmap.
}
} // namespace skia
......@@ -15,11 +15,6 @@ PlatformSurface PlatformDevice::BeginPlatformPaint() {
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
bool PlatformDevice::LoadPathToDC(HDC context, const SkPath& path) {
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