void
TextureClientPool::ShrinkToMaximumSize()
{
  uint32_t totalClientsOutstanding = mTextureClients.size() + mOutstandingClients;
  TCP_LOG("TexturePool %p shrinking to max size %u; total outstanding %u\n",
      this, mMaxTextureClients, totalClientsOutstanding);

  // We're over our desired maximum size, immediately shrink down to the
  // maximum, or zero if we have too many outstanding texture clients.
  // We cull from the deferred TextureClients first, as we can't reuse those
  // until they get returned.
  while (totalClientsOutstanding > mMaxTextureClients) {
    if (mTextureClientsDeferred.size()) {
      MOZ_ASSERT(mOutstandingClients > 0);
      mOutstandingClients--;
      TCP_LOG("TexturePool %p dropped deferred client %p; %u remaining\n",
          this, mTextureClientsDeferred.top().get(),
          mTextureClientsDeferred.size() - 1);
      mTextureClientsDeferred.pop();
    } else {
      if (!mTextureClients.size()) {
        // Getting here means we're over our desired number of TextureClients
        // with none in the pool. This can happen for pathological cases, or
        // it could mean that mMaxTextureClients needs adjusting for whatever
        // device we're running on.
        TCP_LOG("TexturePool %p encountering pathological case!\n", this);
        break;
      }
      TCP_LOG("TexturePool %p dropped non-deferred client %p; %u remaining\n",
          this, mTextureClients.top().get(), mTextureClients.size() - 1);
      mTextureClients.pop();
    }
    totalClientsOutstanding--;
  }
}
void
TextureClientPool::ReturnTextureClient(TextureClient *aClient)
{
  if (!aClient) {
    return;
  }
#ifdef GFX_DEBUG_TRACK_CLIENTS_IN_POOL
  DebugOnly<bool> ok = TestClientPool("return", aClient, this);
  MOZ_ASSERT(ok);
#endif
  // Add the client to the pool:
  MOZ_ASSERT(mOutstandingClients > mTextureClientsDeferred.size());
  mOutstandingClients--;
  mTextureClients.push(aClient);
  TCP_LOG("TexturePool %p had client %p returned; size %u outstanding %u\n",
      this, aClient, mTextureClients.size(), mOutstandingClients);

  // Shrink down if we're beyond our maximum size
  ShrinkToMaximumSize();

  // Kick off the pool shrinking timer if there are still more unused texture
  // clients than our desired minimum cache size.
  if (mTextureClients.size() > sMinCacheSize) {
    TCP_LOG("TexturePool %p scheduling a shrink-to-min-size\n", this);
    mTimer->InitWithFuncCallback(ShrinkCallback, this, mShrinkTimeoutMsec,
                                 nsITimer::TYPE_ONE_SHOT);
  }
}
void
TextureClientPool::ShrinkToMinimumSize()
{
  TCP_LOG("TexturePool %p shrinking to minimum size %u\n", this, sMinCacheSize);
  while (mTextureClients.size() > sMinCacheSize) {
    TCP_LOG("TexturePool %p popped %p; shrunk to %u\n",
        this, mTextureClients.top().get(), mTextureClients.size() - 1);
    mTextureClients.pop();
  }
}
TextureClientPool::TextureClientPool(LayersBackend aLayersBackend,
                                     gfx::SurfaceFormat aFormat,
                                     gfx::IntSize aSize,
                                     TextureFlags aFlags,
                                     uint32_t aShrinkTimeoutMsec,
                                     uint32_t aClearTimeoutMsec,
                                     uint32_t aInitialPoolSize,
                                     uint32_t aPoolUnusedSize,
                                     TextureForwarder* aAllocator)
  : mBackend(aLayersBackend)
  , mFormat(aFormat)
  , mSize(aSize)
  , mFlags(aFlags)
  , mShrinkTimeoutMsec(aShrinkTimeoutMsec)
  , mClearTimeoutMsec(aClearTimeoutMsec)
  , mInitialPoolSize(aInitialPoolSize)
  , mPoolUnusedSize(aPoolUnusedSize)
  , mOutstandingClients(0)
  , mSurfaceAllocator(aAllocator)
  , mDestroyed(false)
{
  TCP_LOG("TexturePool %p created with maximum unused texture clients %u\n",
      this, mInitialPoolSize);
  mShrinkTimer = do_CreateInstance("@mozilla.org/timer;1");
  mClearTimer = do_CreateInstance("@mozilla.org/timer;1");
  if (aFormat == gfx::SurfaceFormat::UNKNOWN) {
    gfxWarning() << "Creating texture pool for SurfaceFormat::UNKNOWN format";
  }
}
void
TextureClientPool::AllocateTextureClient()
{
  TCP_LOG("TexturePool %p allocating TextureClient, outstanding %u\n",
      this, mOutstandingClients);

  RefPtr<TextureClient> newClient;
  if (gfxPrefs::ForceShmemTiles()) {
    // gfx::BackendType::NONE means use the content backend
    newClient =
      TextureClient::CreateForRawBufferAccess(mSurfaceAllocator,
                                              mFormat, mSize,
                                              gfx::BackendType::NONE,
                                              mBackend,
                                              mFlags, ALLOC_DEFAULT);
  } else {
    newClient =
      TextureClient::CreateForDrawing(mSurfaceAllocator,
                                      mFormat, mSize,
                                      mBackend,
                                      BackendSelector::Content,
                                      mFlags);
  }

  if (newClient) {
    mTextureClients.push(newClient);
  }
}
already_AddRefed<TextureClient>
TextureClientPool::GetTextureClient()
{
  // Try to fetch a client from the pool
  RefPtr<TextureClient> textureClient;

  // We initially allocate mInitialPoolSize for our pool. If we run
  // out of TextureClients, we allocate additional TextureClients to try and keep around
  // mPoolUnusedSize
  if (!mTextureClients.size()) {
    AllocateTextureClient();
  }

  if (!mTextureClients.size()) {
    // All our allocations failed, return nullptr
    return nullptr;
  }

  mOutstandingClients++;
  textureClient = mTextureClients.top();
  mTextureClients.pop();
#ifdef GFX_DEBUG_TRACK_CLIENTS_IN_POOL
  if (textureClient) {
    textureClient->mPoolTracker = this;
  }
  DebugOnly<bool> ok = TestClientPool("fetch", textureClient, this);
  MOZ_ASSERT(ok);
#endif
  TCP_LOG("TexturePool %p giving %p from pool; size %u outstanding %u\n",
      this, textureClient.get(), mTextureClients.size(), mOutstandingClients);

  return textureClient.forget();
}
void
TextureClientPool::Clear()
{
  TCP_LOG("TexturePool %p getting cleared\n", this);
  while (!mTextureClients.empty()) {
    TCP_LOG("TexturePool %p releasing client %p\n",
        this, mTextureClients.top().get());
    mTextureClients.pop();
  }
  while (!mTextureClientsDeferred.empty()) {
    MOZ_ASSERT(mOutstandingClients > 0);
    mOutstandingClients--;
    TCP_LOG("TexturePool %p releasing deferred client %p\n",
        this, mTextureClientsDeferred.front().get());
    mTextureClientsDeferred.pop_front();
  }
}
void
TextureClientPool::ReportClientLost()
{
  MOZ_ASSERT(mOutstandingClients > mTextureClientsDeferred.size());
  mOutstandingClients--;
  TCP_LOG("TexturePool %p getting report client lost; down to %u outstanding\n",
      this, mOutstandingClients);
}
void
TextureClientPool::ResetTimers()
{
  // Shrink down if we're beyond our maximum size
  if (mShrinkTimeoutMsec &&
      mTextureClients.size() + mTextureClientsDeferred.size() > mPoolUnusedSize) {
    TCP_LOG("TexturePool %p scheduling a shrink-to-max-size\n", this);
    mShrinkTimer->InitWithFuncCallback(ShrinkCallback, this, mShrinkTimeoutMsec,
                                       nsITimer::TYPE_ONE_SHOT);
  }

  // Clear pool after a period of inactivity to reduce memory consumption
  if (mClearTimeoutMsec) {
    TCP_LOG("TexturePool %p scheduling a clear\n", this);
    mClearTimer->InitWithFuncCallback(ClearCallback, this, mClearTimeoutMsec,
                                      nsITimer::TYPE_ONE_SHOT);
  }
}
示例#10
0
void HTTPConnection::sendData(mtpBuffer &buffer) {
	if (status == FinishedWork) return;

	if (buffer.size() < 3) {
		LOG(("TCP Error: writing bad packet, len = %1").arg(buffer.size() * sizeof(mtpPrime)));
		TCP_LOG(("TCP Error: bad packet %1").arg(Logs::mb(&buffer[0], buffer.size() * sizeof(mtpPrime)).str()));
		emit error();
		return;
	}

	int32 requestSize = (buffer.size() - 3) * sizeof(mtpPrime);

	QNetworkRequest request(address);
	request.setHeader(QNetworkRequest::ContentLengthHeader, QVariant(requestSize));
	request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(qsl("application/x-www-form-urlencoded")));

	TCP_LOG(("HTTP Info: sending %1 len request %2").arg(requestSize).arg(Logs::mb(&buffer[2], requestSize).str()));
	requests.insert(manager.post(request, QByteArray((const char*)(&buffer[2]), requestSize)));
}
示例#11
0
TemporaryRef<TextureClient>
TextureClientPool::GetTextureClient()
{
  // Try to fetch a client from the pool
  RefPtr<TextureClient> textureClient;
  if (mTextureClients.size()) {
    mOutstandingClients++;
    textureClient = mTextureClients.top();
    mTextureClients.pop();
#ifdef GFX_DEBUG_TRACK_CLIENTS_IN_POOL
    DebugOnly<bool> ok = TestClientPool("fetch", textureClient, this);
    MOZ_ASSERT(ok);
#endif
    TCP_LOG("TexturePool %p giving %p from pool; size %u outstanding %u\n",
        this, textureClient.get(), mTextureClients.size(), mOutstandingClients);
    return textureClient;
  }

  // We're increasing the number of outstanding TextureClients without reusing a
  // client, we may need to free a deferred-return TextureClient.
  ShrinkToMaximumSize();

  // No unused clients in the pool, create one
  if (gfxPrefs::ForceShmemTiles()) {
    // gfx::BackendType::NONE means use the content backend
    textureClient = TextureClient::CreateForRawBufferAccess(mSurfaceAllocator,
      mFormat, mSize, gfx::BackendType::NONE,
      TextureFlags::IMMEDIATE_UPLOAD, ALLOC_DEFAULT);
  } else {
    textureClient = TextureClient::CreateForDrawing(mSurfaceAllocator,
      mFormat, mSize, gfx::BackendType::NONE, TextureFlags::IMMEDIATE_UPLOAD);
  }

  mOutstandingClients++;
#ifdef GFX_DEBUG_TRACK_CLIENTS_IN_POOL
  if (textureClient) {
    textureClient->mPoolTracker = this;
  }
#endif
  TCP_LOG("TexturePool %p giving new %p; size %u outstanding %u\n",
      this, textureClient.get(), mTextureClients.size(), mOutstandingClients);
  return textureClient;
}
示例#12
0
void
TextureClientPool::ReturnDeferredClients()
{
  if (mTextureClientsDeferred.empty()) {
    return;
  }

  TCP_LOG("TexturePool %p returning %u deferred clients to pool\n",
      this, mTextureClientsDeferred.size());

  ReturnUnlockedClients();
  ShrinkToMaximumSize();
}
示例#13
0
void HTTPConnection::connectHttp(const QString &addr, int32 p, MTPDdcOption::Flags flags) {
	address = QUrl(((flags & MTPDdcOption::Flag::f_ipv6) ? qsl("http://[%1]:%2/api") : qsl("http://%1:%2/api")).arg(addr).arg(80));//not p - always 80 port for http transport
	TCP_LOG(("HTTP Info: address is %1").arg(address.toDisplayString()));
	connect(&manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(requestFinished(QNetworkReply*)));

	_flags = flags;

	mtpBuffer buffer(preparePQFake(httpNonce));

	DEBUG_LOG(("Connection Info: sending fake req_pq through HTTP/%1 transport").arg((flags & MTPDdcOption::Flag::f_ipv6) ? "IPv6" : "IPv4"));

	sendData(buffer);
}
示例#14
0
void
TextureClientPool::ReturnDeferredClients()
{
  TCP_LOG("TexturePool %p returning %u deferred clients to pool\n",
      this, mTextureClientsDeferred.size());
  while (!mTextureClientsDeferred.empty()) {
    mTextureClients.push(mTextureClientsDeferred.top());
    mTextureClientsDeferred.pop();

    MOZ_ASSERT(mOutstandingClients > 0);
    mOutstandingClients--;
  }
  ShrinkToMaximumSize();

  // Kick off the pool shrinking timer if there are still more unused texture
  // clients than our desired minimum cache size.
  if (mTextureClients.size() > sMinCacheSize) {
    TCP_LOG("TexturePool %p kicking off shrink-to-min timer\n", this);
    mTimer->InitWithFuncCallback(ShrinkCallback, this, mShrinkTimeoutMsec,
                                 nsITimer::TYPE_ONE_SHOT);
  }
}
示例#15
0
void
TextureClientPool::ShrinkToMaximumSize()
{
  // We're over our desired maximum size, immediately shrink down to the
  // maximum.
  //
  // We cull from the deferred TextureClients first, as we can't reuse those
  // until they get returned.
  uint32_t totalUnusedTextureClients = mTextureClients.size() + mTextureClientsDeferred.size();

  // If we have > mInitialPoolSize outstanding, then we want to keep around
  // mPoolUnusedSize at a maximum. If we have fewer than mInitialPoolSize
  // outstanding, then keep around the entire initial pool size.
  uint32_t targetUnusedClients;
  if (mOutstandingClients > mInitialPoolSize) {
    targetUnusedClients = mPoolUnusedSize;
  } else {
    targetUnusedClients = mInitialPoolSize;
  }

  TCP_LOG("TexturePool %p shrinking to maximum unused size %u; current pool size %u; total outstanding %u\n",
      this, targetUnusedClients, totalUnusedTextureClients, mOutstandingClients);

  while (totalUnusedTextureClients > targetUnusedClients) {
    if (mTextureClientsDeferred.size()) {
      mOutstandingClients--;
      TCP_LOG("TexturePool %p dropped deferred client %p; %u remaining\n",
          this, mTextureClientsDeferred.front().get(),
          mTextureClientsDeferred.size() - 1);
      mTextureClientsDeferred.pop_front();
    } else {
      TCP_LOG("TexturePool %p dropped non-deferred client %p; %u remaining\n",
          this, mTextureClients.top().get(), mTextureClients.size() - 1);
      mTextureClients.pop();
    }
    totalUnusedTextureClients--;
  }
}
示例#16
0
void
TextureClientPool::ReturnTextureClientDeferred(TextureClient *aClient)
{
  if (!aClient) {
    return;
  }
#ifdef GFX_DEBUG_TRACK_CLIENTS_IN_POOL
  DebugOnly<bool> ok = TestClientPool("defer", aClient, this);
  MOZ_ASSERT(ok);
#endif
  mTextureClientsDeferred.push(aClient);
  TCP_LOG("TexturePool %p had client %p defer-returned, size %u outstanding %u\n",
      this, aClient, mTextureClientsDeferred.size(), mOutstandingClients);
  ShrinkToMaximumSize();
}
示例#17
0
void
TextureClientPool::ReturnTextureClientDeferred(TextureClient* aClient)
{
  if (!aClient || mDestroyed) {
    return;
  }
  MOZ_ASSERT(aClient->GetReadLock());
#ifdef GFX_DEBUG_TRACK_CLIENTS_IN_POOL
  DebugOnly<bool> ok = TestClientPool("defer", aClient, this);
  MOZ_ASSERT(ok);
#endif
  mTextureClientsDeferred.push_back(aClient);
  TCP_LOG("TexturePool %p had client %p defer-returned, size %u outstanding %u\n",
      this, aClient, mTextureClientsDeferred.size(), mOutstandingClients);

  ResetTimers();
}
示例#18
0
void
TextureClientPool::ReturnTextureClient(TextureClient *aClient)
{
  if (!aClient || mDestroyed) {
    return;
  }
#ifdef GFX_DEBUG_TRACK_CLIENTS_IN_POOL
  DebugOnly<bool> ok = TestClientPool("return", aClient, this);
  MOZ_ASSERT(ok);
#endif
  // Add the client to the pool:
  MOZ_ASSERT(mOutstandingClients > mTextureClientsDeferred.size());
  mOutstandingClients--;
  mTextureClients.push(aClient);
  TCP_LOG("TexturePool %p had client %p returned; size %u outstanding %u\n",
      this, aClient, mTextureClients.size(), mOutstandingClients);

  ResetTimers();
}
示例#19
0
TextureClientPool::TextureClientPool(gfx::SurfaceFormat aFormat,
                                     gfx::IntSize aSize,
                                     uint32_t aMaxTextureClients,
                                     uint32_t aShrinkTimeoutMsec,
                                     ISurfaceAllocator *aAllocator)
  : mFormat(aFormat)
  , mSize(aSize)
  , mMaxTextureClients(aMaxTextureClients)
  , mShrinkTimeoutMsec(aShrinkTimeoutMsec)
  , mOutstandingClients(0)
  , mSurfaceAllocator(aAllocator)
{
  TCP_LOG("TexturePool %p created with max size %u and timeout %u\n",
      this, mMaxTextureClients, aShrinkTimeoutMsec);
  mTimer = do_CreateInstance("@mozilla.org/timer;1");
  if (aFormat == gfx::SurfaceFormat::UNKNOWN) {
    gfxWarning() << "Creating texture pool for SurfaceFormat::UNKNOWN format";
  }
}