OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. |
3 * Copyright (C) 2013 Google Inc. All rights reserved. | 3 * Copyright (C) 2013 Google Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "config.h" | 27 #include "config.h" |
28 #include "platform/graphics/GraphicsContext.h" | 28 #include "platform/graphics/GraphicsContext.h" |
29 | 29 |
30 #include "platform/RuntimeEnabledFeatures.h" | 30 #include "platform/RuntimeEnabledFeatures.h" |
31 #include "platform/TraceEvent.h" | 31 #include "platform/TraceEvent.h" |
32 #include "platform/geometry/IntRect.h" | 32 #include "platform/geometry/IntRect.h" |
33 #include "platform/graphics/ColorSpace.h" | 33 #include "platform/graphics/ColorSpace.h" |
34 #include "platform/graphics/Gradient.h" | 34 #include "platform/graphics/Gradient.h" |
35 #include "platform/graphics/ImageBuffer.h" | 35 #include "platform/graphics/ImageBuffer.h" |
36 #include "platform/weborigin/KURL.h" | 36 #include "platform/weborigin/KURL.h" |
| 37 #include "skia/ext/platform_device.h" |
37 #include "third_party/skia/include/core/SkAnnotation.h" | 38 #include "third_party/skia/include/core/SkAnnotation.h" |
38 #include "third_party/skia/include/core/SkColorFilter.h" | 39 #include "third_party/skia/include/core/SkColorFilter.h" |
39 #include "third_party/skia/include/core/SkData.h" | 40 #include "third_party/skia/include/core/SkData.h" |
40 #include "third_party/skia/include/core/SkPicture.h" | 41 #include "third_party/skia/include/core/SkPicture.h" |
41 #include "third_party/skia/include/core/SkPictureRecorder.h" | 42 #include "third_party/skia/include/core/SkPictureRecorder.h" |
42 #include "third_party/skia/include/core/SkRRect.h" | 43 #include "third_party/skia/include/core/SkRRect.h" |
43 #include "third_party/skia/include/core/SkRefCnt.h" | 44 #include "third_party/skia/include/core/SkRefCnt.h" |
44 #include "third_party/skia/include/effects/SkLumaColorFilter.h" | 45 #include "third_party/skia/include/effects/SkLumaColorFilter.h" |
45 #include "third_party/skia/include/effects/SkPictureImageFilter.h" | 46 #include "third_party/skia/include/effects/SkPictureImageFilter.h" |
46 #include "third_party/skia/include/utils/SkNullCanvas.h" | 47 #include "third_party/skia/include/utils/SkNullCanvas.h" |
(...skipping 21 matching lines...) Expand all Loading... |
68 explicit RecordingState(SkCanvas* canvas, const SkMatrix& matrix) | 69 explicit RecordingState(SkCanvas* canvas, const SkMatrix& matrix) |
69 : m_savedCanvas(canvas) | 70 : m_savedCanvas(canvas) |
70 , m_savedMatrix(matrix) | 71 , m_savedMatrix(matrix) |
71 { } | 72 { } |
72 | 73 |
73 SkPictureRecorder m_recorder; | 74 SkPictureRecorder m_recorder; |
74 SkCanvas* m_savedCanvas; | 75 SkCanvas* m_savedCanvas; |
75 const SkMatrix m_savedMatrix; | 76 const SkMatrix m_savedMatrix; |
76 }; | 77 }; |
77 | 78 |
78 GraphicsContext::GraphicsContext(DisplayItemList* displayItemList, DisabledMode
disableContextOrPainting) | 79 GraphicsContext::GraphicsContext(DisplayItemList* displayItemList, DisabledMode
disableContextOrPainting, SkMetaData* metaData) |
79 : GraphicsContext(nullptr, displayItemList, disableContextOrPainting) | 80 : GraphicsContext(nullptr, displayItemList, disableContextOrPainting, metaDa
ta) |
80 { | 81 { |
81 // TODO(chrishtr): switch the type of the parameter to DisplayItemList&. | 82 // TODO(chrishtr): switch the type of the parameter to DisplayItemList&. |
82 ASSERT(displayItemList); | 83 ASSERT(displayItemList); |
83 } | 84 } |
84 | 85 |
85 PassOwnPtr<GraphicsContext> GraphicsContext::deprecatedCreateWithCanvas(SkCanvas
* canvas, DisabledMode disableContextOrPainting) | 86 PassOwnPtr<GraphicsContext> GraphicsContext::deprecatedCreateWithCanvas(SkCanvas
* canvas, DisabledMode disableContextOrPainting, SkMetaData* metaData) |
86 { | 87 { |
87 return adoptPtr(new GraphicsContext(canvas, nullptr, disableContextOrPaintin
g)); | 88 return adoptPtr(new GraphicsContext(canvas, nullptr, disableContextOrPaintin
g, metaData)); |
88 } | 89 } |
89 | 90 |
90 GraphicsContext::GraphicsContext(SkCanvas* canvas, DisplayItemList* displayItemL
ist, DisabledMode disableContextOrPainting) | 91 GraphicsContext::GraphicsContext(SkCanvas* canvas, DisplayItemList* displayItemL
ist, DisabledMode disableContextOrPainting, SkMetaData* metaData) |
91 : m_canvas(canvas) | 92 : m_canvas(canvas) |
92 , m_originalCanvas(canvas) | 93 , m_originalCanvas(canvas) |
93 , m_displayItemList(displayItemList) | 94 , m_displayItemList(displayItemList) |
94 , m_paintStateStack() | 95 , m_paintStateStack() |
95 , m_paintStateIndex(0) | 96 , m_paintStateIndex(0) |
96 #if ENABLE(ASSERT) | 97 #if ENABLE(ASSERT) |
97 , m_layerCount(0) | 98 , m_layerCount(0) |
98 , m_disableDestructionChecks(false) | 99 , m_disableDestructionChecks(false) |
99 , m_inDrawingRecorder(false) | 100 , m_inDrawingRecorder(false) |
100 #endif | 101 #endif |
101 , m_disabledState(disableContextOrPainting) | 102 , m_disabledState(disableContextOrPainting) |
102 , m_deviceScaleFactor(1.0f) | 103 , m_deviceScaleFactor(1.0f) |
103 , m_accelerated(false) | 104 , m_accelerated(false) |
104 , m_printing(false) | 105 , m_printing(false) |
| 106 , m_hasMetaData(!!metaData) |
105 { | 107 { |
| 108 if (metaData) |
| 109 m_metaData = *metaData; |
| 110 |
106 // FIXME: Do some tests to determine how many states are typically used, and
allocate | 111 // FIXME: Do some tests to determine how many states are typically used, and
allocate |
107 // several here. | 112 // several here. |
108 m_paintStateStack.append(GraphicsContextState::create()); | 113 m_paintStateStack.append(GraphicsContextState::create()); |
109 m_paintState = m_paintStateStack.last().get(); | 114 m_paintState = m_paintStateStack.last().get(); |
110 | 115 |
111 if (contextDisabled()) { | 116 if (contextDisabled()) { |
112 DEFINE_STATIC_LOCAL(RefPtr<SkCanvas>, nullCanvas, (adoptRef(SkCreateNull
Canvas()))); | 117 DEFINE_STATIC_LOCAL(RefPtr<SkCanvas>, nullCanvas, (adoptRef(SkCreateNull
Canvas()))); |
113 m_canvas = nullCanvas.get(); | 118 m_canvas = nullCanvas.get(); |
114 } | 119 } |
115 } | 120 } |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 ASSERT(m_layerCount-- > 0); | 400 ASSERT(m_layerCount-- > 0); |
396 } | 401 } |
397 | 402 |
398 void GraphicsContext::beginRecording(const FloatRect& bounds) | 403 void GraphicsContext::beginRecording(const FloatRect& bounds) |
399 { | 404 { |
400 if (contextDisabled()) | 405 if (contextDisabled()) |
401 return; | 406 return; |
402 | 407 |
403 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) { | 408 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) { |
404 m_canvas = m_pictureRecorder.beginRecording(bounds, 0); | 409 m_canvas = m_pictureRecorder.beginRecording(bounds, 0); |
| 410 if (m_hasMetaData) |
| 411 skia::getMetaData(*m_canvas) = m_metaData; |
405 return; | 412 return; |
406 } | 413 } |
407 | 414 |
408 m_recordingStateStack.append( | 415 m_recordingStateStack.append( |
409 RecordingState::Create(m_canvas, getTotalMatrix())); | 416 RecordingState::Create(m_canvas, getTotalMatrix())); |
| 417 |
410 m_canvas = m_recordingStateStack.last()->recorder().beginRecording(bounds, 0
); | 418 m_canvas = m_recordingStateStack.last()->recorder().beginRecording(bounds, 0
); |
| 419 if (m_hasMetaData) |
| 420 skia::getMetaData(*m_canvas) = m_metaData; |
411 } | 421 } |
412 | 422 |
413 PassRefPtr<const SkPicture> GraphicsContext::endRecording() | 423 PassRefPtr<const SkPicture> GraphicsContext::endRecording() |
414 { | 424 { |
415 if (contextDisabled()) | 425 if (contextDisabled()) |
416 return nullptr; | 426 return nullptr; |
417 | 427 |
418 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) { | 428 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) { |
419 RefPtr<const SkPicture> picture = adoptRef(m_pictureRecorder.endRecordin
gAsPicture()); | 429 RefPtr<const SkPicture> picture = adoptRef(m_pictureRecorder.endRecordin
gAsPicture()); |
420 m_canvas = m_originalCanvas; | 430 m_canvas = m_originalCanvas; |
(...skipping 1139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1560 static const SkPMColor colors[] = { | 1570 static const SkPMColor colors[] = { |
1561 SkPreMultiplyARGB(0x60, 0xFF, 0x00, 0x00), // More transparent red | 1571 SkPreMultiplyARGB(0x60, 0xFF, 0x00, 0x00), // More transparent red |
1562 SkPreMultiplyARGB(0x60, 0xC0, 0xC0, 0xC0) // More transparent gray | 1572 SkPreMultiplyARGB(0x60, 0xC0, 0xC0, 0xC0) // More transparent gray |
1563 }; | 1573 }; |
1564 | 1574 |
1565 return colors[index]; | 1575 return colors[index]; |
1566 } | 1576 } |
1567 #endif | 1577 #endif |
1568 | 1578 |
1569 } // namespace blink | 1579 } // namespace blink |
OLD | NEW |