当前位置: 首页>>代码示例>>C++>>正文


C++ Maybe类代码示例

本文整理汇总了C++中Maybe的典型用法代码示例。如果您正苦于以下问题:C++ Maybe类的具体用法?C++ Maybe怎么用?C++ Maybe使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Maybe类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: NS_ASSERTION

void VideoFrameContainer::InvalidateWithFlags(uint32_t aFlags)
{
  NS_ASSERTION(NS_IsMainThread(), "Must call on main thread");

  if (!mElement) {
    // Element has been destroyed
    return;
  }

  nsIFrame* frame = mElement->GetPrimaryFrame();
  bool invalidateFrame = false;

  {
    Maybe<AutoTimer<Telemetry::VFC_INVALIDATE_LOCK_WAIT_MS>> lockWait;
    lockWait.emplace();

    MutexAutoLock lock(mMutex);

    lockWait.reset();
    AutoTimer<Telemetry::VFC_INVALIDATE_LOCK_HOLD_MS> lockHold;

    // Get mImageContainerSizeChanged while holding the lock.
    invalidateFrame = mImageSizeChanged;
    mImageSizeChanged = false;

    if (mIntrinsicSizeChanged) {
      mElement->UpdateMediaSize(mIntrinsicSize);
      mIntrinsicSizeChanged = false;

      if (frame) {
        nsPresContext* presContext = frame->PresContext();
        nsIPresShell *presShell = presContext->PresShell();
        presShell->FrameNeedsReflow(frame,
                                    nsIPresShell::eStyleChange,
                                    NS_FRAME_IS_DIRTY);
      }
    }
  }

  bool asyncInvalidate = mImageContainer &&
                         mImageContainer->IsAsync() &&
                         !(aFlags & INVALIDATE_FORCE);

  if (frame) {
    if (invalidateFrame) {
      frame->InvalidateFrame();
    } else {
      frame->InvalidateLayer(nsDisplayItem::TYPE_VIDEO, nullptr, nullptr,
                             asyncInvalidate ? nsIFrame::UPDATE_IS_ASYNC : 0);
    }
  }

  nsSVGEffects::InvalidateDirectRenderingObservers(mElement);
}
开发者ID:ncalexan,项目名称:gecko-dev,代码行数:54,代码来源:VideoFrameContainer.cpp

示例2: triangle

void
Compositor::DrawGeometry(const gfx::Rect& aRect,
                         const gfx::IntRect& aClipRect,
                         const EffectChain& aEffectChain,
                         gfx::Float aOpacity,
                         const gfx::Matrix4x4& aTransform,
                         const gfx::Rect& aVisibleRect,
                         const Maybe<gfx::Polygon3D>& aGeometry)
{
  if (!aGeometry) {
    DrawQuad(aRect, aClipRect, aEffectChain,
             aOpacity, aTransform, aVisibleRect);
    return;
  }

  // Cull invisible polygons.
  if (aRect.Intersect(aGeometry->BoundingBox()).IsEmpty()) {
    return;
  }

  gfx::Polygon3D clipped = aGeometry->ClipPolygon(aRect);
  nsTArray<gfx::Triangle> triangles = clipped.ToTriangles();

  for (gfx::Triangle& geometry : triangles) {
    const gfx::Rect intersection = aRect.Intersect(geometry.BoundingBox());

    // Cull invisible triangles.
    if (intersection.IsEmpty()) {
      continue;
    }

    MOZ_ASSERT(aRect.width > 0.0f && aRect.height > 0.0f);
    MOZ_ASSERT(intersection.width > 0.0f && intersection.height > 0.0f);

    gfx::TexturedTriangle triangle(Move(geometry));
    triangle.width = aRect.width;
    triangle.height = aRect.height;

    // Since the texture was created for non-split geometry, we need to
    // update the texture coordinates to account for the split.
    if (aEffectChain.mPrimaryEffect->mType == EffectTypes::RGB) {
      TexturedEffect* texturedEffect =
        static_cast<TexturedEffect*>(aEffectChain.mPrimaryEffect.get());

      UpdateTextureCoordinates(triangle, aRect, intersection,
                               texturedEffect->mTextureCoords);
    }

    DrawTriangle(triangle, aClipRect, aEffectChain,
                 aOpacity, aTransform, aVisibleRect);
  }
}
开发者ID:MichaelKohler,项目名称:gecko-dev,代码行数:52,代码来源:Compositor.cpp

示例3: MOZ_ASSERT

nsresult
SourceBuffer::Compact()
{
  mMutex.AssertCurrentThreadOwns();

  MOZ_ASSERT(mConsumerCount == 0, "Should have no consumers here");
  MOZ_ASSERT(mWaitingConsumers.Length() == 0, "Shouldn't have waiters");
  MOZ_ASSERT(mStatus, "Should be complete here");

  // Compact our waiting consumers list, since we're complete and no future
  // consumer will ever have to wait.
  mWaitingConsumers.Compact();

  // If we have no chunks, then there's nothing to compact.
  if (mChunks.Length() < 1) {
    return NS_OK;
  }

  // If we have one chunk, then we can compact if it has excess capacity.
  if (mChunks.Length() == 1 && mChunks[0].Length() == mChunks[0].Capacity()) {
    return NS_OK;
  }

  // We can compact our buffer. Determine the total length.
  size_t length = 0;
  for (uint32_t i = 0 ; i < mChunks.Length() ; ++i) {
    length += mChunks[i].Length();
  }

  Maybe<Chunk> newChunk = CreateChunk(length, /* aRoundUp = */ false);
  if (MOZ_UNLIKELY(!newChunk || newChunk->AllocationFailed())) {
    NS_WARNING("Failed to allocate chunk for SourceBuffer compacting - OOM?");
    return NS_OK;
  }

  // Copy our old chunks into the new chunk.
  for (uint32_t i = 0 ; i < mChunks.Length() ; ++i) {
    size_t offset = newChunk->Length();
    MOZ_ASSERT(offset < newChunk->Capacity());
    MOZ_ASSERT(offset + mChunks[i].Length() <= newChunk->Capacity());

    memcpy(newChunk->Data() + offset, mChunks[i].Data(), mChunks[i].Length());
    newChunk->AddLength(mChunks[i].Length());
  }

  MOZ_ASSERT(newChunk->Length() == newChunk->Capacity(),
             "Compacted chunk has slack space");

  // Replace the old chunks with the new, compact chunk.
  mChunks.Clear();
  if (MOZ_UNLIKELY(NS_FAILED(AppendChunk(Move(newChunk))))) {
    return HandleError(NS_ERROR_OUT_OF_MEMORY);
  }
  mChunks.Compact();

  return NS_OK;
}
开发者ID:AOSC-Dev,项目名称:Pale-Moon,代码行数:57,代码来源:SourceBuffer.cpp

示例4: XGetGeometry

Maybe<gfx::IntSize>
GLContextGLX::GetTargetSize()
{
    unsigned int width = 0, height = 0;
    Window root;
    int x, y;
    unsigned int border, depth;
    XGetGeometry(mDisplay, mDrawable, &root, &x, &y, &width, &height,
                 &border, &depth);
    Maybe<gfx::IntSize> size;
    size.emplace(width, height);
    return size;
}
开发者ID:brendandahl,项目名称:positron,代码行数:13,代码来源:GLContextProviderGLX.cpp

示例5: AddWorkerHolderToStreamChild

void CacheOpChild::HandleResponse(const Maybe<CacheResponse>& aMaybeResponse) {
  if (aMaybeResponse.isNothing()) {
    mPromise->MaybeResolveWithUndefined();
    return;
  }

  const CacheResponse& cacheResponse = aMaybeResponse.ref();

  AddWorkerHolderToStreamChild(cacheResponse, GetWorkerHolder());
  RefPtr<Response> response = ToResponse(cacheResponse);

  mPromise->MaybeResolve(response);
}
开发者ID:Noctem,项目名称:gecko-dev,代码行数:13,代码来源:CacheOpChild.cpp

示例6: TEST

TEST(ContainerParser, MIMETypes)
{
  const char* containerTypes[] = {"video/webm", "audio/webm", "video/mp4",
                                  "audio/mp4", "audio/aac"};
  nsAutoPtr<ContainerParser> parser;
  for (size_t i = 0; i < ArrayLength(containerTypes); ++i) {
    Maybe<MediaContainerType> containerType =
        MakeMediaContainerType(containerTypes[i]);
    ASSERT_TRUE(containerType.isSome());
    parser = ContainerParser::CreateForMIMEType(*containerType);
    ASSERT_NE(parser, nullptr);
  }
}
开发者ID:jld,项目名称:gecko-dev,代码行数:13,代码来源:TestContainerParser.cpp

示例7: AssertIsOnOwningThread

void
IDBRequest::SetResultCallback(ResultCallback* aCallback)
{
  AssertIsOnOwningThread();
  MOZ_ASSERT(aCallback);
  MOZ_ASSERT(!mHaveResultOrErrorCode);
  MOZ_ASSERT(mResultVal.isUndefined());
  MOZ_ASSERT(!mError);

  // See if our window is still valid.
  if (NS_WARN_IF(NS_FAILED(CheckInnerWindowCorrectness()))) {
    IDB_REPORT_INTERNAL_ERR();
    SetError(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
    return;
  }

  AutoJSAPI autoJS;
  Maybe<JSAutoCompartment> ac;

  if (GetScriptOwner()) {
    // If we have a script owner we want the SafeJSContext and then to enter the
    // script owner's compartment.
    autoJS.Init();
    ac.emplace(autoJS.cx(), GetScriptOwner());
  } else {
    // Otherwise our owner is a window and we use that to initialize.
    MOZ_ASSERT(GetOwner());
    if (!autoJS.InitWithLegacyErrorReporting(GetOwner())) {
      IDB_WARNING("Failed to initialize AutoJSAPI!");
      SetError(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
      return;
    }
  }

  JSContext* cx = autoJS.cx();

  AssertIsRooted();

  JS::Rooted<JS::Value> result(cx);
  nsresult rv = aCallback->GetResult(cx, &result);
  if (NS_WARN_IF(NS_FAILED(rv))) {
    SetError(rv);
    mResultVal.setUndefined();
  } else {
    mError = nullptr;
    mResultVal = result;
  }

  mHaveResultOrErrorCode = true;
}
开发者ID:alex-tifrea,项目名称:gecko-dev,代码行数:50,代码来源:IDBRequest.cpp

示例8: id

dom::Nullable<uint64_t>
DominatorTree::GetImmediateDominator(uint64_t aNodeId) const
{
  JS::ubi::Node::Id id(aNodeId);
  Maybe<JS::ubi::Node> node = mHeapSnapshot->getNodeById(id);
  if (node.isNothing())
    return dom::Nullable<uint64_t>();

  JS::ubi::Node dominator = mDominatorTree.getImmediateDominator(*node);
  if (!dominator || dominator == *node)
    return dom::Nullable<uint64_t>();

  return dom::Nullable<uint64_t>(dominator.identifier());
}
开发者ID:artines1,项目名称:gecko-dev,代码行数:14,代码来源:DominatorTree.cpp

示例9: rect

void
nsHTMLButtonControlFrame::BuildDisplayList(nsDisplayListBuilder*   aBuilder,
                                           const nsRect&           aDirtyRect,
                                           const nsDisplayListSet& aLists)
{
  // Clip to our border area for event hit testing.
  Maybe<DisplayListClipState::AutoSaveRestore> eventClipState;
  const bool isForEventDelivery = aBuilder->IsForEventDelivery();
  if (isForEventDelivery) {
    eventClipState.emplace(aBuilder);
    nsRect rect(aBuilder->ToReferenceFrame(this), GetSize());
    nscoord radii[8];
    bool hasRadii = GetBorderRadii(radii);
    eventClipState->ClipContainingBlockDescendants(rect, hasRadii ? radii : nullptr);
  }

  nsDisplayList onTop;
  if (IsVisibleForPainting(aBuilder)) {
    mRenderer.DisplayButton(aBuilder, aLists.BorderBackground(), &onTop);
  }

  nsDisplayListCollection set;

  // Do not allow the child subtree to receive events.
  if (!isForEventDelivery) {
    DisplayListClipState::AutoSaveRestore clipState(aBuilder);

    if (IsInput() || StyleDisplay()->mOverflowX != NS_STYLE_OVERFLOW_VISIBLE) {
      nsMargin border = StyleBorder()->GetComputedBorder();
      nsRect rect(aBuilder->ToReferenceFrame(this), GetSize());
      rect.Deflate(border);
      nscoord radii[8];
      bool hasRadii = GetPaddingBoxBorderRadii(radii);
      clipState.ClipContainingBlockDescendants(rect, hasRadii ? radii : nullptr);
    }

    BuildDisplayListForChild(aBuilder, mFrames.FirstChild(), aDirtyRect, set,
                             DISPLAY_CHILD_FORCE_PSEUDO_STACKING_CONTEXT);
    // That should put the display items in set.Content()
  }
  
  // Put the foreground outline and focus rects on top of the children
  set.Content()->AppendToTop(&onTop);
  set.MoveTo(aLists);
  
  DisplayOutline(aBuilder, aLists);

  // to draw border when selected in editor
  DisplaySelectionOverlay(aBuilder, aLists.Content());
}
开发者ID:Nazi-Nigger,项目名称:gecko-dev,代码行数:50,代码来源:nsHTMLButtonControlFrame.cpp

示例10: js_ContextIterator

JSContext *
js_ContextIterator(JSRuntime *rt, JSBool unlocked, JSContext **iterp)
{
    JSContext *cx = *iterp;

    Maybe<AutoLockGC> lockIf;
    if (unlocked)
        lockIf.construct(rt);
    cx = JSContext::fromLinkField(cx ? cx->link.next : rt->contextList.next);
    if (&cx->link == &rt->contextList)
        cx = NULL;
    *iterp = cx;
    return cx;
}
开发者ID:mbrubeck,项目名称:mozilla-central,代码行数:14,代码来源:jscntxt.cpp

示例11: findLocalMin

std::pair<T, int> findLocalMin(const Shrinkable<T> &shrinkable,
                               Predicate pred) {
  std::pair<T, int> result(shrinkable.value(), 0);
  Seq<Shrinkable<T>> shrinks = shrinkable.shrinks();
  Maybe<Shrinkable<T>> shrink;
  while ((shrink = shrinks.next())) {
    T value = shrink->value();
    if (pred(value)) {
      result.first = std::move(value);
      shrinks = shrink->shrinks();
      result.second++;
    }
  }

  return result;
}
开发者ID:neoliang,项目名称:test-code,代码行数:16,代码来源:Operations.hpp

示例12: gmp

void
GMPVideoDecoder::InitTags(nsTArray<nsCString>& aTags)
{
  if (MP4Decoder::IsH264(mConfig.mMimeType)) {
    aTags.AppendElement(NS_LITERAL_CSTRING("h264"));
    const Maybe<nsCString> gmp(
      GMPDecoderModule::PreferredGMP(NS_LITERAL_CSTRING("video/avc")));
    if (gmp.isSome()) {
      aTags.AppendElement(gmp.value());
    }
  } else if (VPXDecoder::IsVP8(mConfig.mMimeType)) {
    aTags.AppendElement(NS_LITERAL_CSTRING("vp8"));
  } else if (VPXDecoder::IsVP9(mConfig.mMimeType)) {
    aTags.AppendElement(NS_LITERAL_CSTRING("vp9"));
  }
}
开发者ID:philbooth,项目名称:gecko-dev,代码行数:16,代码来源:GMPVideoDecoder.cpp

示例13: Some

void
FrameBuilder::ProcessChildList(ContainerLayer* aContainer,
                               RenderViewMLGPU* aView,
                               const RenderTargetIntRect& aParentClipRect,
                               const Maybe<gfx::Polygon>& aParentGeometry)
{
  nsTArray<LayerPolygon> polygons =
    aContainer->SortChildrenBy3DZOrder(ContainerLayer::SortMode::WITH_GEOMETRY);

  // Visit layers in front-to-back order.
  for (auto iter = polygons.rbegin(); iter != polygons.rend(); iter++) {
    LayerPolygon& entry = *iter;
    Layer* child = entry.layer;
    if (child->IsBackfaceHidden() || !child->IsVisible()) {
      continue;
    }

    RenderTargetIntRect clip = child->CalculateScissorRect(aParentClipRect);
    if (clip.IsEmpty()) {
      continue;
    }

    Maybe<gfx::Polygon> geometry;
    if (aParentGeometry && entry.geometry) {
      // Both parent and child are split.
      geometry = Some(aParentGeometry->ClipPolygon(*entry.geometry));
    } else if (aParentGeometry) {
      geometry = aParentGeometry;
    } else if (entry.geometry) {
      geometry = Move(entry.geometry);
    }

    AssignLayer(child, aView, clip, Move(geometry));
  }
}
开发者ID:,项目名称:,代码行数:35,代码来源:

示例14: CreateSurfaceFromRawData

/*
 * CreateImageFromRawData(), CreateSurfaceFromRawData() and
 * CreateImageFromRawDataInMainThreadSyncTask are helpers for
 * create-from-ImageData case
 */
static already_AddRefed<SourceSurface>
CreateSurfaceFromRawData(const gfx::IntSize& aSize,
                         uint32_t aStride,
                         gfx::SurfaceFormat aFormat,
                         uint8_t* aBuffer,
                         uint32_t aBufferLength,
                         const Maybe<IntRect>& aCropRect)
{
  MOZ_ASSERT(!aSize.IsEmpty());
  MOZ_ASSERT(aBuffer);

  // Wrap the source buffer into a SourceSurface.
  RefPtr<DataSourceSurface> dataSurface =
    Factory::CreateWrappingDataSourceSurface(aBuffer, aStride, aSize, aFormat);

  if (NS_WARN_IF(!dataSurface)) {
    return nullptr;
  }

  // The temporary cropRect variable is equal to the size of source buffer if we
  // do not need to crop, or it equals to the given cropping size.
  const IntRect cropRect = aCropRect.valueOr(IntRect(0, 0, aSize.width, aSize.height));

  // Copy the source buffer in the _cropRect_ area into a new SourceSurface.
  RefPtr<DataSourceSurface> result = CropAndCopyDataSourceSurface(dataSurface, cropRect);

  if (NS_WARN_IF(!result)) {
    return nullptr;
  }

  return result.forget();
}
开发者ID:Danielzac,项目名称:gecko-dev,代码行数:37,代码来源:ImageBitmap.cpp

示例15: NotifyPushObservers

nsresult
PushNotifier::NotifyPush(const nsACString& aScope, nsIPrincipal* aPrincipal,
                         const nsAString& aMessageId,
                         const Maybe<nsTArray<uint8_t>>& aData)
{
  // Notify XPCOM observers in the current process.
  nsresult rv = NotifyPushObservers(aScope, aData);
  Unused << NS_WARN_IF(NS_FAILED(rv));

  if (XRE_IsContentProcess()) {
    // If we're in the content process, forward the notification to the parent.
    // We don't need to do anything if we're already in the parent;
    // `ContentChild::RecvPush` will notify content process observers.
    ContentChild* parentActor = ContentChild::GetSingleton();
    if (!NS_WARN_IF(!parentActor)) {
      if (aData) {
        Unused << NS_WARN_IF(
          !parentActor->SendNotifyPushObserversWithData(
            PromiseFlatCString(aScope), PromiseFlatString(aMessageId),
            aData.ref()));
      } else {
        Unused << NS_WARN_IF(
          !parentActor->SendNotifyPushObservers(
            PromiseFlatCString(aScope), PromiseFlatString(aMessageId)));
      }
    }
  }

  rv = NotifyPushWorkers(aScope, aPrincipal, aMessageId, aData);
  if (NS_WARN_IF(NS_FAILED(rv))) {
    return rv;
  }
  return NS_OK;
}
开发者ID:flodolo,项目名称:gecko-dev,代码行数:34,代码来源:PushNotifier.cpp


注:本文中的Maybe类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。