gfx/skia/trunk/src/gpu/GrGpu.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /*
michael@0 2 * Copyright 2011 Google Inc.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license that can be
michael@0 5 * found in the LICENSE file.
michael@0 6 */
michael@0 7
michael@0 8 #ifndef GrGpu_DEFINED
michael@0 9 #define GrGpu_DEFINED
michael@0 10
michael@0 11 #include "GrDrawTarget.h"
michael@0 12 #include "GrClipMaskManager.h"
michael@0 13 #include "SkPath.h"
michael@0 14
michael@0 15 class GrContext;
michael@0 16 class GrIndexBufferAllocPool;
michael@0 17 class GrPath;
michael@0 18 class GrPathRenderer;
michael@0 19 class GrPathRendererChain;
michael@0 20 class GrResource;
michael@0 21 class GrStencilBuffer;
michael@0 22 class GrVertexBufferAllocPool;
michael@0 23
michael@0 24 class GrGpu : public GrDrawTarget {
michael@0 25 public:
michael@0 26
michael@0 27 /**
michael@0 28 * Additional blend coefficients for dual source blending, not exposed
michael@0 29 * through GrPaint/GrContext.
michael@0 30 */
michael@0 31 enum ExtendedBlendCoeffs {
michael@0 32 // source 2 refers to second output color when
michael@0 33 // using dual source blending.
michael@0 34 kS2C_GrBlendCoeff = kPublicGrBlendCoeffCount,
michael@0 35 kIS2C_GrBlendCoeff,
michael@0 36 kS2A_GrBlendCoeff,
michael@0 37 kIS2A_GrBlendCoeff,
michael@0 38
michael@0 39 kTotalGrBlendCoeffCount
michael@0 40 };
michael@0 41
michael@0 42 /**
michael@0 43 * Create an instance of GrGpu that matches the specified backend. If the requested backend is
michael@0 44 * not supported (at compile-time or run-time) this returns NULL. The context will not be
michael@0 45 * fully constructed and should not be used by GrGpu until after this function returns.
michael@0 46 */
michael@0 47 static GrGpu* Create(GrBackend, GrBackendContext, GrContext* context);
michael@0 48
michael@0 49 ////////////////////////////////////////////////////////////////////////////
michael@0 50
michael@0 51 GrGpu(GrContext* context);
michael@0 52 virtual ~GrGpu();
michael@0 53
michael@0 54 GrContext* getContext() { return this->INHERITED::getContext(); }
michael@0 55 const GrContext* getContext() const { return this->INHERITED::getContext(); }
michael@0 56
michael@0 57 /**
michael@0 58 * The GrGpu object normally assumes that no outsider is setting state
michael@0 59 * within the underlying 3D API's context/device/whatever. This call informs
michael@0 60 * the GrGpu that the state was modified and it shouldn't make assumptions
michael@0 61 * about the state.
michael@0 62 */
michael@0 63 void markContextDirty(uint32_t state = kAll_GrBackendState) {
michael@0 64 fResetBits |= state;
michael@0 65 }
michael@0 66
michael@0 67 void unimpl(const char[]);
michael@0 68
michael@0 69 /**
michael@0 70 * Creates a texture object. If desc width or height is not a power of
michael@0 71 * two but underlying API requires a power of two texture then srcData
michael@0 72 * will be embedded in a power of two texture. The extra width and height
michael@0 73 * is filled as though srcData were rendered clamped into the texture.
michael@0 74 *
michael@0 75 * If kRenderTarget_TextureFlag is specified the GrRenderTarget is
michael@0 76 * accessible via GrTexture::asRenderTarget(). The texture will hold a ref
michael@0 77 * on the render target until the texture is destroyed.
michael@0 78 *
michael@0 79 * @param desc describes the texture to be created.
michael@0 80 * @param srcData texel data to load texture. Begins with full-size
michael@0 81 * palette data for paletted textures. Contains width*
michael@0 82 * height texels. If NULL texture data is uninitialized.
michael@0 83 *
michael@0 84 * @return The texture object if successful, otherwise NULL.
michael@0 85 */
michael@0 86 GrTexture* createTexture(const GrTextureDesc& desc,
michael@0 87 const void* srcData, size_t rowBytes);
michael@0 88
michael@0 89 /**
michael@0 90 * Implements GrContext::wrapBackendTexture
michael@0 91 */
michael@0 92 GrTexture* wrapBackendTexture(const GrBackendTextureDesc&);
michael@0 93
michael@0 94 /**
michael@0 95 * Implements GrContext::wrapBackendTexture
michael@0 96 */
michael@0 97 GrRenderTarget* wrapBackendRenderTarget(const GrBackendRenderTargetDesc&);
michael@0 98
michael@0 99 /**
michael@0 100 * Creates a vertex buffer.
michael@0 101 *
michael@0 102 * @param size size in bytes of the vertex buffer
michael@0 103 * @param dynamic hints whether the data will be frequently changed
michael@0 104 * by either GrVertexBuffer::lock or
michael@0 105 * GrVertexBuffer::updateData.
michael@0 106 *
michael@0 107 * @return The vertex buffer if successful, otherwise NULL.
michael@0 108 */
michael@0 109 GrVertexBuffer* createVertexBuffer(size_t size, bool dynamic);
michael@0 110
michael@0 111 /**
michael@0 112 * Creates an index buffer.
michael@0 113 *
michael@0 114 * @param size size in bytes of the index buffer
michael@0 115 * @param dynamic hints whether the data will be frequently changed
michael@0 116 * by either GrIndexBuffer::lock or
michael@0 117 * GrIndexBuffer::updateData.
michael@0 118 *
michael@0 119 * @return The index buffer if successful, otherwise NULL.
michael@0 120 */
michael@0 121 GrIndexBuffer* createIndexBuffer(size_t size, bool dynamic);
michael@0 122
michael@0 123 /**
michael@0 124 * Creates a path object that can be stenciled using stencilPath(). It is
michael@0 125 * only legal to call this if the caps report support for path stenciling.
michael@0 126 */
michael@0 127 GrPath* createPath(const SkPath& path, const SkStrokeRec& stroke);
michael@0 128
michael@0 129 /**
michael@0 130 * Returns an index buffer that can be used to render quads.
michael@0 131 * Six indices per quad: 0, 1, 2, 0, 2, 3, etc.
michael@0 132 * The max number of quads can be queried using GrIndexBuffer::maxQuads().
michael@0 133 * Draw with kTriangles_GrPrimitiveType
michael@0 134 * @ return the quad index buffer
michael@0 135 */
michael@0 136 const GrIndexBuffer* getQuadIndexBuffer() const;
michael@0 137
michael@0 138 /**
michael@0 139 * Resolves MSAA.
michael@0 140 */
michael@0 141 void resolveRenderTarget(GrRenderTarget* target);
michael@0 142
michael@0 143 /**
michael@0 144 * Ensures that the current render target is actually set in the
michael@0 145 * underlying 3D API. Used when client wants to use 3D API to directly
michael@0 146 * render to the RT.
michael@0 147 */
michael@0 148 void forceRenderTargetFlush();
michael@0 149
michael@0 150 /**
michael@0 151 * Gets a preferred 8888 config to use for writing/reading pixel data to/from a surface with
michael@0 152 * config surfaceConfig. The returned config must have at least as many bits per channel as the
michael@0 153 * readConfig or writeConfig param.
michael@0 154 */
michael@0 155 virtual GrPixelConfig preferredReadPixelsConfig(GrPixelConfig readConfig,
michael@0 156 GrPixelConfig surfaceConfig) const {
michael@0 157 return readConfig;
michael@0 158 }
michael@0 159 virtual GrPixelConfig preferredWritePixelsConfig(GrPixelConfig writeConfig,
michael@0 160 GrPixelConfig surfaceConfig) const {
michael@0 161 return writeConfig;
michael@0 162 }
michael@0 163
michael@0 164 /**
michael@0 165 * Called before uploading writing pixels to a GrTexture when the src pixel config doesn't
michael@0 166 * match the texture's config.
michael@0 167 */
michael@0 168 virtual bool canWriteTexturePixels(const GrTexture*, GrPixelConfig srcConfig) const = 0;
michael@0 169
michael@0 170 /**
michael@0 171 * OpenGL's readPixels returns the result bottom-to-top while the skia
michael@0 172 * API is top-to-bottom. Thus we have to do a y-axis flip. The obvious
michael@0 173 * solution is to have the subclass do the flip using either the CPU or GPU.
michael@0 174 * However, the caller (GrContext) may have transformations to apply and can
michael@0 175 * simply fold in the y-flip for free. On the other hand, the subclass may
michael@0 176 * be able to do it for free itself. For example, the subclass may have to
michael@0 177 * do memcpys to handle rowBytes that aren't tight. It could do the y-flip
michael@0 178 * concurrently.
michael@0 179 *
michael@0 180 * This function returns true if a y-flip is required to put the pixels in
michael@0 181 * top-to-bottom order and the subclass cannot do it for free.
michael@0 182 *
michael@0 183 * See read pixels for the params
michael@0 184 * @return true if calling readPixels with the same set of params will
michael@0 185 * produce bottom-to-top data
michael@0 186 */
michael@0 187 virtual bool readPixelsWillPayForYFlip(GrRenderTarget* renderTarget,
michael@0 188 int left, int top,
michael@0 189 int width, int height,
michael@0 190 GrPixelConfig config,
michael@0 191 size_t rowBytes) const = 0;
michael@0 192 /**
michael@0 193 * This should return true if reading a NxM rectangle of pixels from a
michael@0 194 * render target is faster if the target has dimensons N and M and the read
michael@0 195 * rectangle has its top-left at 0,0.
michael@0 196 */
michael@0 197 virtual bool fullReadPixelsIsFasterThanPartial() const { return false; };
michael@0 198
michael@0 199 /**
michael@0 200 * Reads a rectangle of pixels from a render target.
michael@0 201 *
michael@0 202 * @param renderTarget the render target to read from. NULL means the
michael@0 203 * current render target.
michael@0 204 * @param left left edge of the rectangle to read (inclusive)
michael@0 205 * @param top top edge of the rectangle to read (inclusive)
michael@0 206 * @param width width of rectangle to read in pixels.
michael@0 207 * @param height height of rectangle to read in pixels.
michael@0 208 * @param config the pixel config of the destination buffer
michael@0 209 * @param buffer memory to read the rectangle into.
michael@0 210 * @param rowBytes the number of bytes between consecutive rows. Zero
michael@0 211 * means rows are tightly packed.
michael@0 212 * @param invertY buffer should be populated bottom-to-top as opposed
michael@0 213 * to top-to-bottom (skia's usual order)
michael@0 214 *
michael@0 215 * @return true if the read succeeded, false if not. The read can fail
michael@0 216 * because of a unsupported pixel config or because no render
michael@0 217 * target is currently set.
michael@0 218 */
michael@0 219 bool readPixels(GrRenderTarget* renderTarget,
michael@0 220 int left, int top, int width, int height,
michael@0 221 GrPixelConfig config, void* buffer, size_t rowBytes);
michael@0 222
michael@0 223 /**
michael@0 224 * Updates the pixels in a rectangle of a texture.
michael@0 225 *
michael@0 226 * @param left left edge of the rectangle to write (inclusive)
michael@0 227 * @param top top edge of the rectangle to write (inclusive)
michael@0 228 * @param width width of rectangle to write in pixels.
michael@0 229 * @param height height of rectangle to write in pixels.
michael@0 230 * @param config the pixel config of the source buffer
michael@0 231 * @param buffer memory to read pixels from
michael@0 232 * @param rowBytes number of bytes between consecutive rows. Zero
michael@0 233 * means rows are tightly packed.
michael@0 234 */
michael@0 235 bool writeTexturePixels(GrTexture* texture,
michael@0 236 int left, int top, int width, int height,
michael@0 237 GrPixelConfig config, const void* buffer,
michael@0 238 size_t rowBytes);
michael@0 239
michael@0 240 /**
michael@0 241 * Called to tell Gpu object that all GrResources have been lost and should
michael@0 242 * be abandoned. Overrides must call INHERITED::abandonResources().
michael@0 243 */
michael@0 244 virtual void abandonResources();
michael@0 245
michael@0 246 /**
michael@0 247 * Called to tell Gpu object to release all GrResources. Overrides must call
michael@0 248 * INHERITED::releaseResources().
michael@0 249 */
michael@0 250 void releaseResources();
michael@0 251
michael@0 252 /**
michael@0 253 * Add resource to list of resources. Should only be called by GrResource.
michael@0 254 * @param resource the resource to add.
michael@0 255 */
michael@0 256 void insertResource(GrResource* resource);
michael@0 257
michael@0 258 /**
michael@0 259 * Remove resource from list of resources. Should only be called by
michael@0 260 * GrResource.
michael@0 261 * @param resource the resource to remove.
michael@0 262 */
michael@0 263 void removeResource(GrResource* resource);
michael@0 264
michael@0 265 // GrDrawTarget overrides
michael@0 266 virtual void clear(const SkIRect* rect,
michael@0 267 GrColor color,
michael@0 268 bool canIgnoreRect,
michael@0 269 GrRenderTarget* renderTarget = NULL) SK_OVERRIDE;
michael@0 270
michael@0 271 virtual void purgeResources() SK_OVERRIDE {
michael@0 272 // The clip mask manager can rebuild all its clip masks so just
michael@0 273 // get rid of them all.
michael@0 274 fClipMaskManager.releaseResources();
michael@0 275 }
michael@0 276
michael@0 277 // After the client interacts directly with the 3D context state the GrGpu
michael@0 278 // must resync its internal state and assumptions about 3D context state.
michael@0 279 // Each time this occurs the GrGpu bumps a timestamp.
michael@0 280 // state of the 3D context
michael@0 281 // At 10 resets / frame and 60fps a 64bit timestamp will overflow in about
michael@0 282 // a billion years.
michael@0 283 typedef uint64_t ResetTimestamp;
michael@0 284
michael@0 285 // This timestamp is always older than the current timestamp
michael@0 286 static const ResetTimestamp kExpiredTimestamp = 0;
michael@0 287 // Returns a timestamp based on the number of times the context was reset.
michael@0 288 // This timestamp can be used to lazily detect when cached 3D context state
michael@0 289 // is dirty.
michael@0 290 ResetTimestamp getResetTimestamp() const {
michael@0 291 return fResetTimestamp;
michael@0 292 }
michael@0 293
michael@0 294 /**
michael@0 295 * These methods are called by the clip manager's setupClipping function
michael@0 296 * which (called as part of GrGpu's implementation of onDraw and
michael@0 297 * onStencilPath member functions.) The GrGpu subclass should flush the
michael@0 298 * stencil state to the 3D API in its implementation of flushGraphicsState.
michael@0 299 */
michael@0 300 void enableScissor(const SkIRect& rect) {
michael@0 301 fScissorState.fEnabled = true;
michael@0 302 fScissorState.fRect = rect;
michael@0 303 }
michael@0 304 void disableScissor() { fScissorState.fEnabled = false; }
michael@0 305
michael@0 306 /**
michael@0 307 * Like the scissor methods above this is called by setupClipping and
michael@0 308 * should be flushed by the GrGpu subclass in flushGraphicsState. These
michael@0 309 * stencil settings should be used in place of those on the GrDrawState.
michael@0 310 * They have been adjusted to account for any interactions between the
michael@0 311 * GrDrawState's stencil settings and stencil clipping.
michael@0 312 */
michael@0 313 void setStencilSettings(const GrStencilSettings& settings) {
michael@0 314 fStencilSettings = settings;
michael@0 315 }
michael@0 316 void disableStencil() { fStencilSettings.setDisabled(); }
michael@0 317
michael@0 318 // GrGpu subclass sets clip bit in the stencil buffer. The subclass is
michael@0 319 // free to clear the remaining bits to zero if masked clears are more
michael@0 320 // expensive than clearing all bits.
michael@0 321 virtual void clearStencilClip(const SkIRect& rect, bool insideClip) = 0;
michael@0 322
michael@0 323 enum PrivateDrawStateStateBits {
michael@0 324 kFirstBit = (GrDrawState::kLastPublicStateBit << 1),
michael@0 325
michael@0 326 kModifyStencilClip_StateBit = kFirstBit, // allows draws to modify
michael@0 327 // stencil bits used for
michael@0 328 // clipping.
michael@0 329 };
michael@0 330
michael@0 331 void getPathStencilSettingsForFillType(SkPath::FillType fill, GrStencilSettings* outStencilSettings);
michael@0 332
michael@0 333 protected:
michael@0 334 enum DrawType {
michael@0 335 kDrawPoints_DrawType,
michael@0 336 kDrawLines_DrawType,
michael@0 337 kDrawTriangles_DrawType,
michael@0 338 kStencilPath_DrawType,
michael@0 339 kDrawPath_DrawType,
michael@0 340 };
michael@0 341
michael@0 342 DrawType PrimTypeToDrawType(GrPrimitiveType type) {
michael@0 343 switch (type) {
michael@0 344 case kTriangles_GrPrimitiveType:
michael@0 345 case kTriangleStrip_GrPrimitiveType:
michael@0 346 case kTriangleFan_GrPrimitiveType:
michael@0 347 return kDrawTriangles_DrawType;
michael@0 348 case kPoints_GrPrimitiveType:
michael@0 349 return kDrawPoints_DrawType;
michael@0 350 case kLines_GrPrimitiveType:
michael@0 351 case kLineStrip_GrPrimitiveType:
michael@0 352 return kDrawLines_DrawType;
michael@0 353 default:
michael@0 354 GrCrash("Unexpected primitive type");
michael@0 355 return kDrawTriangles_DrawType;
michael@0 356 }
michael@0 357 }
michael@0 358
michael@0 359 // prepares clip flushes gpu state before a draw
michael@0 360 bool setupClipAndFlushState(DrawType,
michael@0 361 const GrDeviceCoordTexture* dstCopy,
michael@0 362 GrDrawState::AutoRestoreEffects* are,
michael@0 363 const SkRect* devBounds);
michael@0 364
michael@0 365 // Functions used to map clip-respecting stencil tests into normal
michael@0 366 // stencil funcs supported by GPUs.
michael@0 367 static GrStencilFunc ConvertStencilFunc(bool stencilInClip,
michael@0 368 GrStencilFunc func);
michael@0 369 static void ConvertStencilFuncAndMask(GrStencilFunc func,
michael@0 370 bool clipInStencil,
michael@0 371 unsigned int clipBit,
michael@0 372 unsigned int userBits,
michael@0 373 unsigned int* ref,
michael@0 374 unsigned int* mask);
michael@0 375
michael@0 376 GrClipMaskManager fClipMaskManager;
michael@0 377
michael@0 378 struct GeometryPoolState {
michael@0 379 const GrVertexBuffer* fPoolVertexBuffer;
michael@0 380 int fPoolStartVertex;
michael@0 381
michael@0 382 const GrIndexBuffer* fPoolIndexBuffer;
michael@0 383 int fPoolStartIndex;
michael@0 384 };
michael@0 385 const GeometryPoolState& getGeomPoolState() {
michael@0 386 return fGeomPoolStateStack.back();
michael@0 387 }
michael@0 388
michael@0 389 // The state of the scissor is controlled by the clip manager
michael@0 390 struct ScissorState {
michael@0 391 bool fEnabled;
michael@0 392 SkIRect fRect;
michael@0 393 } fScissorState;
michael@0 394
michael@0 395 // The final stencil settings to use as determined by the clip manager.
michael@0 396 GrStencilSettings fStencilSettings;
michael@0 397
michael@0 398 // Helpers for setting up geometry state
michael@0 399 void finalizeReservedVertices();
michael@0 400 void finalizeReservedIndices();
michael@0 401
michael@0 402 private:
michael@0 403 // GrDrawTarget overrides
michael@0 404 virtual bool onReserveVertexSpace(size_t vertexSize, int vertexCount, void** vertices) SK_OVERRIDE;
michael@0 405 virtual bool onReserveIndexSpace(int indexCount, void** indices) SK_OVERRIDE;
michael@0 406 virtual void releaseReservedVertexSpace() SK_OVERRIDE;
michael@0 407 virtual void releaseReservedIndexSpace() SK_OVERRIDE;
michael@0 408 virtual void onSetVertexSourceToArray(const void* vertexArray, int vertexCount) SK_OVERRIDE;
michael@0 409 virtual void onSetIndexSourceToArray(const void* indexArray, int indexCount) SK_OVERRIDE;
michael@0 410 virtual void releaseVertexArray() SK_OVERRIDE;
michael@0 411 virtual void releaseIndexArray() SK_OVERRIDE;
michael@0 412 virtual void geometrySourceWillPush() SK_OVERRIDE;
michael@0 413 virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) SK_OVERRIDE;
michael@0 414
michael@0 415
michael@0 416 // called when the 3D context state is unknown. Subclass should emit any
michael@0 417 // assumed 3D context state and dirty any state cache.
michael@0 418 virtual void onResetContext(uint32_t resetBits) = 0;
michael@0 419
michael@0 420 // overridden by backend-specific derived class to create objects.
michael@0 421 virtual GrTexture* onCreateTexture(const GrTextureDesc& desc,
michael@0 422 const void* srcData,
michael@0 423 size_t rowBytes) = 0;
michael@0 424 virtual GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&) = 0;
michael@0 425 virtual GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&) = 0;
michael@0 426 virtual GrVertexBuffer* onCreateVertexBuffer(size_t size, bool dynamic) = 0;
michael@0 427 virtual GrIndexBuffer* onCreateIndexBuffer(size_t size, bool dynamic) = 0;
michael@0 428 virtual GrPath* onCreatePath(const SkPath& path, const SkStrokeRec&) = 0;
michael@0 429
michael@0 430 // overridden by backend-specific derived class to perform the clear and
michael@0 431 // clearRect. NULL rect means clear whole target. If canIgnoreRect is
michael@0 432 // true, it is okay to perform a full clear instead of a partial clear
michael@0 433 virtual void onClear(const SkIRect* rect, GrColor color, bool canIgnoreRect) = 0;
michael@0 434
michael@0 435 // overridden by backend-specific derived class to perform the draw call.
michael@0 436 virtual void onGpuDraw(const DrawInfo&) = 0;
michael@0 437
michael@0 438 // overridden by backend-specific derived class to perform the path stenciling.
michael@0 439 virtual void onGpuStencilPath(const GrPath*, SkPath::FillType) = 0;
michael@0 440 virtual void onGpuDrawPath(const GrPath*, SkPath::FillType) = 0;
michael@0 441
michael@0 442 // overridden by backend-specific derived class to perform flush
michael@0 443 virtual void onForceRenderTargetFlush() = 0;
michael@0 444
michael@0 445 // overridden by backend-specific derived class to perform the read pixels.
michael@0 446 virtual bool onReadPixels(GrRenderTarget* target,
michael@0 447 int left, int top, int width, int height,
michael@0 448 GrPixelConfig,
michael@0 449 void* buffer,
michael@0 450 size_t rowBytes) = 0;
michael@0 451
michael@0 452 // overridden by backend-specific derived class to perform the texture update
michael@0 453 virtual bool onWriteTexturePixels(GrTexture* texture,
michael@0 454 int left, int top, int width, int height,
michael@0 455 GrPixelConfig config, const void* buffer,
michael@0 456 size_t rowBytes) = 0;
michael@0 457
michael@0 458 // overridden by backend-specific derived class to perform the resolve
michael@0 459 virtual void onResolveRenderTarget(GrRenderTarget* target) = 0;
michael@0 460
michael@0 461 // width and height may be larger than rt (if underlying API allows it).
michael@0 462 // Should attach the SB to the RT. Returns false if compatible sb could
michael@0 463 // not be created.
michael@0 464 virtual bool createStencilBufferForRenderTarget(GrRenderTarget*, int width, int height) = 0;
michael@0 465
michael@0 466 // attaches an existing SB to an existing RT.
michael@0 467 virtual bool attachStencilBufferToRenderTarget(GrStencilBuffer*, GrRenderTarget*) = 0;
michael@0 468
michael@0 469 // The GrGpu typically records the clients requested state and then flushes
michael@0 470 // deltas from previous state at draw time. This function does the
michael@0 471 // backend-specific flush of the state.
michael@0 472 // returns false if current state is unsupported.
michael@0 473 virtual bool flushGraphicsState(DrawType, const GrDeviceCoordTexture* dstCopy) = 0;
michael@0 474
michael@0 475 // clears the entire stencil buffer to 0
michael@0 476 virtual void clearStencil() = 0;
michael@0 477
michael@0 478 // Given a rt, find or create a stencil buffer and attach it
michael@0 479 bool attachStencilBufferToRenderTarget(GrRenderTarget* target);
michael@0 480
michael@0 481 // GrDrawTarget overrides
michael@0 482 virtual void onDraw(const DrawInfo&) SK_OVERRIDE;
michael@0 483 virtual void onStencilPath(const GrPath*, SkPath::FillType) SK_OVERRIDE;
michael@0 484 virtual void onDrawPath(const GrPath*, SkPath::FillType,
michael@0 485 const GrDeviceCoordTexture* dstCopy) SK_OVERRIDE;
michael@0 486
michael@0 487 // readies the pools to provide vertex/index data.
michael@0 488 void prepareVertexPool();
michael@0 489 void prepareIndexPool();
michael@0 490
michael@0 491 void resetContext() {
michael@0 492 // We call this because the client may have messed with the
michael@0 493 // stencil buffer. Perhaps we should detect whether it is a
michael@0 494 // internally created stencil buffer and if so skip the invalidate.
michael@0 495 fClipMaskManager.invalidateStencilMask();
michael@0 496 this->onResetContext(fResetBits);
michael@0 497 fResetBits = 0;
michael@0 498 ++fResetTimestamp;
michael@0 499 }
michael@0 500
michael@0 501 void handleDirtyContext() {
michael@0 502 if (fResetBits) {
michael@0 503 this->resetContext();
michael@0 504 }
michael@0 505 }
michael@0 506
michael@0 507 enum {
michael@0 508 kPreallocGeomPoolStateStackCnt = 4,
michael@0 509 };
michael@0 510 typedef SkTInternalLList<GrResource> ResourceList;
michael@0 511 SkSTArray<kPreallocGeomPoolStateStackCnt, GeometryPoolState, true> fGeomPoolStateStack;
michael@0 512 ResetTimestamp fResetTimestamp;
michael@0 513 uint32_t fResetBits;
michael@0 514 GrVertexBufferAllocPool* fVertexPool;
michael@0 515 GrIndexBufferAllocPool* fIndexPool;
michael@0 516 // counts number of uses of vertex/index pool in the geometry stack
michael@0 517 int fVertexPoolUseCnt;
michael@0 518 int fIndexPoolUseCnt;
michael@0 519 // these are mutable so they can be created on-demand
michael@0 520 mutable GrIndexBuffer* fQuadIndexBuffer;
michael@0 521 // Used to abandon/release all resources created by this GrGpu. TODO: Move this
michael@0 522 // functionality to GrResourceCache.
michael@0 523 ResourceList fResourceList;
michael@0 524
michael@0 525 typedef GrDrawTarget INHERITED;
michael@0 526 };
michael@0 527
michael@0 528 #endif

mercurial