flutter_flutter/engine/core/painting/PaintingContext.cpp
Adam Barth 510cddef63 Integrate custom paint with the DocumentLifecycle
Instead of running paint requests during microtasks, we run them after updating
layout for the current frame. After draining all the paint requests, we then
drain whatever commits are available.

It's still possible that requestPaint callbacks can dirty style and layout
information, so we need to clean that information after servicing the requests.
Ideally we'd block these callbacks from dirtying style or layout information.

R=ojan@chromium.org

Review URL: https://codereview.chromium.org/1027563002
2015-03-19 21:58:14 -07:00

53 lines
1.4 KiB
C++

// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/engine/config.h"
#include "sky/engine/core/painting/PaintingContext.h"
#include "sky/engine/core/dom/Document.h"
#include "sky/engine/core/dom/Element.h"
#include "sky/engine/core/painting/PaintingTasks.h"
#include "sky/engine/platform/geometry/IntRect.h"
#include "third_party/skia/include/core/SkCanvas.h"
namespace blink {
PassRefPtr<PaintingContext> PaintingContext::create(PassRefPtr<Element> element, const FloatSize& size)
{
return adoptRef(new PaintingContext(element, size));
}
PaintingContext::PaintingContext(PassRefPtr<Element> element, const FloatSize& size)
: m_element(element)
, m_size(size)
{
m_displayList = adoptRef(new DisplayList);
m_canvas = m_displayList->beginRecording(expandedIntSize(m_size));
}
PaintingContext::~PaintingContext()
{
}
void PaintingContext::drawCircle(double x, double y, double radius, Paint* paint)
{
if (!m_canvas)
return;
ASSERT(paint);
ASSERT(m_displayList->isRecording());
m_canvas->drawCircle(x, y, radius, paint->paint());
}
void PaintingContext::commit()
{
if (!m_canvas)
return;
m_displayList->endRecording();
m_canvas = nullptr;
PaintingTasks::enqueueCommit(m_element, m_displayList.release());
m_element->document().scheduleVisualUpdate();
}
} // namespace blink