Skia
Created at 2017-05-14T18:07:20+09:00

SampleApp

[ Data structure ]
SkOSWindow < SkWindow < SkView < SkEventSink
'-' SkUnixWindow (holding X stuff e.g. Display, GLXContext)
 - (as SkWindow)
  '-' SkSurfaceProps
  '-' SkBitmap
 - (as SkView)
  '-' draw

GMSampleView < SampleView < SkView
'-' AnalyticAntiAliasConvexGM < skiagm::GM

SkSurface_Base < SkSurface
- SkCanvas

(TODO: GL context (DRI setup?))
GrContext
GrGLContext
GrGLInterface
GrGpu
GrGLGpu


[ Main ]
- main =>
  - SkGraphics::Init =>
    - ... read_cpu_features and Init_sse4 for example
  - create_sk_window => new SampleWindow =>
    - SkWindow::SkWindow => a bunch of init ...
    - SkOSWindow::SkOSWindow =>
      - SkOSWindow::initWindow => X client routine
      - SkOSWindow::resize =>
        - SkBitmap::allocPixels
        - SkView::inval
        - SkView::setSize
    - SampleWindow::SampleWindow =>
      - SkGMRegistyToSampleRegistry =>
        - skiagm::GMRegistry::Head
          (loop through the list of kiagm::GM created via DEF_GM,
           e.g. DEF_GM( return new AnalyticAntiAliasConvexGM; ))
        - new SkViewRegister => new SkGMSampleViewFactory
      - fTypeface = SkTypeface::MakeFromName("Courier", ..)
      - keyboard shortcut setup (e.g. appendList(... "Raster", "OpenGL" ...)
      - SkView::setVisibleP, setClipToBounds
      - (*fSamples[fCurrIndex])() =>
        - SkGMSampleViewFactory::operator() =>
          - (initialize first skiagm::GM in this case new AnalyticAntiAliasConvexGM)
          - new GMSampleView
      - loadView =>
        - attachChildToFront
        - setSize
      - new DefaultDeviceManager
      - DefaultDeviceManager::setUpBackend =>
        - SkOSWindow::attach(kNativeGL_BackEndType, ..) => glx context setup
        - GrGLCreateNativeInterface
        - GrContext::Create => new GrContext, init =>
          - GrGpu::Create => GrGLGpu::Create =>
            - GrGLContext::Create => new GrGLContext
            - new GrGLGpu
          - initCommon =>
            - new GrDrawingManager, GrAtlasGlyphCache, GrTextBlobCache
        - windowSizeChanged => SkWindow::makeGpuBackedSurface =>
          - GrBackendRenderTarget
          - SkSurface::MakeFromBackendRenderTarget =>
            - GrContextPriv::MakeFromBackendRenderTargetRenderTargetContext =>
              - GrDrawingManager::makeRenderTargetContext => new GrRenderTargetContext
            - SkGpuDevice::Make => new SkGpuDevice
  - SkOSWindow::loop => for(;;)
    - nextXEvent => MyXNextEventWithDelay => XNextEvent
      - handleClick or handleKey ...
    - SkWindow::update =>
      - makeSurface => SkSurface::MakeRasterDirect
      - SkCanvas* canvas = SkSurface::getCanvas
      - SkCanvas::clipRegion(fDirtyRgn)
      - SampleWindow::draw(<SkCanvas>) =>
        - (kNo_Tiling == fTilingMode)
          - SkView::draw (as this->INHERITED::draw) =>
            - (as child->draw) SkView::draw => SampleView::onDraw =>
              - GMSampleView::onDrawContent => skiagm::GM::drawContent =>
                - AnalyticAntiAliasConvexGM::onDraw => ...
        - SkCanvas::flush =>
        - DefaultDeviceManager::publishCanvas(renderingCanvas ..) =>
          - (assume kRaster_DeviceType)
            - auto data = SkData::MakeUninitialized
            - renderingCanvas->readPixels(.. data->writable_data() ..) =>
              - SkBaseDevice::readPixels => SkBitmapDevice::onReadPixels =>
                - SkBitmap::readPixels => SkPixmap::readPixels =>
                  - SkConvertPixels => memcpy
            - auto offscreenImage = SkImage::MakeRasterData( .. data .. )
            - gpuCanvas->drawImage => ...
          - SkOSWindow::present => glxSwapBuffers
    - doPaint =>
      - (for non glx case)
        - convertBitmapToXImage => XInitImage from SkBitmap
        - XPutImage

Rendering (kRaster_DeviceType)

[ Data structure ]
SkCanvas
'-' MCRec
  '-' DeviceCM (fTopLayer)
    '-' SkBaseDevice (> SkBitmapDevice, SkGpuDevice or etc..)

SkBitmapDevice (< SkBaseDevice)
'-' SkMatrix
'-' SkBitmap
'-' SkRasterClipStack

SkDraw (> BDDraw)
'-' SkMatrix
'-' SkRasterClip
'-' SkPixmap
  '-' void *fPixels
  '-' SkColorTable
  '-' SkImageInfo

SkPath
'-' SkPathRef
  '-' SkPoint* fPoints
  '-' uint8_t* fVerbs

SkPaint
'-' SkTypeface
'-' SkShader
'-' SkMaskFilter
'-' SkPathEffect

DrawOneGlyph
'-' SkGlyphCache
'-' SkBlitter

SkGlyph
'-' void* fImage
'-' fAdvanceX, fAdvanceY, fWidth, fHeight, fTop, fLeft


[ Fixed shape ]
- SkCanvas::drawRect => onDrawRect =>
  - SkBitmapDevice::drawRect =>
    - SkBitmapDevice::BDDraw::drawRect (i.e. SkDraw::drawRect) =>
      - (for simply kPath_RectType)
        - SkDraw draw, SkPath tmp (on stack)
        - SkPath::addRect =>
          - kVerbs = 5 (i.e. moveTo + 3x lineTo + close)
          - incReserve(kVerbs) => SkPathRef::Editor
          - RectPointIterator
          - moveTo =>
            - SkPathRef::Editor::growForVerb(kMove_Verb) =>
              - SkPathRef::growForVerb
          - 3x lineTo => ...
          - close => ...
        - SkPath::setFillType(kWinding_FillType)
        - draw.drawPath(tmp ...) => (SEE BELOW)


[ Text ]
(GM:typefacestyles)
- SkDraw::drawText =>
  - SkAutoGlyphCache cache
  - SkAutoBlitterChoose blitterChooser
  - SkAAClipBlitterWrapper wrapper
  - DrawOneGlyph drawOneGlyph
  - SkFindAndPlaceGlyph::ProcessText =>
    - LookupGlyph glyphFinder
    - GlyphFindAndPlace<ProcessOneGlyph> findAndPosition
    - findAndPosition->findAndPositionGlyph (i.e. GlyphFindAndPlaceFullPixel::findAndPositionGlyph) =>
      - SkGlyph& glyph = UtfNGlyphFinder::lookupGlyph(text) =>
        - SkUnichar unichar = nextUnichar(text)
        - SkGlyphCache::lookupByChar(unichar) => ...
      - SkAutoKern::adjust
      - TextAlignmentAdjustment =>
      - processOneGlyph (i.e. DrawOneGlyph::operator()) =>
        - getImageData => SkGlyphCache::findImage =>
          - SkScalerContext::getImage => FreeType::generateImage =>
            - FT_Load_Glyph => ...
            - SkScalerContext_FreeType_Base::generateGlyphImage =>
              - FT_Outline_Get_Bitmap => ...
        - blitMask => SkARGB32_Opaque_Blitter::blitMask => (SEE BELOW)


[ Paint ]
- SkDraw::drawPaint => ...


[ Path ]
- SkDraw::drawPath => drawDevPath =>
  - SkScan::AntiHairPath => hair_path(... SkScan::AntiHairLineRgn) =>
    - SkPath::RawIter iter(path)
    - while ((verb = iter.next(pts)) != SkPath::kDone_Verb)
      - (for example, case SkPath::kCubic_Verb)
        - haircubic => hair_cubic =>
          - int lines = compute_cubic_segs(pts) => ...
          - for (int i = 1; i < lines; ++i) { t = t + dt, (((A * t + B) * t + C) * t + D) ... }
          - lineproc (i.e. SkScan::AntiHairLineRgn) =>
            - for i < arrayCount
              - do_anti_hairline =>
                - SkAntiHairBlitter::drawLine =>
                  - some-blitter::blitXXX => ...


[ Paint effects ]
(SkMaskFilter)
(SkShader)
(SkPathEffect)


[ Blitting ]

Chromium (Blink)

  • GPU process
    • platform GL backend ?
    • igalia's wayland backend fork ?
  • Renderer (Blink)
    • SkPicture backend ?
    • impl thread paint

Reference

TODO (as different post)

  • text shaper (Harfbuzz integration ?)
    • start from drawKernText in typeface.cpp
  • glyph rasterization (freetype ?)
  • usage on android
  • vulkan backend