Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "config.h" | 5 #include "config.h" |
| 6 | |
| 7 #include "ThrottledTextureUploader.h" | 6 #include "ThrottledTextureUploader.h" |
| 8 | 7 |
| 9 #include "Extensions3DChromium.h" | 8 #include "Extensions3DChromium.h" |
| 9 #include <algorithm> | |
| 10 #include <public/WebGraphicsContext3D.h> | 10 #include <public/WebGraphicsContext3D.h> |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 // Number of pending texture update queries to allow. | 14 // Number of pending texture update queries to allow. |
| 15 static const size_t maxPendingQueries = 2; | 15 static const size_t maxPendingQueries = 2; |
| 16 | 16 |
| 17 // How many previous uploads to use when predicting future throughput. | |
| 18 static const size_t uploadHistorySize = 10; | |
|
nduca
2012/09/14 05:50:26
This is in number of queries, right? I might make
brianderson
2012/09/14 19:12:00
I intentionally kept it low so that we would quick
| |
| 19 | |
| 20 // Default number of pixels per second. | |
|
nduca
2012/09/14 05:50:26
This seems a bit low, no? If you have 1.5ms per te
brianderson
2012/09/14 19:12:00
It is low. What I've calculated below is actually
| |
| 21 static double estimatedPixelsPerSecondDefault = 256 * 256 * 48; | |
| 22 | |
| 17 } // anonymous namespace | 23 } // anonymous namespace |
| 18 | 24 |
| 19 namespace WebCore { | 25 namespace WebCore { |
| 20 | 26 |
| 21 ThrottledTextureUploader::Query::Query(WebKit::WebGraphicsContext3D* context) | 27 ThrottledTextureUploader::Query::Query(WebKit::WebGraphicsContext3D* context) |
| 22 : m_context(context) | 28 : m_context(context) |
| 23 , m_queryId(0) | 29 , m_queryId(0) |
| 30 , m_pixelsUploaded(0) | |
| 24 { | 31 { |
| 25 m_queryId = m_context->createQueryEXT(); | 32 m_queryId = m_context->createQueryEXT(); |
| 26 } | 33 } |
| 27 | 34 |
| 28 ThrottledTextureUploader::Query::~Query() | 35 ThrottledTextureUploader::Query::~Query() |
| 29 { | 36 { |
| 30 m_context->deleteQueryEXT(m_queryId); | 37 m_context->deleteQueryEXT(m_queryId); |
| 31 } | 38 } |
| 32 | 39 |
| 33 void ThrottledTextureUploader::Query::begin() | 40 void ThrottledTextureUploader::Query::begin() |
| 34 { | 41 { |
| 35 m_context->beginQueryEXT(Extensions3DChromium::COMMANDS_ISSUED_CHROMIUM, m_q ueryId); | 42 m_context->beginQueryEXT(Extensions3DChromium::COMMANDS_ISSUED_CHROMIUM, m_q ueryId); |
| 36 } | 43 } |
| 37 | 44 |
| 38 void ThrottledTextureUploader::Query::end() | 45 void ThrottledTextureUploader::Query::end(double pixelsUploaded) |
| 39 { | 46 { |
| 40 m_context->endQueryEXT(Extensions3DChromium::COMMANDS_ISSUED_CHROMIUM); | 47 m_context->endQueryEXT(Extensions3DChromium::COMMANDS_ISSUED_CHROMIUM); |
| 48 m_pixelsUploaded = pixelsUploaded; | |
| 41 } | 49 } |
| 42 | 50 |
| 43 bool ThrottledTextureUploader::Query::isPending() | 51 bool ThrottledTextureUploader::Query::isPending() |
| 44 { | 52 { |
| 45 unsigned available = 1; | 53 unsigned available = 1; |
| 46 m_context->getQueryObjectuivEXT(m_queryId, Extensions3DChromium::QUERY_RESUL T_AVAILABLE_EXT, &available); | 54 m_context->getQueryObjectuivEXT(m_queryId, Extensions3DChromium::QUERY_RESUL T_AVAILABLE_EXT, &available); |
| 47 return !available; | 55 return !available; |
| 48 } | 56 } |
| 49 | 57 |
| 50 void ThrottledTextureUploader::Query::wait() | 58 void ThrottledTextureUploader::Query::wait() |
| 51 { | 59 { |
| 60 value(); | |
| 61 return; | |
| 62 } | |
| 63 | |
| 64 unsigned ThrottledTextureUploader::Query::value() | |
| 65 { | |
|
nduca
2012/09/14 05:50:26
can you reverse this so that you have m_hasValue,
brianderson
2012/09/14 19:12:00
Ok. Avoiding the call to getQueryObjectuivEXT mult
| |
| 52 unsigned result; | 66 unsigned result; |
| 53 m_context->getQueryObjectuivEXT(m_queryId, Extensions3DChromium::QUERY_RESUL T_EXT, &result); | 67 m_context->getQueryObjectuivEXT(m_queryId, Extensions3DChromium::QUERY_RESUL T_EXT, &result); |
| 68 return result; | |
| 69 } | |
| 70 | |
| 71 double ThrottledTextureUploader::Query::pixelsUploaded() | |
| 72 { | |
| 73 return m_pixelsUploaded; | |
| 54 } | 74 } |
| 55 | 75 |
| 56 ThrottledTextureUploader::ThrottledTextureUploader(WebKit::WebGraphicsContext3D* context) | 76 ThrottledTextureUploader::ThrottledTextureUploader(WebKit::WebGraphicsContext3D* context) |
| 57 : m_context(context) | 77 : m_context(context) |
| 58 , m_maxPendingQueries(maxPendingQueries) | 78 , m_maxPendingQueries(maxPendingQueries) |
| 79 , m_pixelsUploaded(0) | |
| 59 { | 80 { |
| 60 } | 81 } |
| 61 | 82 |
| 62 ThrottledTextureUploader::ThrottledTextureUploader(WebKit::WebGraphicsContext3D* context, size_t pendingUploadLimit) | 83 ThrottledTextureUploader::ThrottledTextureUploader(WebKit::WebGraphicsContext3D* context, size_t pendingUploadLimit) |
| 63 : m_context(context) | 84 : m_context(context) |
| 64 , m_maxPendingQueries(pendingUploadLimit) | 85 , m_maxPendingQueries(pendingUploadLimit) |
| 86 , m_pixelsUploaded(0) | |
| 65 { | 87 { |
| 66 ASSERT(m_context); | 88 ASSERT(m_context); |
| 67 } | 89 } |
| 68 | 90 |
| 69 ThrottledTextureUploader::~ThrottledTextureUploader() | 91 ThrottledTextureUploader::~ThrottledTextureUploader() |
| 70 { | 92 { |
| 71 } | 93 } |
| 72 | |
| 73 bool ThrottledTextureUploader::isBusy() | 94 bool ThrottledTextureUploader::isBusy() |
| 74 { | 95 { |
| 75 processQueries(); | 96 processQueries(); |
| 76 | 97 |
| 77 if (!m_availableQueries.isEmpty()) | 98 if (!m_availableQueries.isEmpty()) |
| 78 return false; | 99 return false; |
| 79 | 100 |
| 80 if (m_pendingQueries.size() == m_maxPendingQueries) | 101 if (m_pendingQueries.size() == m_maxPendingQueries) |
| 81 return true; | 102 return true; |
| 82 | 103 |
| 83 m_availableQueries.append(Query::create(m_context)); | 104 m_availableQueries.append(Query::create(m_context)); |
| 84 return false; | 105 return false; |
| 85 } | 106 } |
| 86 | 107 |
| 108 double ThrottledTextureUploader::estimatedPixelsPerSecond() | |
| 109 { | |
| 110 processQueries(); | |
| 111 | |
| 112 if (m_pixelsPerSecondHistory.empty()) | |
|
nduca
2012/09/14 05:50:26
Instead of this, seed the queue with max entries w
brianderson
2012/09/14 19:12:00
Sounds good.
| |
| 113 return estimatedPixelsPerSecondDefault; | |
| 114 | |
| 115 // Sort the history and use the median as our estimate. | |
| 116 std::deque<double> sortedHistory(m_pixelsPerSecondHistory); | |
|
nduca
2012/09/14 05:50:26
why deque and not a vector?
brianderson
2012/09/14 19:12:00
My thinking was that the deque copy constructor wo
| |
| 117 std::sort(sortedHistory.begin(), sortedHistory.end()); | |
| 118 return sortedHistory[sortedHistory.size() / 2]; | |
| 119 } | |
| 120 | |
| 87 void ThrottledTextureUploader::beginUploads() | 121 void ThrottledTextureUploader::beginUploads() |
| 88 { | 122 { |
| 123 m_pixelsUploaded = 0; | |
| 124 | |
| 89 // Wait for query to become available. | 125 // Wait for query to become available. |
| 90 while (isBusy()) | 126 while (isBusy()) |
| 91 m_pendingQueries.first()->wait(); | 127 m_pendingQueries.first()->wait(); |
| 92 | 128 |
| 93 ASSERT(!m_availableQueries.isEmpty()); | 129 ASSERT(!m_availableQueries.isEmpty()); |
| 94 m_availableQueries.first()->begin(); | 130 m_availableQueries.first()->begin(); |
| 95 } | 131 } |
| 96 | 132 |
| 97 void ThrottledTextureUploader::endUploads() | 133 void ThrottledTextureUploader::endUploads() |
| 98 { | 134 { |
| 99 m_availableQueries.first()->end(); | 135 m_availableQueries.first()->end(m_pixelsUploaded); |
| 100 m_pendingQueries.append(m_availableQueries.takeFirst()); | 136 m_pendingQueries.append(m_availableQueries.takeFirst()); |
| 101 } | 137 } |
| 102 | 138 |
| 103 void ThrottledTextureUploader::uploadTexture(CCResourceProvider* resourceProvide r, Parameters upload) | 139 void ThrottledTextureUploader::uploadTexture(CCResourceProvider* resourceProvide r, Parameters upload) |
| 104 { | 140 { |
| 141 m_pixelsUploaded += upload.sourceRect.width() * upload.sourceRect.width(); | |
| 105 upload.texture->updateRect(resourceProvider, upload.sourceRect, upload.destO ffset); | 142 upload.texture->updateRect(resourceProvider, upload.sourceRect, upload.destO ffset); |
| 106 } | 143 } |
| 107 | 144 |
| 108 void ThrottledTextureUploader::processQueries() | 145 void ThrottledTextureUploader::processQueries() |
| 109 { | 146 { |
| 110 while (!m_pendingQueries.isEmpty()) { | 147 while (!m_pendingQueries.isEmpty()) { |
| 111 if (m_pendingQueries.first()->isPending()) | 148 if (m_pendingQueries.first()->isPending()) |
| 112 break; | 149 break; |
| 113 | 150 |
| 151 unsigned usElapsed = m_pendingQueries.first()->value(); | |
| 152 double pixelsPerSecond = m_pendingQueries.first()->pixelsUploaded() / (u sElapsed * 1e-6); | |
| 153 | |
| 154 // Remove the oldest values from our history and insert the new one | |
| 155 if (m_pixelsPerSecondHistory.size() >= uploadHistorySize) | |
| 156 m_pixelsPerSecondHistory.pop_back(); | |
| 157 m_pixelsPerSecondHistory.push_front(pixelsPerSecond); | |
| 158 | |
| 114 m_availableQueries.append(m_pendingQueries.takeFirst()); | 159 m_availableQueries.append(m_pendingQueries.takeFirst()); |
| 115 } | 160 } |
| 116 } | 161 } |
| 117 | 162 |
| 118 } | 163 } |
| OLD | NEW |