OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (C) 2012, Google Inc. All rights reserved. |
| 3 * |
| 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions |
| 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the |
| 11 * documentation and/or other materials provided with the distribution. |
| 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y |
| 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N |
| 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 */ |
| 24 |
| 25 #include "config.h" |
| 26 |
| 27 #include "ThrottledTextureUploader.h" |
| 28 |
| 29 #include "Extensions3DChromium.h" |
| 30 #include <public/WebGraphicsContext3D.h> |
| 31 |
| 32 namespace { |
| 33 |
| 34 // Number of pending texture update queries to allow. |
| 35 static const size_t maxPendingQueries = 2; |
| 36 |
| 37 } // anonymous namespace |
| 38 |
| 39 namespace WebCore { |
| 40 |
| 41 ThrottledTextureUploader::Query::Query(WebKit::WebGraphicsContext3D* context) |
| 42 : m_context(context) |
| 43 , m_queryId(0) |
| 44 { |
| 45 m_queryId = m_context->createQueryEXT(); |
| 46 } |
| 47 |
| 48 ThrottledTextureUploader::Query::~Query() |
| 49 { |
| 50 m_context->deleteQueryEXT(m_queryId); |
| 51 } |
| 52 |
| 53 void ThrottledTextureUploader::Query::begin() |
| 54 { |
| 55 m_context->beginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, m_queryId); |
| 56 } |
| 57 |
| 58 void ThrottledTextureUploader::Query::end() |
| 59 { |
| 60 m_context->endQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); |
| 61 } |
| 62 |
| 63 bool ThrottledTextureUploader::Query::isPending() |
| 64 { |
| 65 unsigned available = 1; |
| 66 m_context->getQueryObjectuivEXT(m_queryId, GL_QUERY_RESULT_AVAILABLE_EXT, &a
vailable); |
| 67 return !available; |
| 68 } |
| 69 |
| 70 void ThrottledTextureUploader::Query::wait() |
| 71 { |
| 72 unsigned result; |
| 73 m_context->getQueryObjectuivEXT(m_queryId, GL_QUERY_RESULT_EXT, &result); |
| 74 } |
| 75 |
| 76 ThrottledTextureUploader::ThrottledTextureUploader(WebKit::WebGraphicsContext3D*
context) |
| 77 : m_context(context) |
| 78 , m_maxPendingQueries(maxPendingQueries) |
| 79 { |
| 80 } |
| 81 |
| 82 ThrottledTextureUploader::ThrottledTextureUploader(WebKit::WebGraphicsContext3D*
context, size_t pendingUploadLimit) |
| 83 : m_context(context) |
| 84 , m_maxPendingQueries(pendingUploadLimit) |
| 85 { |
| 86 ASSERT(m_context); |
| 87 } |
| 88 |
| 89 ThrottledTextureUploader::~ThrottledTextureUploader() |
| 90 { |
| 91 } |
| 92 |
| 93 bool ThrottledTextureUploader::isBusy() |
| 94 { |
| 95 processQueries(); |
| 96 |
| 97 if (!m_availableQueries.isEmpty()) |
| 98 return false; |
| 99 |
| 100 if (m_pendingQueries.size() == m_maxPendingQueries) |
| 101 return true; |
| 102 |
| 103 m_availableQueries.append(Query::create(m_context)); |
| 104 return false; |
| 105 } |
| 106 |
| 107 void ThrottledTextureUploader::beginUploads() |
| 108 { |
| 109 // Wait for query to become available. |
| 110 while (isBusy()) |
| 111 m_pendingQueries.first()->wait(); |
| 112 |
| 113 ASSERT(!m_availableQueries.isEmpty()); |
| 114 m_availableQueries.first()->begin(); |
| 115 } |
| 116 |
| 117 void ThrottledTextureUploader::endUploads() |
| 118 { |
| 119 m_availableQueries.first()->end(); |
| 120 m_pendingQueries.append(m_availableQueries.takeFirst()); |
| 121 } |
| 122 |
| 123 void ThrottledTextureUploader::uploadTexture(CCGraphicsContext* context, LayerTe
xtureUpdater::Texture* texture, TextureAllocator* allocator, const IntRect sourc
eRect, const IntRect destRect) |
| 124 { |
| 125 texture->updateRect(context, allocator, sourceRect, destRect); |
| 126 } |
| 127 |
| 128 void ThrottledTextureUploader::processQueries() |
| 129 { |
| 130 while (!m_pendingQueries.isEmpty()) { |
| 131 if (m_pendingQueries.first()->isPending()) |
| 132 break; |
| 133 |
| 134 m_availableQueries.append(m_pendingQueries.takeFirst()); |
| 135 } |
| 136 } |
| 137 |
| 138 } |
OLD | NEW |