Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / platform / graphics / paint / SkPictureBuilder.h
blob035271f8177405c00f43689220554a4621e2942d
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef SkPictureBuilder_h
6 #define SkPictureBuilder_h
8 #include "platform/RuntimeEnabledFeatures.h"
9 #include "platform/graphics/GraphicsContext.h"
10 #include "platform/graphics/paint/DisplayItemList.h"
11 #include "wtf/OwnPtr.h"
13 namespace blink {
15 // When slimming paint ships we can remove this SkPicture abstraction and
16 // rely on DisplayItemList here.
17 class SkPictureBuilder {
18 WTF_MAKE_NONCOPYABLE(SkPictureBuilder);
19 STACK_ALLOCATED();
20 public:
21 SkPictureBuilder(const FloatRect& bounds, SkMetaData* metaData = 0, GraphicsContext* containingContext = 0)
22 : m_bounds(bounds)
24 GraphicsContext::DisabledMode disabledMode = GraphicsContext::NothingDisabled;
25 if (containingContext && containingContext->contextDisabled())
26 disabledMode = GraphicsContext::FullyDisabled;
28 m_displayItemList = DisplayItemList::create();
29 m_context = adoptPtr(new GraphicsContext(m_displayItemList.get(), disabledMode, metaData));
31 if (containingContext) {
32 m_context->setDeviceScaleFactor(containingContext->deviceScaleFactor());
33 m_context->setPrinting(containingContext->printing());
37 GraphicsContext& context() { return *m_context; }
39 PassRefPtr<const SkPicture> endRecording()
41 m_context->beginRecording(m_bounds);
42 m_displayItemList->commitNewDisplayItemsAndReplay(*m_context);
43 return m_context->endRecording();
46 private:
47 OwnPtr<DisplayItemList> m_displayItemList;
48 OwnPtr<GraphicsContext> m_context;
49 FloatRect m_bounds;
52 } // namespace blink
54 #endif // SkPictureBuilder_h