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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/paint/SkPictureBuilder.h

Issue 1841833002: Deal gracefully with null {GraphicsContext,SkPictureBuilder}.endRecording() results. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't end recording twice in DrawingRecorder. Created 4 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef SkPictureBuilder_h 5 #ifndef SkPictureBuilder_h
6 #define SkPictureBuilder_h 6 #define SkPictureBuilder_h
7 7
8 #include "platform/RuntimeEnabledFeatures.h" 8 #include "platform/RuntimeEnabledFeatures.h"
9 #include "platform/graphics/GraphicsContext.h" 9 #include "platform/graphics/GraphicsContext.h"
10 #include "platform/graphics/paint/PaintController.h" 10 #include "platform/graphics/paint/PaintController.h"
11 #include "wtf/Allocator.h" 11 #include "wtf/Allocator.h"
12 #include "wtf/Noncopyable.h" 12 #include "wtf/Noncopyable.h"
13 #include "wtf/OwnPtr.h" 13 #include "wtf/OwnPtr.h"
14 14
15 namespace blink { 15 namespace blink {
16 16
17 // When slimming paint ships we can remove this SkPicture abstraction and 17 // When slimming paint ships we can remove this SkPicture abstraction and
18 // rely on PaintController here. 18 // rely on PaintController here.
19 class SkPictureBuilder final { 19 class SkPictureBuilder final {
20 WTF_MAKE_NONCOPYABLE(SkPictureBuilder); 20 WTF_MAKE_NONCOPYABLE(SkPictureBuilder);
21 public: 21 public:
22 // Constructs a new builder with the given bounds for the resulting recorded picture. If
23 // |metadata| is specified, that metadata is propagated to the builder's int ernal canvas. If
24 // |containingContext| is specified, the device scale factor, printing, and disabled state are
25 // propagated to the builder's internal context.
22 SkPictureBuilder(const FloatRect& bounds, SkMetaData* metaData = nullptr, Gr aphicsContext* containingContext = nullptr) 26 SkPictureBuilder(const FloatRect& bounds, SkMetaData* metaData = nullptr, Gr aphicsContext* containingContext = nullptr)
23 : m_bounds(bounds) 27 : m_bounds(bounds)
24 { 28 {
25 GraphicsContext::DisabledMode disabledMode = GraphicsContext::NothingDis abled; 29 GraphicsContext::DisabledMode disabledMode = GraphicsContext::NothingDis abled;
26 if (containingContext && containingContext->contextDisabled()) 30 if (containingContext && containingContext->contextDisabled())
27 disabledMode = GraphicsContext::FullyDisabled; 31 disabledMode = GraphicsContext::FullyDisabled;
28 32
29 m_paintController = PaintController::create(); 33 m_paintController = PaintController::create();
30 m_paintController->beginSkippingCache(); 34 m_paintController->beginSkippingCache();
31 m_context = adoptPtr(new GraphicsContext(*m_paintController, disabledMod e, metaData)); 35 m_context = adoptPtr(new GraphicsContext(*m_paintController, disabledMod e, metaData));
32 36
33 if (containingContext) { 37 if (containingContext) {
34 m_context->setDeviceScaleFactor(containingContext->deviceScaleFactor ()); 38 m_context->setDeviceScaleFactor(containingContext->deviceScaleFactor ());
35 m_context->setPrinting(containingContext->printing()); 39 m_context->setPrinting(containingContext->printing());
36 } 40 }
37 } 41 }
38 42
39 GraphicsContext& context() { return *m_context; } 43 GraphicsContext& context() { return *m_context; }
40 44
45 // Returns a picture capturing all drawing performed on the builder's contex t since
46 // construction, or nullptr if the picture could not be created.
41 PassRefPtr<SkPicture> endRecording() 47 PassRefPtr<SkPicture> endRecording()
42 { 48 {
43 m_context->beginRecording(m_bounds); 49 m_context->beginRecording(m_bounds);
44 m_paintController->endSkippingCache(); 50 m_paintController->endSkippingCache();
45 m_paintController->commitNewDisplayItems(); 51 m_paintController->commitNewDisplayItems();
46 m_paintController->paintArtifact().replay(*m_context); 52 m_paintController->paintArtifact().replay(*m_context);
47 return m_context->endRecording(); 53 return m_context->endRecording();
48 } 54 }
49 55
50 private: 56 private:
51 OwnPtr<PaintController> m_paintController; 57 OwnPtr<PaintController> m_paintController;
52 OwnPtr<GraphicsContext> m_context; 58 OwnPtr<GraphicsContext> m_context;
53 FloatRect m_bounds; 59 FloatRect m_bounds;
54 }; 60 };
55 61
56 } // namespace blink 62 } // namespace blink
57 63
58 #endif // SkPictureBuilder_h 64 #endif // SkPictureBuilder_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698