void Ctrl::GatherTransparentAreas(Vector<Rect>& area, SystemDraw& w, Rect r, const Rect& clip) { GuiLock __; LTIMING("GatherTransparentAreas"); Point off = r.TopLeft(); Point viewpos = off + GetView().TopLeft(); r.Inflate(overpaint); Rect notr = GetVoidRect(); if(notr.IsEmpty()) notr = GetOpaqueRect(); notr += viewpos; if(!IsShown() || r.IsEmpty() || !clip.Intersects(r) || !w.IsPainting(r)) return; if(notr.IsEmpty()) CombineArea(area, r & clip); else { if(notr != r) { CombineArea(area, clip & Rect(r.left, r.top, notr.left, r.bottom)); CombineArea(area, clip & Rect(notr.right, r.top, r.right, r.bottom)); CombineArea(area, clip & Rect(notr.left, r.top, notr.right, notr.top)); CombineArea(area, clip & Rect(notr.left, notr.bottom, notr.right, r.bottom)); } for(Ctrl *q = firstchild; q; q = q->next) { Point qoff = q->InView() ? viewpos : off; Rect qr = q->GetRect() + qoff; if(clip.Intersects(qr)) q->GatherTransparentAreas(area, w, qr, clip); } } }
bool Ctrl::PaintOpaqueAreas(SystemDraw& w, const Rect& r, const Rect& clip, bool nochild) { GuiLock __; LTIMING("PaintOpaqueAreas"); if(!IsShown() || r.IsEmpty() || !r.Intersects(clip) || !w.IsPainting(r)) return true; Point off = r.TopLeft(); Point viewpos = off + GetView().TopLeft(); if(backpaint == EXCLUDEPAINT) return w.ExcludeClip(r); Rect cview = clip & (GetView() + off); for(Ctrl *q = lastchild; q; q = q->prev) if(!q->PaintOpaqueAreas(w, q->GetRect() + (q->InView() ? viewpos : off), q->InView() ? cview : clip)) return false; if(nochild && (lastchild || GetNext())) return true; Rect opaque = (GetOpaqueRect() + viewpos) & clip; if(opaque.IsEmpty()) return true; #ifdef SYSTEMDRAW if(backpaint == FULLBACKPAINT && !dynamic_cast<BackDraw *>(&w)) #else if(backpaint == FULLBACKPAINT && !w.IsBack()) #endif { ShowRepaintRect(w, opaque, LtRed()); BackDraw bw; bw.Create(w, opaque.GetSize()); bw.Offset(viewpos - opaque.TopLeft()); bw.SetPaintingDraw(w, opaque.TopLeft()); { LEVELCHECK(bw, this); Paint(bw); PaintCaret(bw); } bw.Put(w, opaque.TopLeft()); } else { w.Clip(opaque); ShowRepaintRect(w, opaque, Green()); w.Offset(viewpos); { LEVELCHECK(w, this); Paint(w); PaintCaret(w); } w.End(); w.End(); } LLOG("Exclude " << opaque); return w.ExcludeClip(opaque); }
void RenderWindow::Init(HWND parent, const Rect& bounds) { if (window_style_ == 0) window_style_ = parent ? kWindowDefaultChildStyle : kWindowDefaultStyle; int x, y, width, height; if (bounds.IsEmpty()) { x = y = width = height = CW_USEDEFAULT; } else { x = bounds.x(); y = bounds.y(); width = bounds.width(); height = bounds.height(); } bool destroyed = false; HWND hwnd = CreateWindowEx(window_ex_style_, kRenderWindowClassName, NULL, window_style_, x, y, width, height, parent, NULL, NULL, this); //assert(hwnd_ && GetLastError() == 0); DWORD dwStyle = GetWindowLong(GWL_STYLE); SetWindowLong(GWL_STYLE, (dwStyle & ~WS_CAPTION)); //SetBoundsRect(bounds); }
void Ctrl::RefreshFrame(const Rect& r) { GuiLock __; if(!IsOpen() || !IsVisible() || r.IsEmpty()) return; LTIMING("RefreshFrame"); LLOG("RefreshRect " << Name() << ' ' << r); #ifdef PLATFORM_WIN32 if(isdhctrl) { InvalidateRect(((DHCtrl *)this)->GetHWND(), r, false); return; } #endif if(!top) { if(InFrame()) parent->RefreshFrame(r + GetRect().TopLeft()); else parent->Refresh(r + GetRect().TopLeft()); } else { LLOG("WndInvalidateRect: " << r << ' ' << Name()); LTIMING("RefreshFrame InvalidateRect"); WndInvalidateRect(r); #ifdef PLATFORM_WIN32 LLOG("UpdateRect: " << GetWndUpdateRect() << ' ' << Name()); #endif } }
void DrawTargetSkia::DrawSurface(SourceSurface *aSurface, const Rect &aDest, const Rect &aSource, const DrawSurfaceOptions &aSurfOptions, const DrawOptions &aOptions) { if (!(aSurface->GetType() == SurfaceType::SKIA || aSurface->GetType() == SurfaceType::DATA)) { return; } if (aSource.IsEmpty()) { return; } MarkChanged(); SkRect destRect = RectToSkRect(aDest); SkRect sourceRect = RectToSkRect(aSource); TempBitmap bitmap = GetBitmapForSurface(aSurface); AutoPaintSetup paint(mCanvas.get(), aOptions); if (aSurfOptions.mFilter == Filter::POINT) { paint.mPaint.setFilterBitmap(false); } mCanvas->drawBitmapRectToRect(bitmap.mBitmap, &sourceRect, destRect, &paint.mPaint); }
void DrawTargetSkia::DrawSurface(SourceSurface *aSurface, const Rect &aDest, const Rect &aSource, const DrawSurfaceOptions &aSurfOptions, const DrawOptions &aOptions) { if (aSurface->GetType() != SURFACE_SKIA) { return; } if (aSource.IsEmpty()) { return; } MarkChanged(); SkRect destRect = RectToSkRect(aDest); SkRect sourceRect = RectToSkRect(aSource); SkMatrix matrix; matrix.setRectToRect(sourceRect, destRect, SkMatrix::kFill_ScaleToFit); const SkBitmap& bitmap = static_cast<SourceSurfaceSkia*>(aSurface)->GetBitmap(); AutoPaintSetup paint(mCanvas.get(), aOptions); SkShader *shader = SkShader::CreateBitmapShader(bitmap, SkShader::kClamp_TileMode, SkShader::kClamp_TileMode); shader->setLocalMatrix(matrix); SkSafeUnref(paint.mPaint.setShader(shader)); if (aSurfOptions.mFilter != FILTER_LINEAR) { paint.mPaint.setFilterBitmap(false); } mCanvas->drawRect(destRect, paint.mPaint); }
void Ctrl::ScrollCtrl(Top *top, Ctrl *q, const Rect& r, Rect cr, int dx, int dy) { if(top && r.Intersects(cr)) { // Uno: Contains -> Intersetcs Rect to = cr; GetTopRect(to, false); if(r.Intersects(cr.Offseted(-dx, -dy))) { // Uno's suggestion 06/11/26 Contains -> Intersetcs Rect from = cr.Offseted(-dx, -dy); GetTopRect(from, false); MoveCtrl *m = FindMoveCtrlPtr(top->move, q); if(m && m->from == from && m->to == to) { LLOG("ScrollView Matched " << from << " -> " << to); m->ctrl = NULL; return; } } if(r.Intersects(cr.Offseted(dx, dy))) { // Uno's suggestion 06/11/26 Contains -> Intersetcs Rect from = to; to = cr.Offseted(dx, dy); GetTopRect(to, false); MoveCtrl& m = top->scroll_move.Add(q); m.from = from; m.to = to; m.ctrl = q; LLOG("ScrollView Add " << UPP::Name(q) << from << " -> " << to); return; } cr &= r; if(!cr.IsEmpty()) { Refresh(cr); Refresh(cr + Point(dx, dy)); } } }
void StrokeSnappedEdgesOfRect(const Rect& aRect, DrawTarget& aDrawTarget, const ColorPattern& aColor, const StrokeOptions& aStrokeOptions) { if (aRect.IsEmpty()) { return; } Point p1 = aRect.TopLeft(); Point p2 = aRect.BottomLeft(); SnapLineToDevicePixelsForStroking(p1, p2, aDrawTarget); aDrawTarget.StrokeLine(p1, p2, aColor, aStrokeOptions); p1 = aRect.BottomLeft(); p2 = aRect.BottomRight(); SnapLineToDevicePixelsForStroking(p1, p2, aDrawTarget); aDrawTarget.StrokeLine(p1, p2, aColor, aStrokeOptions); p1 = aRect.TopLeft(); p2 = aRect.TopRight(); SnapLineToDevicePixelsForStroking(p1, p2, aDrawTarget); aDrawTarget.StrokeLine(p1, p2, aColor, aStrokeOptions); p1 = aRect.TopRight(); p2 = aRect.BottomRight(); SnapLineToDevicePixelsForStroking(p1, p2, aDrawTarget); aDrawTarget.StrokeLine(p1, p2, aColor, aStrokeOptions); }
bool SystemDraw::IsPaintingOp(const Rect& r) const { Rect cr = r.Offseted(GetOffset()); cr.Intersect(GetClip()); if(cr.IsEmpty()) return false; return !invalid || gdk_region_rect_in(invalid, GdkRect(cr)) != GDK_OVERLAP_RECTANGLE_OUT; }
void Ctrl::ScrollRefresh(const Rect& r, int dx, int dy) { GuiLock __; if(!IsOpen() || !IsVisible() || r.IsEmpty()) return; int tdx = tabs(dx), tdy = tabs(dy); if(dx) WndInvalidateRect(RectC(dx >= 0 ? r.left : r.right - tdx, r.top - tdy, tdx, r.Height())); if(dy) WndInvalidateRect(RectC(r.left - tdx, dy >= 0 ? r.top : r.bottom - tdy, r.Width(), tdy)); }
void gfxContext::PushGroupAndCopyBackground(gfxContentType content) { IntRect clipExtents; if (mDT->GetFormat() != SurfaceFormat::B8G8R8X8) { gfxRect clipRect = GetRoundOutDeviceClipExtents(this); clipExtents = IntRect(clipRect.x, clipRect.y, clipRect.width, clipRect.height); } if ((mDT->GetFormat() == SurfaceFormat::B8G8R8X8 || mDT->GetOpaqueRect().Contains(clipExtents)) && !mDT->GetUserData(&sDontUseAsSourceKey)) { DrawTarget *oldDT = mDT; RefPtr<SourceSurface> source = mDT->Snapshot(); Point oldDeviceOffset = CurrentState().deviceOffset; PushNewDT(gfxContentType::COLOR); if (oldDT == mDT) { // Creating new DT failed. return; } Point offset = CurrentState().deviceOffset - oldDeviceOffset; Rect surfRect(0, 0, Float(mDT->GetSize().width), Float(mDT->GetSize().height)); Rect sourceRect = surfRect + offset; mDT->SetTransform(Matrix()); // XXX: It's really sad that we have to do this (for performance). // Once DrawTarget gets a PushLayer API we can implement this within // DrawTargetTiled. if (source->GetType() == SurfaceType::TILED) { SnapshotTiled *sourceTiled = static_cast<SnapshotTiled*>(source.get()); for (uint32_t i = 0; i < sourceTiled->mSnapshots.size(); i++) { Rect tileSourceRect = sourceRect.Intersect(Rect(sourceTiled->mOrigins[i].x, sourceTiled->mOrigins[i].y, sourceTiled->mSnapshots[i]->GetSize().width, sourceTiled->mSnapshots[i]->GetSize().height)); if (tileSourceRect.IsEmpty()) { continue; } Rect tileDestRect = tileSourceRect - offset; tileSourceRect -= sourceTiled->mOrigins[i]; mDT->DrawSurface(sourceTiled->mSnapshots[i], tileDestRect, tileSourceRect); } } else { mDT->DrawSurface(source, surfRect, sourceRect); } mDT->SetOpaqueRect(oldDT->GetOpaqueRect()); PushClipsToDT(mDT); mDT->SetTransform(GetDTTransform()); return; } PushGroup(content); }
bool Context::IsImmutable () { Rect box; Top ()->GetClip (&box); return box.IsEmpty (); }
void Ctrl::ScrollRefresh(const Rect& r, int dx, int dy) { sCheckGuiLock(); GuiLock __; // Beware: Even if we have ThreadHasGuiLock ASSERT, we still can be the main thread! LLOG("ScrollRefresh " << r << " " << dx << " " << dy); if(!IsOpen() || !IsVisible() || r.IsEmpty()) return; int tdx = tabs(dx), tdy = tabs(dy); if(dx) WndInvalidateRect(RectC(dx >= 0 ? r.left : r.right - tdx, r.top - tdy, tdx, r.Height())); if(dy) WndInvalidateRect(RectC(r.left - tdx, dy >= 0 ? r.top : r.bottom - tdy, r.Width(), tdy)); }
Rect Ctrl::GetClipBound(const Vector<Rect>& inv, const Rect& r) { Rect ri = Null; for(int j = 0; j < inv.GetCount(); j++) { Rect rr = inv[j] & r; if(!rr.IsEmpty()) ri = IsNull(ri) ? rr : rr | ri; } return ri; }
void TopWindow::SetupRect(Ctrl *owner) { Rect r = GetRect(); if(r.IsEmpty()) SetRect(GetDefaultWindowRect()); else if(r.left == 0 && r.top == 0 && center == 1) { Rect area = owner ? owner->GetWorkArea() : Ctrl::GetWorkArea(); SetRect(area.CenterRect(min(area.Size(), r.Size()))); } }
void LayerManagerComposite::Render() { PROFILER_LABEL("LayerManagerComposite", "Render"); if (mDestroyed) { NS_WARNING("Call on destroyed layer manager"); return; } if (mComposer2D && mComposer2D->TryRender(mRoot, mWorldMatrix)) { mCompositor->EndFrameForExternalComposition(mWorldMatrix); return; } mCompositor->GetWidget()->PreRender(this); nsIntRect clipRect; Rect bounds(mRenderBounds.x, mRenderBounds.y, mRenderBounds.width, mRenderBounds.height); Rect actualBounds; if (mRoot->GetClipRect()) { clipRect = *mRoot->GetClipRect(); WorldTransformRect(clipRect); Rect rect(clipRect.x, clipRect.y, clipRect.width, clipRect.height); mCompositor->BeginFrame(&rect, mWorldMatrix, bounds, nullptr, &actualBounds); } else { gfx::Rect rect; mCompositor->BeginFrame(nullptr, mWorldMatrix, bounds, &rect, &actualBounds); clipRect = nsIntRect(rect.x, rect.y, rect.width, rect.height); } if (actualBounds.IsEmpty()) { return; } // Allow widget to render a custom background. mCompositor->GetWidget()->DrawWindowUnderlay(this, nsIntRect(actualBounds.x, actualBounds.y, actualBounds.width, actualBounds.height)); // Render our layers. RootLayer()->RenderLayer(nsIntPoint(0, 0), clipRect); // Allow widget to render a custom foreground. mCompositor->GetWidget()->DrawWindowOverlay(this, nsIntRect(actualBounds.x, actualBounds.y, actualBounds.width, actualBounds.height)); mCompositor->EndFrame(); }
void SDraw::DrawRectOp(int x, int y, int cx, int cy, Color color) { if(IsNull(color)) return; Rect r = RectC(x, y, cx, cy); r += cloff.Top().offset; const Vector<Rect>& clip = cloff.Top().clip; for(int i = 0; i < clip.GetCount(); i++) { Rect cr = clip[i] & r; if(!cr.IsEmpty()) PutRect(cr, color); } }
Rect Rect::Union(const Rect& rect) const { // special case empty rects... if (IsEmpty()) return rect; if (rect.IsEmpty()) return *this; int32_t rx = std::min(x(), rect.x()); int32_t ry = std::min(y(), rect.y()); int32_t rr = std::max(right(), rect.right()); int32_t rb = std::max(bottom(), rect.bottom()); return Rect(rx, ry, rr - rx, rb - ry); }
cairo_t * MoonEGLContext::Push (Cairo extents) { Target *target = Top ()->GetTarget (); Target *cairo = target->GetCairoTarget (); Rect box; Top ()->GetClip (&box); box = box.Intersection (extents.r); if (box.IsEmpty ()) return Context::Push (extents); if (cairo) { Rect r = cairo->GetData (NULL); Region *region = new Region (r); if (region->RectIn (box) != CAIRO_REGION_OVERLAP_IN) { ForceCurrent (); SyncDrawable (); } delete region; } if (!target->GetCairoTarget ()) { MoonSurface *ms; Rect r = target->GetData (&ms); if (HasDrawable ()) { MoonEGLSurface *surface = new MoonEGLSurface (box.width, box.height); Target *cairo = new Target (surface, box); target->SetCairoTarget (cairo); cairo->unref (); surface->unref (); } else { // mark target contents as initialized target->SetInit (ms); } ms->unref (); } return Context::Push (extents); }
void CombineArea(Vector<Rect>& area, const Rect& r) { LTIMING("CombineArea"); if(r.IsEmpty()) return; int ra = Area(r); for(int i = 0; i < area.GetCount(); i++) { Rect ur = r | area[i]; int a = Area(ur); if(a < 2 * (ra + Area(area[i])) || a < 16000) { area[i] = ur; return; } } area.Add(r); }
void SDraw::SysDrawImageOp(int x, int y, const Image& img, const Rect& src, Color color) { Rect sr(Point(x, y) + cloff.Top().offset, (src & img.GetSize()).GetSize()); const Vector<Rect>& clip = cloff.Top().clip; for(int i = 0; i < clip.GetCount(); i++) { Rect cr = clip[i] & sr; if(!cr.IsEmpty()) { Point p = cr.TopLeft(); Rect r(cr.TopLeft() - sr.TopLeft() + src.TopLeft(), cr.GetSize()); if(IsNull(color)) PutImage(p, img, r); else PutImage(p, img, r, color); } } }
/* For the purposes of the update/invalidation logic pretend to be a rectangle. */ bool SVGImageElement::GetGeometryBounds(Rect* aBounds, Float aStrokeWidth, CapStyle aCapStyle, const Matrix& aTransform) { Rect rect; GetAnimatedLengthValues(&rect.x, &rect.y, &rect.width, &rect.height, nullptr); if (rect.IsEmpty()) { // Rendering of the element disabled rect.SetEmpty(); // Make sure width/height are zero and not negative } *aBounds = aTransform.TransformBounds(rect); return true; }
Image GetRect_(const Image& orig, const Rect &r) { if(r.IsEmpty()) return Image(); ImageBuffer ib(r.GetSize()); for(int y = r.top; y < r.bottom; y++) { const RGBA *s = orig[y] + r.left; const RGBA *e = orig[y] + r.right; RGBA *t = ib[y - r.top]; while(s < e) { *t = *s; t++; s++; } } return ib; }
void DrawRectBASE(PixelBlock& w, int x, int y, int cx, int cy, Color c) { RTIMING("DrawRect"); Rect r = RectC(x, y, cx, cy); r.Intersect(w.GetSize()); if(r.IsEmpty()) return; dword color = c.GetRaw(); dword *a = w.PointAdr(r.left, r.top); int d = w.LineDelta(); cy = r.Height(); cx = r.Width(); while(cy--) { memsetd(a, color, cx); a += d; } }
/* For the purposes of the update/invalidation logic pretend to be a rectangle. */ bool SVGImageElement::GetGeometryBounds(Rect* aBounds, const StrokeOptions& aStrokeOptions, const Matrix& aToBoundsSpace, const Matrix* aToNonScalingStrokeSpace) { Rect rect; GetAnimatedLengthValues(&rect.x, &rect.y, &rect.width, &rect.height, nullptr); if (rect.IsEmpty()) { // Rendering of the element disabled rect.SetEmpty(); // Make sure width/height are zero and not negative } *aBounds = aToBoundsSpace.TransformBounds(rect); return true; }
void TexturedLayerMLGPU::AssignBigImage(FrameBuilder* aBuilder, RenderViewMLGPU* aView, BigImageIterator* aIter, const Maybe<Polygon>& aGeometry) { const Matrix4x4& transform = GetLayer()->GetEffectiveTransformForBuffer(); // Note that we don't need to assign these in any particular order, since // they do not overlap. do { IntRect tileRect = aIter->GetTileRect(); IntRect rect = tileRect.Intersect(mPictureRect); if (rect.IsEmpty()) { continue; } { Rect screenRect = transform.TransformBounds(Rect(rect)); screenRect.MoveBy(-aView->GetTargetOffset()); screenRect = screenRect.Intersect(Rect(mComputedClipRect.ToUnknownRect())); if (screenRect.IsEmpty()) { // This tile is not in the clip region, so skip it. continue; } } RefPtr<TextureSource> tile = mBigImageTexture->ExtractCurrentTile(); if (!tile) { continue; } // Create a temporary item. RefPtr<TempImageLayerMLGPU> item = new TempImageLayerMLGPU(aBuilder->GetManager()); item->Init(this, tile, rect); Maybe<Polygon> geometry = aGeometry; item->AddBoundsToView(aBuilder, aView, std::move(geometry)); // Since the layer tree is not holding this alive, we have to ask the // FrameBuilder to do it for us. aBuilder->RetainTemporaryLayer(item); } while (aIter->NextTile()); }
Rect Rect::Union(const Rect& rect) const { // 空矩形特殊处理. if(IsEmpty()) { return rect; } if(rect.IsEmpty()) { return *this; } int rx = std::min(x(), rect.x()); int ry = std::min(y(), rect.y()); int rr = std::max(right(), rect.right()); int rb = std::max(bottom(), rect.bottom()); return Rect(rx, ry, rr-rx, rb-ry); }
void Ctrl::RefreshFrame(const Rect& r) { GuiLock __; if(!IsOpen() || !IsVisible() || r.IsEmpty()) return; LTIMING("RefreshFrame"); LLOG("RefreshRect " << Name() << ' ' << r); if(GuiPlatformRefreshFrameSpecial(r)) return; if(!top) { if(InFrame()) parent->RefreshFrame(r + GetRect().TopLeft()); else parent->Refresh(r + GetRect().TopLeft()); } else { LLOG("WndInvalidateRect: " << r << ' ' << Name()); LTIMING("RefreshFrame InvalidateRect"); WndInvalidateRect(r); } }
void Ctrl::RefreshFrame(const Rect& r) { sCheckGuiLock(); GuiLock __; // Beware: Even if we have ThreadHasGuiLock ASSERT, we still can be the main thread! if(!IsOpen() || !IsVisible() || r.IsEmpty()) return; LTIMING("RefreshFrame"); LLOG("RefreshRect " << Name() << ' ' << r); if(GuiPlatformRefreshFrameSpecial(r)) return; if(!top) { if(InFrame()) parent->RefreshFrame(r + GetRect().TopLeft()); else parent->Refresh(r + GetRect().TopLeft()); } else { LLOG("WndInvalidateRect: " << r << ' ' << Name()); LTIMING("RefreshFrame InvalidateRect"); WndInvalidateRect(r); } }
int UtcDaliRectIsEmpty(void) { TestApplication application; Rect<int> ri; Rect<float> rf(10.0f, 20.0f, 400.0f, 200.0f); Rect<float> rf2; Rect<float> rf3(10.0f, 20.0f, 0.0f, 200.0f); Rect<float> rf4(10.0f, 20.0f, 400.0f, 0.0f); Rect<double> rd(10.0, 20.0, 0.0, 200.0); Rect<unsigned int> ru(0u, 0u, 4u, 0u); DALI_TEST_CHECK(!rf.IsEmpty()); DALI_TEST_CHECK(rf2.IsEmpty()); DALI_TEST_CHECK(rf3.IsEmpty()); DALI_TEST_CHECK(rf4.IsEmpty()); DALI_TEST_CHECK(ri.IsEmpty()); DALI_TEST_CHECK(rd.IsEmpty()); DALI_TEST_CHECK(ru.IsEmpty()); END_TEST; }