Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(195)

Unified Diff: third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridge.cpp

Issue 2739533003: Revert of Make cc/paint have concrete types (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridge.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridge.cpp b/third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridge.cpp
index 046285877acd3f62b1631beea4860604e17d88e6..7129cc32c4f599cccddae76d3a5b4cf4b94165d7 100644
--- a/third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridge.cpp
+++ b/third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridge.cpp
@@ -82,13 +82,13 @@
};
#endif // USE_IOSURFACE_FOR_2D_CANVAS
-static sk_sp<SkSurface> createSkSurface(GrContext* gr,
- const IntSize& size,
- int msaaSampleCount,
- OpacityMode opacityMode,
- sk_sp<SkColorSpace> colorSpace,
- SkColorType colorType,
- bool* surfaceIsAccelerated) {
+static sk_sp<PaintSurface> createSkSurface(GrContext* gr,
+ const IntSize& size,
+ int msaaSampleCount,
+ OpacityMode opacityMode,
+ sk_sp<SkColorSpace> colorSpace,
+ SkColorType colorType,
+ bool* surfaceIsAccelerated) {
if (gr)
gr->resetContext();
@@ -97,18 +97,18 @@
SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), colorType,
alphaType, colorSpace);
SkSurfaceProps disableLCDProps(0, kUnknown_SkPixelGeometry);
- sk_sp<SkSurface> surface;
+ sk_sp<PaintSurface> surface;
if (gr) {
*surfaceIsAccelerated = true;
- surface = SkSurface::MakeRenderTarget(
+ surface = PaintSurface::MakeRenderTarget(
gr, SkBudgeted::kNo, info, msaaSampleCount,
Opaque == opacityMode ? 0 : &disableLCDProps);
}
if (!surface) {
*surfaceIsAccelerated = false;
- surface = SkSurface::MakeRaster(
+ surface = PaintSurface::MakeRaster(
info, Opaque == opacityMode ? 0 : &disableLCDProps);
}
@@ -174,7 +174,7 @@
DCHECK(m_isDeferralEnabled);
m_recorder = WTF::wrapUnique(new PaintRecorder);
PaintCanvas* canvas =
- m_recorder->beginRecording(m_size.width(), m_size.height());
+ m_recorder->beginRecording(m_size.width(), m_size.height(), nullptr);
// Always save an initial frame, to support resetting the top level matrix
// and clip.
canvas->save();
@@ -187,11 +187,6 @@
void Canvas2DLayerBridge::setLoggerForTesting(std::unique_ptr<Logger> logger) {
m_logger = std::move(logger);
-}
-
-void Canvas2DLayerBridge::ResetSurface() {
- m_surfacePaintCanvas.reset();
- m_surface.reset();
}
bool Canvas2DLayerBridge::shouldAccelerate(AccelerationHint hint) const {
@@ -502,8 +497,8 @@
}
TRACE_EVENT0("blink", "Canvas2DLayerBridge::hibernate");
- sk_sp<SkSurface> tempHibernationSurface =
- SkSurface::MakeRasterN32Premul(m_size.width(), m_size.height());
+ sk_sp<PaintSurface> tempHibernationSurface =
+ PaintSurface::MakeRasterN32Premul(m_size.width(), m_size.height());
if (!tempHibernationSurface) {
m_logger->reportHibernationEvent(HibernationAbortedDueToAllocationFailure);
return;
@@ -517,12 +512,12 @@
// a surface, and we have an early exit at the top of this function for when
// 'this' does not already have a surface.
DCHECK(!m_haveRecordedDrawCommands);
- SkPaint copyPaint;
+ PaintFlags copyPaint;
copyPaint.setBlendMode(SkBlendMode::kSrc);
m_surface->draw(tempHibernationSurface->getCanvas(), 0, 0,
&copyPaint); // GPU readback
m_hibernationImage = tempHibernationSurface->makeImageSnapshot();
- ResetSurface();
+ m_surface.reset(); // destroy the GPU-backed buffer
m_layer->clearTexture();
#if USE_IOSURFACE_FOR_2D_CANVAS
clearCHROMIUMImageCache();
@@ -547,7 +542,7 @@
}
}
-SkSurface* Canvas2DLayerBridge::getOrCreateSurface(AccelerationHint hint) {
+PaintSurface* Canvas2DLayerBridge::getOrCreateSurface(AccelerationHint hint) {
if (m_surface)
return m_surface.get();
@@ -568,13 +563,11 @@
wantAcceleration ? m_contextProvider->grContext() : nullptr, m_size,
m_msaaSampleCount, m_opacityMode, skSurfaceColorSpace(), m_colorType,
&surfaceIsAccelerated);
- m_surfacePaintCanvas =
- WTF::wrapUnique(new PaintCanvas(m_surface->getCanvas()));
if (m_surface) {
// Always save an initial frame, to support resetting the top level matrix
// and clip.
- m_surfacePaintCanvas->save();
+ m_surface->getCanvas()->save();
} else {
reportSurfaceCreationFailure();
}
@@ -600,7 +593,7 @@
m_logger->reportHibernationEvent(HibernationEndedWithFallbackToSW);
}
- SkPaint copyPaint;
+ PaintFlags copyPaint;
copyPaint.setBlendMode(SkBlendMode::kSrc);
m_surface->getCanvas()->drawImage(m_hibernationImage.get(), 0, 0,
&copyPaint);
@@ -610,7 +603,7 @@
m_imageBuffer->updateGPUMemoryUsage();
if (m_imageBuffer && !m_isDeferralEnabled)
- m_imageBuffer->resetCanvas(m_surfacePaintCanvas.get());
+ m_imageBuffer->resetCanvas(m_surface->getCanvas());
}
return m_surface.get();
@@ -618,8 +611,8 @@
PaintCanvas* Canvas2DLayerBridge::canvas() {
if (!m_isDeferralEnabled) {
- getOrCreateSurface();
- return m_surfacePaintCanvas.get();
+ PaintSurface* s = getOrCreateSurface();
+ return s ? s->getCanvas() : nullptr;
}
return m_recorder->getRecordingCanvas();
}
@@ -651,9 +644,9 @@
m_isDeferralEnabled = false;
m_recorder.reset();
// install the current matrix/clip stack onto the immediate canvas
- getOrCreateSurface();
- if (m_imageBuffer && m_surfacePaintCanvas)
- m_imageBuffer->resetCanvas(m_surfacePaintCanvas.get());
+ PaintSurface* surface = getOrCreateSurface();
+ if (m_imageBuffer && surface)
+ m_imageBuffer->resetCanvas(surface->getCanvas());
}
void Canvas2DLayerBridge::setImageBuffer(ImageBuffer* imageBuffer) {
@@ -673,7 +666,7 @@
m_imageBuffer = nullptr;
m_destructionInProgress = true;
setIsHidden(true);
- ResetSurface();
+ m_surface.reset();
if (m_layer && m_accelerationMode != DisableAcceleration) {
GraphicsLayer::unregisterContentsLayer(m_layer->layer());
@@ -718,20 +711,20 @@
}
if (!isHidden() && m_softwareRenderingWhileHidden) {
flushRecordingOnly();
- SkPaint copyPaint;
+ PaintFlags copyPaint;
copyPaint.setBlendMode(SkBlendMode::kSrc);
- sk_sp<SkSurface> oldSurface = std::move(m_surface);
- ResetSurface();
+ sk_sp<PaintSurface> oldSurface = std::move(m_surface);
+ m_surface.reset();
m_softwareRenderingWhileHidden = false;
- SkSurface* newSurface =
+ PaintSurface* newSurface =
getOrCreateSurface(PreferAccelerationAfterVisibilityChange);
if (newSurface) {
if (oldSurface)
oldSurface->draw(newSurface->getCanvas(), 0, 0, &copyPaint);
if (m_imageBuffer && !m_isDeferralEnabled) {
- m_imageBuffer->resetCanvas(m_surfacePaintCanvas.get());
+ m_imageBuffer->resetCanvas(m_surface->getCanvas());
}
}
}
@@ -833,7 +826,7 @@
return false;
if (m_contextProvider->contextGL()->GetGraphicsResetStatusKHR() !=
GL_NO_ERROR) {
- ResetSurface();
+ m_surface.reset();
for (auto mailboxInfo = m_mailboxes.begin();
mailboxInfo != m_mailboxes.end(); ++mailboxInfo) {
if (mailboxInfo->m_image)
@@ -863,7 +856,7 @@
if (sharedGL && sharedGL->GetGraphicsResetStatusKHR() == GL_NO_ERROR) {
GrContext* grCtx = m_contextProvider->grContext();
bool surfaceIsAccelerated;
- sk_sp<SkSurface> surface(createSkSurface(
+ sk_sp<PaintSurface> surface(createSkSurface(
grCtx, m_size, m_msaaSampleCount, m_opacityMode, skSurfaceColorSpace(),
m_colorType, &surfaceIsAccelerated));
if (!m_surface)

Powered by Google App Engine
This is Rietveld 408576698