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

Side by Side Diff: third_party/WebKit/Source/core/css/MediaValuesCached.cpp

Issue 1679703002: Revert of Create MediaValuesCached and TokenPreloadScanner on the parser thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@TRV_MediaValuesCached
Patch Set: Created 4 years, 10 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "core/css/MediaValuesCached.h" 5 #include "core/css/MediaValuesCached.h"
6 6
7 #include "core/css/CSSPrimitiveValue.h" 7 #include "core/css/CSSPrimitiveValue.h"
8 #include "core/dom/Document.h" 8 #include "core/dom/Document.h"
9 #include "core/frame/LocalFrame.h" 9 #include "core/frame/LocalFrame.h"
10 #include "core/layout/LayoutObject.h" 10 #include "core/layout/LayoutObject.h"
11 11
12 namespace blink { 12 namespace blink {
13 13
14 MediaValuesCached::MediaValuesCachedData::MediaValuesCachedData(Document& docume nt)
15 : MediaValuesCached::MediaValuesCachedData()
16 {
17 ASSERT(isMainThread());
18 LocalFrame* frame = MediaValues::frameFrom(document);
19 // TODO(hiroshige): Clean up |frame->view()| conditions.
20 ASSERT(!frame || frame->view());
21 if (frame && frame->view()) {
22 ASSERT(frame->document() && frame->document()->layoutView());
23
24 // In case that frame is missing (e.g. for images that their document do es not have a frame)
25 // We simply leave the MediaValues object with the default MediaValuesCa chedData values.
26 viewportWidth = MediaValues::calculateViewportWidth(frame);
27 viewportHeight = MediaValues::calculateViewportHeight(frame);
28 deviceWidth = MediaValues::calculateDeviceWidth(frame);
29 deviceHeight = MediaValues::calculateDeviceHeight(frame);
30 devicePixelRatio = MediaValues::calculateDevicePixelRatio(frame);
31 colorBitsPerComponent = MediaValues::calculateColorBitsPerComponent(fram e);
32 monochromeBitsPerComponent = MediaValues::calculateMonochromeBitsPerComp onent(frame);
33 primaryPointerType = MediaValues::calculatePrimaryPointerType(frame);
34 availablePointerTypes = MediaValues::calculateAvailablePointerTypes(fram e);
35 primaryHoverType = MediaValues::calculatePrimaryHoverType(frame);
36 availableHoverTypes = MediaValues::calculateAvailableHoverTypes(frame);
37 defaultFontSize = MediaValues::calculateDefaultFontSize(frame);
38 threeDEnabled = MediaValues::calculateThreeDEnabled(frame);
39 strictMode = MediaValues::calculateStrictMode(frame);
40 displayMode = MediaValues::calculateDisplayMode(frame);
41 mediaType = MediaValues::calculateMediaType(frame);
42 }
43 }
44
45 PassRefPtrWillBeRawPtr<MediaValuesCached> MediaValuesCached::create() 14 PassRefPtrWillBeRawPtr<MediaValuesCached> MediaValuesCached::create()
46 { 15 {
47 return adoptRefWillBeNoop(new MediaValuesCached()); 16 return adoptRefWillBeNoop(new MediaValuesCached());
48 } 17 }
49 18
50 PassRefPtrWillBeRawPtr<MediaValuesCached> MediaValuesCached::create(const MediaV aluesCachedData& data) 19 PassRefPtrWillBeRawPtr<MediaValuesCached> MediaValuesCached::create(MediaValuesC achedData& data)
51 { 20 {
52 return adoptRefWillBeNoop(new MediaValuesCached(data)); 21 return adoptRefWillBeNoop(new MediaValuesCached(data));
53 } 22 }
54 23
24 PassRefPtrWillBeRawPtr<MediaValuesCached> MediaValuesCached::create(Document& do cument)
25 {
26 return MediaValuesCached::create(frameFrom(document));
27 }
28
29 PassRefPtrWillBeRawPtr<MediaValuesCached> MediaValuesCached::create(LocalFrame* frame)
30 {
31 // FIXME - Added an assert here so we can better understand when a frame is present without its view().
32 ASSERT(!frame || frame->view());
33 if (!frame || !frame->view())
34 return adoptRefWillBeNoop(new MediaValuesCached());
35 ASSERT(frame->document() && frame->document()->layoutView());
36 return adoptRefWillBeNoop(new MediaValuesCached(frame));
37 }
38
55 MediaValuesCached::MediaValuesCached() 39 MediaValuesCached::MediaValuesCached()
56 { 40 {
57 } 41 }
58 42
43 MediaValuesCached::MediaValuesCached(LocalFrame* frame)
44 {
45 ASSERT(isMainThread());
46 ASSERT(frame);
47 // In case that frame is missing (e.g. for images that their document does n ot have a frame)
48 // We simply leave the MediaValues object with the default MediaValuesCached Data values.
49 m_data.viewportWidth = calculateViewportWidth(frame);
50 m_data.viewportHeight = calculateViewportHeight(frame);
51 m_data.deviceWidth = calculateDeviceWidth(frame);
52 m_data.deviceHeight = calculateDeviceHeight(frame);
53 m_data.devicePixelRatio = calculateDevicePixelRatio(frame);
54 m_data.colorBitsPerComponent = calculateColorBitsPerComponent(frame);
55 m_data.monochromeBitsPerComponent = calculateMonochromeBitsPerComponent(fram e);
56 m_data.primaryPointerType = calculatePrimaryPointerType(frame);
57 m_data.availablePointerTypes = calculateAvailablePointerTypes(frame);
58 m_data.primaryHoverType = calculatePrimaryHoverType(frame);
59 m_data.availableHoverTypes = calculateAvailableHoverTypes(frame);
60 m_data.defaultFontSize = calculateDefaultFontSize(frame);
61 m_data.threeDEnabled = calculateThreeDEnabled(frame);
62 m_data.strictMode = calculateStrictMode(frame);
63 m_data.displayMode = calculateDisplayMode(frame);
64 const String mediaType = calculateMediaType(frame);
65 if (!mediaType.isEmpty())
66 m_data.mediaType = mediaType.isolatedCopy();
67 }
68
59 MediaValuesCached::MediaValuesCached(const MediaValuesCachedData& data) 69 MediaValuesCached::MediaValuesCached(const MediaValuesCachedData& data)
60 : m_data(data) 70 : m_data(data)
61 { 71 {
62 } 72 }
63 73
64 PassRefPtrWillBeRawPtr<MediaValues> MediaValuesCached::copy() const 74 PassRefPtrWillBeRawPtr<MediaValues> MediaValuesCached::copy() const
65 { 75 {
66 return adoptRefWillBeNoop(new MediaValuesCached(m_data)); 76 return adoptRefWillBeNoop(new MediaValuesCached(m_data));
67 } 77 }
68 78
69 bool MediaValuesCached::computeLength(double value, CSSPrimitiveValue::UnitType type, int& result) const 79 bool MediaValuesCached::computeLength(double value, CSSPrimitiveValue::UnitType type, int& result) const
70 { 80 {
71 return MediaValues::computeLength(value, type, m_data.defaultFontSize, m_dat a.viewportWidth, m_data.viewportHeight, result); 81 return MediaValues::computeLength(value, type, m_data.defaultFontSize, m_dat a.viewportWidth, m_data.viewportHeight, result);
72 } 82 }
73 83
74 bool MediaValuesCached::computeLength(double value, CSSPrimitiveValue::UnitType type, double& result) const 84 bool MediaValuesCached::computeLength(double value, CSSPrimitiveValue::UnitType type, double& result) const
75 { 85 {
76 return MediaValues::computeLength(value, type, m_data.defaultFontSize, m_dat a.viewportWidth, m_data.viewportHeight, result); 86 return MediaValues::computeLength(value, type, m_data.defaultFontSize, m_dat a.viewportWidth, m_data.viewportHeight, result);
77 } 87 }
78 88
89 bool MediaValuesCached::isSafeToSendToAnotherThread() const
90 {
91 #if ENABLE(OILPAN)
92 // Oilpan objects are safe to send to another thread as long as the thread
93 // does not outlive the thread used for creation. MediaValues are
94 // allocated on the main thread and may be passed to the parser thread,
95 // so this should be safe.
96 return true;
97 #else
98 return hasOneRef();
99 #endif
100 }
101
79 double MediaValuesCached::viewportWidth() const 102 double MediaValuesCached::viewportWidth() const
80 { 103 {
81 return m_data.viewportWidth; 104 return m_data.viewportWidth;
82 } 105 }
83 106
84 double MediaValuesCached::viewportHeight() const 107 double MediaValuesCached::viewportHeight() const
85 { 108 {
86 return m_data.viewportHeight; 109 return m_data.viewportHeight;
87 } 110 }
88 111
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 { 188 {
166 m_data.viewportWidth = width; 189 m_data.viewportWidth = width;
167 } 190 }
168 191
169 void MediaValuesCached::setViewportHeight(double height) 192 void MediaValuesCached::setViewportHeight(double height)
170 { 193 {
171 m_data.viewportHeight = height; 194 m_data.viewportHeight = height;
172 } 195 }
173 196
174 } // namespace blink 197 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698