GrGpu.h revision e699d0cd25fd059e3f0c4949e613e50c83a52179
1/* 2 * Copyright 2011 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8#ifndef GrGpu_DEFINED 9#define GrGpu_DEFINED 10 11#include "GrPipelineBuilder.h" 12#include "GrProgramDesc.h" 13#include "GrStencil.h" 14#include "GrSwizzle.h" 15#include "GrAllocator.h" 16#include "GrTextureParamsAdjuster.h" 17#include "GrTypes.h" 18#include "GrXferProcessor.h" 19#include "SkPath.h" 20#include "SkTArray.h" 21 22class GrBatchTracker; 23class GrContext; 24class GrGLContext; 25class GrIndexBuffer; 26class GrNonInstancedVertices; 27class GrPath; 28class GrPathRange; 29class GrPathRenderer; 30class GrPathRendererChain; 31class GrPathRendering; 32class GrPipeline; 33class GrPrimitiveProcessor; 34class GrRenderTarget; 35class GrStencilAttachment; 36class GrSurface; 37class GrTexture; 38class GrTransferBuffer; 39class GrVertexBuffer; 40class GrVertices; 41 42class GrGpu : public SkRefCnt { 43public: 44 /** 45 * Create an instance of GrGpu that matches the specified backend. If the requested backend is 46 * not supported (at compile-time or run-time) this returns nullptr. The context will not be 47 * fully constructed and should not be used by GrGpu until after this function returns. 48 */ 49 static GrGpu* Create(GrBackend, GrBackendContext, const GrContextOptions&, GrContext* context); 50 51 //////////////////////////////////////////////////////////////////////////// 52 53 GrGpu(GrContext* context); 54 ~GrGpu() override; 55 56 GrContext* getContext() { return fContext; } 57 const GrContext* getContext() const { return fContext; } 58 59 /** 60 * Gets the capabilities of the draw target. 61 */ 62 const GrCaps* caps() const { return fCaps.get(); } 63 64 GrPathRendering* pathRendering() { return fPathRendering.get(); } 65 66 // Called by GrContext when the underlying backend context has been destroyed. 67 // GrGpu should use this to ensure that no backend API calls will be made from 68 // here onward, including in its destructor. Subclasses should call 69 // INHERITED::contextAbandoned() if they override this. 70 virtual void contextAbandoned(); 71 72 /** 73 * The GrGpu object normally assumes that no outsider is setting state 74 * within the underlying 3D API's context/device/whatever. This call informs 75 * the GrGpu that the state was modified and it shouldn't make assumptions 76 * about the state. 77 */ 78 void markContextDirty(uint32_t state = kAll_GrBackendState) { fResetBits |= state; } 79 80 /** 81 * Creates a texture object. If kRenderTarget_GrSurfaceFlag the texture can 82 * be used as a render target by calling GrTexture::asRenderTarget(). Not all 83 * pixel configs can be used as render targets. Support for configs as textures 84 * or render targets can be checked using GrCaps. 85 * 86 * @param desc describes the texture to be created. 87 * @param budgeted does this texture count against the resource cache budget? 88 * @param texels array of mipmap levels containing texel data to load. 89 * Each level begins with full-size palette data for paletted textures. 90 * For compressed formats the level contains the compressed pixel data. 91 * Otherwise, it contains width*height texels. If there is only one 92 * element and it contains nullptr fPixels, texture data is 93 * uninitialized. 94 * @return The texture object if successful, otherwise nullptr. 95 */ 96 GrTexture* createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted, 97 const SkTArray<GrMipLevel>& texels); 98 99 /** 100 * Simplified createTexture() interface for when there is no initial texel data to upload. 101 */ 102 GrTexture* createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted) { 103 return this->createTexture(desc, budgeted, SkTArray<GrMipLevel>()); 104 } 105 106 /** Simplified createTexture() interface for when there is only a base level */ 107 GrTexture* createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted, const void* level0Data, 108 size_t rowBytes) { 109 SkASSERT(level0Data); 110 GrMipLevel level = { level0Data, rowBytes }; 111 SkSTArray<1, GrMipLevel> array; 112 array.push_back() = level; 113 return this->createTexture(desc, budgeted, array); 114 } 115 116 /** 117 * Implements GrTextureProvider::wrapBackendTexture 118 */ 119 GrTexture* wrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership); 120 121 /** 122 * Implements GrTextureProvider::wrapBackendRenderTarget 123 */ 124 GrRenderTarget* wrapBackendRenderTarget(const GrBackendRenderTargetDesc&, GrWrapOwnership); 125 126 /** 127 * Implements GrTextureProvider::wrapBackendTextureAsRenderTarget 128 */ 129 GrRenderTarget* wrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&, GrWrapOwnership); 130 131 /** 132 * Creates a vertex buffer. 133 * 134 * @param size size in bytes of the vertex buffer 135 * @param dynamic hints whether the data will be frequently changed 136 * by either GrVertexBuffer::map() or 137 * GrVertexBuffer::updateData(). 138 * 139 * @return The vertex buffer if successful, otherwise nullptr. 140 */ 141 GrVertexBuffer* createVertexBuffer(size_t size, bool dynamic); 142 143 /** 144 * Creates an index buffer. 145 * 146 * @param size size in bytes of the index buffer 147 * @param dynamic hints whether the data will be frequently changed 148 * by either GrIndexBuffer::map() or 149 * GrIndexBuffer::updateData(). 150 * 151 * @return The index buffer if successful, otherwise nullptr. 152 */ 153 GrIndexBuffer* createIndexBuffer(size_t size, bool dynamic); 154 155 /** 156 * Creates a transfer buffer. 157 * 158 * @param size size in bytes of the index buffer 159 * @param toGpu true if used to transfer from the cpu to the gpu 160 * otherwise to be used to transfer from the gpu to the cpu 161 * 162 * @return The transfer buffer if successful, otherwise nullptr. 163 */ 164 GrTransferBuffer* createTransferBuffer(size_t size, TransferType type); 165 166 /** 167 * Resolves MSAA. 168 */ 169 void resolveRenderTarget(GrRenderTarget* target); 170 171 /** Info struct returned by getReadPixelsInfo about performing intermediate draws before 172 reading pixels for performance or correctness. */ 173 struct ReadPixelTempDrawInfo { 174 /** If the GrGpu is requesting that the caller do a draw to an intermediate surface then 175 this is descriptor for the temp surface. The draw should always be a rect with 176 dst 0,0,w,h. */ 177 GrSurfaceDesc fTempSurfaceDesc; 178 /** Indicates whether there is a performance advantage to using an exact match texture 179 (in terms of width and height) for the intermediate texture instead of approximate. */ 180 bool fUseExactScratch; 181 /** Swizzle to apply during the draw. This is used to compensate for either feature or 182 performance limitations in the underlying 3D API. */ 183 GrSwizzle fSwizzle; 184 /** The config that should be used to read from the temp surface after the draw. This may be 185 different than the original read config in order to compensate for swizzling. The 186 read data will effectively be in the original read config. */ 187 GrPixelConfig fReadConfig; 188 }; 189 190 /** Describes why an intermediate draw must/should be performed before readPixels. */ 191 enum DrawPreference { 192 /** On input means that the caller would proceed without draw if the GrGpu doesn't request 193 one. 194 On output means that the GrGpu is not requesting a draw. */ 195 kNoDraw_DrawPreference, 196 /** Means that the client would prefer a draw for performance of the readback but 197 can satisfy a straight readPixels call on the inputs without an intermediate draw. 198 getReadPixelsInfo will never set the draw preference to this value but may leave 199 it set. */ 200 kCallerPrefersDraw_DrawPreference, 201 /** On output means that GrGpu would prefer a draw for performance of the readback but 202 can satisfy a straight readPixels call on the inputs without an intermediate draw. The 203 caller of getReadPixelsInfo should never specify this on intput. */ 204 kGpuPrefersDraw_DrawPreference, 205 /** On input means that the caller requires a draw to do a transformation and there is no 206 CPU fallback. 207 On output means that GrGpu can only satisfy the readPixels request if the intermediate 208 draw is performed. 209 */ 210 kRequireDraw_DrawPreference 211 }; 212 213 /** 214 * Used to negotiate whether and how an intermediate draw should or must be performed before 215 * a readPixels call. If this returns false then GrGpu could not deduce an intermediate draw 216 * that would allow a successful readPixels call. The passed width, height, and rowBytes, 217 * must be non-zero and already reflect clipping to the src bounds. 218 */ 219 bool getReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeight, size_t rowBytes, 220 GrPixelConfig readConfig, DrawPreference*, ReadPixelTempDrawInfo*); 221 222 /** Info struct returned by getWritePixelsInfo about performing an intermediate draw in order 223 to write pixels to a GrSurface for either performance or correctness reasons. */ 224 struct WritePixelTempDrawInfo { 225 /** If the GrGpu is requesting that the caller upload to an intermediate surface and draw 226 that to the dst then this is the descriptor for the intermediate surface. The caller 227 should upload the pixels such that the upper left pixel of the upload rect is at 0,0 in 228 the intermediate surface.*/ 229 GrSurfaceDesc fTempSurfaceDesc; 230 /** Swizzle to apply during the draw. This is used to compensate for either feature or 231 performance limitations in the underlying 3D API. */ 232 GrSwizzle fSwizzle; 233 /** The config that should be specified when uploading the *original* data to the temp 234 surface before the draw. This may be different than the original src data config in 235 order to compensate for swizzling that will occur when drawing. */ 236 GrPixelConfig fWriteConfig; 237 }; 238 239 /** 240 * Used to negotiate whether and how an intermediate surface should be used to write pixels to 241 * a GrSurface. If this returns false then GrGpu could not deduce an intermediate draw 242 * that would allow a successful transfer of the src pixels to the dst. The passed width, 243 * height, and rowBytes, must be non-zero and already reflect clipping to the dst bounds. 244 */ 245 bool getWritePixelsInfo(GrSurface* dstSurface, int width, int height, 246 GrPixelConfig srcConfig, DrawPreference*, WritePixelTempDrawInfo*); 247 248 /** 249 * Reads a rectangle of pixels from a render target. 250 * 251 * @param surface The surface to read from 252 * @param left left edge of the rectangle to read (inclusive) 253 * @param top top edge of the rectangle to read (inclusive) 254 * @param width width of rectangle to read in pixels. 255 * @param height height of rectangle to read in pixels. 256 * @param config the pixel config of the destination buffer 257 * @param buffer memory to read the rectangle into. 258 * @param rowBytes the number of bytes between consecutive rows. Zero 259 * means rows are tightly packed. 260 * @param invertY buffer should be populated bottom-to-top as opposed 261 * to top-to-bottom (skia's usual order) 262 * 263 * @return true if the read succeeded, false if not. The read can fail 264 * because of a unsupported pixel config or because no render 265 * target is currently set. 266 */ 267 bool readPixels(GrSurface* surface, 268 int left, int top, int width, int height, 269 GrPixelConfig config, void* buffer, size_t rowBytes); 270 271 /** 272 * Updates the pixels in a rectangle of a surface. 273 * 274 * @param surface The surface to write to. 275 * @param left left edge of the rectangle to write (inclusive) 276 * @param top top edge of the rectangle to write (inclusive) 277 * @param width width of rectangle to write in pixels. 278 * @param height height of rectangle to write in pixels. 279 * @param config the pixel config of the source buffer 280 * @param texels array of mipmap levels containing texture data 281 */ 282 bool writePixels(GrSurface* surface, 283 int left, int top, int width, int height, 284 GrPixelConfig config, 285 const SkTArray<GrMipLevel>& texels); 286 287 /** 288 * This function is a shim which creates a SkTArray<GrMipLevel> of size 1. 289 * It then calls writePixels with that SkTArray. 290 * 291 * @param buffer memory to read pixels from. 292 * @param rowBytes number of bytes between consecutive rows. Zero 293 * means rows are tightly packed. 294 */ 295 bool writePixels(GrSurface* surface, 296 int left, int top, int width, int height, 297 GrPixelConfig config, const void* buffer, 298 size_t rowBytes); 299 300 /** 301 * Updates the pixels in a rectangle of a surface using a GrTransferBuffer 302 * 303 * @param surface The surface to write to. 304 * @param left left edge of the rectangle to write (inclusive) 305 * @param top top edge of the rectangle to write (inclusive) 306 * @param width width of rectangle to write in pixels. 307 * @param height height of rectangle to write in pixels. 308 * @param config the pixel config of the source buffer 309 * @param buffer GrTransferBuffer to read pixels from 310 * @param offset offset from the start of the buffer 311 * @param rowBytes number of bytes between consecutive rows. Zero 312 * means rows are tightly packed. 313 */ 314 bool transferPixels(GrSurface* surface, 315 int left, int top, int width, int height, 316 GrPixelConfig config, GrTransferBuffer* buffer, 317 size_t offset, size_t rowBytes); 318 319 /** 320 * Clear the passed in render target. Ignores the draw state and clip. 321 */ 322 void clear(const SkIRect& rect, GrColor color, GrRenderTarget* renderTarget); 323 324 325 void clearStencilClip(const SkIRect& rect, bool insideClip, GrRenderTarget* renderTarget); 326 327 /** 328 * Discards the contents render target. nullptr indicates that the current render target should 329 * be discarded. 330 **/ 331 virtual void discard(GrRenderTarget* = nullptr) = 0; 332 333 /** 334 * This is can be called before allocating a texture to be a dst for copySurface. It will 335 * populate the origin, config, and flags fields of the desc such that copySurface can 336 * efficiently succeed. It should only succeed if it can allow copySurface to perform a copy 337 * that would be more effecient than drawing the src to a dst render target. 338 */ 339 virtual bool initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) const = 0; 340 341 // After the client interacts directly with the 3D context state the GrGpu 342 // must resync its internal state and assumptions about 3D context state. 343 // Each time this occurs the GrGpu bumps a timestamp. 344 // state of the 3D context 345 // At 10 resets / frame and 60fps a 64bit timestamp will overflow in about 346 // a billion years. 347 typedef uint64_t ResetTimestamp; 348 349 // This timestamp is always older than the current timestamp 350 static const ResetTimestamp kExpiredTimestamp = 0; 351 // Returns a timestamp based on the number of times the context was reset. 352 // This timestamp can be used to lazily detect when cached 3D context state 353 // is dirty. 354 ResetTimestamp getResetTimestamp() const { return fResetTimestamp; } 355 356 virtual void buildProgramDesc(GrProgramDesc*, 357 const GrPrimitiveProcessor&, 358 const GrPipeline&) const = 0; 359 360 // Called to perform a surface to surface copy. Fallbacks to issuing a draw from the src to dst 361 // take place at the GrDrawTarget level and this function implement faster copy paths. The rect 362 // and point are pre-clipped. The src rect and implied dst rect are guaranteed to be within the 363 // src/dst bounds and non-empty. 364 bool copySurface(GrSurface* dst, 365 GrSurface* src, 366 const SkIRect& srcRect, 367 const SkIPoint& dstPoint); 368 369 struct MultisampleSpecs { 370 // Nonzero ID that uniquely identifies these multisample specs. 371 uint8_t fUniqueID; 372 // The actual number of samples the GPU will run. NOTE: this value can be greater than the 373 // the render target's sample count. 374 int fEffectiveSampleCnt; 375 // If sample locations are supported, contains the subpixel locations at which the GPU will 376 // sample. Pixel center is at (.5, .5) and (0, 0) indicates the top left corner. 377 SkAutoTDeleteArray<const SkPoint> fSampleLocations; 378 }; 379 380 // Finds a render target's multisample specs. The stencil settings are only needed to flush the 381 // draw state prior to querying multisample information; they should not have any effect on the 382 // multisample information itself. 383 const MultisampleSpecs& getMultisampleSpecs(GrRenderTarget*, const GrStencilSettings&); 384 385 struct DrawArgs { 386 DrawArgs(const GrPrimitiveProcessor* primProc, 387 const GrPipeline* pipeline, 388 const GrProgramDesc* desc) 389 : fPrimitiveProcessor(primProc) 390 , fPipeline(pipeline) 391 , fDesc(desc) { 392 SkASSERT(primProc && pipeline && desc); 393 } 394 const GrPrimitiveProcessor* fPrimitiveProcessor; 395 const GrPipeline* fPipeline; 396 const GrProgramDesc* fDesc; 397 }; 398 399 void draw(const DrawArgs&, const GrVertices&); 400 401 // Called by drawtarget when flushing. 402 // Provides a hook for post-flush actions (e.g. PLS reset and Vulkan command buffer submits). 403 virtual void finishDrawTarget() {} 404 405 /////////////////////////////////////////////////////////////////////////// 406 // Debugging and Stats 407 408 class Stats { 409 public: 410#if GR_GPU_STATS 411 Stats() { this->reset(); } 412 413 void reset() { 414 fRenderTargetBinds = 0; 415 fShaderCompilations = 0; 416 fTextureCreates = 0; 417 fTextureUploads = 0; 418 fTransfersToTexture = 0; 419 fStencilAttachmentCreates = 0; 420 fNumDraws = 0; 421 } 422 423 int renderTargetBinds() const { return fRenderTargetBinds; } 424 void incRenderTargetBinds() { fRenderTargetBinds++; } 425 int shaderCompilations() const { return fShaderCompilations; } 426 void incShaderCompilations() { fShaderCompilations++; } 427 int textureCreates() const { return fTextureCreates; } 428 void incTextureCreates() { fTextureCreates++; } 429 int textureUploads() const { return fTextureUploads; } 430 void incTextureUploads() { fTextureUploads++; } 431 int transfersToTexture() const { return fTransfersToTexture; } 432 void incTransfersToTexture() { fTransfersToTexture++; } 433 void incStencilAttachmentCreates() { fStencilAttachmentCreates++; } 434 void incNumDraws() { fNumDraws++; } 435 void dump(SkString*); 436 void dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values); 437 438 private: 439 int fRenderTargetBinds; 440 int fShaderCompilations; 441 int fTextureCreates; 442 int fTextureUploads; 443 int fTransfersToTexture; 444 int fStencilAttachmentCreates; 445 int fNumDraws; 446#else 447 void dump(SkString*) {} 448 void dumpKeyValuePairs(SkTArray<SkString>*, SkTArray<double>*) {} 449 void incRenderTargetBinds() {} 450 void incShaderCompilations() {} 451 void incTextureCreates() {} 452 void incTextureUploads() {} 453 void incTransfersToTexture() {} 454 void incStencilAttachmentCreates() {} 455 void incNumDraws() {} 456#endif 457 }; 458 459 Stats* stats() { return &fStats; } 460 461 /** Creates a texture directly in the backend API without wrapping it in a GrTexture. This is 462 only to be used for testing (particularly for testing the methods that import an externally 463 created texture into Skia. Must be matched with a call to deleteTestingOnlyTexture(). */ 464 virtual GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h, 465 GrPixelConfig config) = 0; 466 /** Check a handle represents an actual texture in the backend API that has not been freed. */ 467 virtual bool isTestingOnlyBackendTexture(GrBackendObject) const = 0; 468 /** If ownership of the backend texture has been transferred pass true for abandonTexture. This 469 will do any necessary cleanup of the handle without freeing the texture in the backend 470 API. */ 471 virtual void deleteTestingOnlyBackendTexture(GrBackendObject, 472 bool abandonTexture = false) = 0; 473 474 // width and height may be larger than rt (if underlying API allows it). 475 // Returns nullptr if compatible sb could not be created, otherwise the caller owns the ref on 476 // the GrStencilAttachment. 477 virtual GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget*, 478 int width, 479 int height) = 0; 480 // clears target's entire stencil buffer to 0 481 virtual void clearStencil(GrRenderTarget* target) = 0; 482 483 // draws an outline rectangle for debugging/visualization purposes. 484 virtual void drawDebugWireRect(GrRenderTarget*, const SkIRect&, GrColor) = 0; 485 486 // Determines whether a texture will need to be rescaled in order to be used with the 487 // GrTextureParams. This variation is called when the caller will create a new texture using the 488 // texture provider from a non-texture src (cpu-backed image, ...). 489 bool makeCopyForTextureParams(int width, int height, const GrTextureParams&, 490 GrTextureProducer::CopyParams*) const; 491 492 // Like the above but this variation should be called when the caller is not creating the 493 // original texture but rather was handed the original texture. It adds additional checks 494 // relevant to original textures that were created external to Skia via 495 // GrTextureProvider::wrap methods. 496 bool makeCopyForTextureParams(GrTexture* texture, const GrTextureParams& params, 497 GrTextureProducer::CopyParams* copyParams) const { 498 if (this->makeCopyForTextureParams(texture->width(), texture->height(), params, 499 copyParams)) { 500 return true; 501 } 502 return this->onMakeCopyForTextureParams(texture, params, copyParams); 503 } 504 505 // This is only to be used in GL-specific tests. 506 virtual const GrGLContext* glContextForTesting() const { return nullptr; } 507 508 // This is only to be used by testing code 509 virtual void resetShaderCacheForTesting() const {} 510 511protected: 512 // Functions used to map clip-respecting stencil tests into normal 513 // stencil funcs supported by GPUs. 514 static GrStencilFunc ConvertStencilFunc(bool stencilInClip, 515 GrStencilFunc func); 516 static void ConvertStencilFuncAndMask(GrStencilFunc func, 517 bool clipInStencil, 518 unsigned int clipBit, 519 unsigned int userBits, 520 unsigned int* ref, 521 unsigned int* mask); 522 523 static void ElevateDrawPreference(GrGpu::DrawPreference* preference, 524 GrGpu::DrawPreference elevation) { 525 GR_STATIC_ASSERT(GrGpu::kCallerPrefersDraw_DrawPreference > GrGpu::kNoDraw_DrawPreference); 526 GR_STATIC_ASSERT(GrGpu::kGpuPrefersDraw_DrawPreference > 527 GrGpu::kCallerPrefersDraw_DrawPreference); 528 GR_STATIC_ASSERT(GrGpu::kRequireDraw_DrawPreference > 529 GrGpu::kGpuPrefersDraw_DrawPreference); 530 *preference = SkTMax(*preference, elevation); 531 } 532 533 void handleDirtyContext() { 534 if (fResetBits) { 535 this->resetContext(); 536 } 537 } 538 539 Stats fStats; 540 SkAutoTDelete<GrPathRendering> fPathRendering; 541 // Subclass must initialize this in its constructor. 542 SkAutoTUnref<const GrCaps> fCaps; 543 544private: 545 // called when the 3D context state is unknown. Subclass should emit any 546 // assumed 3D context state and dirty any state cache. 547 virtual void onResetContext(uint32_t resetBits) = 0; 548 549 // Called before certain draws in order to guarantee coherent results from dst reads. 550 virtual void xferBarrier(GrRenderTarget*, GrXferBarrierType) = 0; 551 552 // overridden by backend-specific derived class to create objects. 553 // Texture size and sample size will have already been validated in base class before 554 // onCreateTexture/CompressedTexture are called. 555 virtual GrTexture* onCreateTexture(const GrSurfaceDesc& desc, 556 GrGpuResource::LifeCycle lifeCycle, 557 const SkTArray<GrMipLevel>& texels) = 0; 558 virtual GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, 559 GrGpuResource::LifeCycle lifeCycle, 560 const SkTArray<GrMipLevel>& texels) = 0; 561 562 virtual GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) = 0; 563 virtual GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&, 564 GrWrapOwnership) = 0; 565 virtual GrRenderTarget* onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&, 566 GrWrapOwnership) = 0; 567 virtual GrVertexBuffer* onCreateVertexBuffer(size_t size, bool dynamic) = 0; 568 virtual GrIndexBuffer* onCreateIndexBuffer(size_t size, bool dynamic) = 0; 569 virtual GrTransferBuffer* onCreateTransferBuffer(size_t size, TransferType type) = 0; 570 571 // overridden by backend-specific derived class to perform the clear. 572 virtual void onClear(GrRenderTarget*, const SkIRect& rect, GrColor color) = 0; 573 574 575 // Overridden by backend specific classes to perform a clear of the stencil clip bits. This is 576 // ONLY used by the the clip target 577 virtual void onClearStencilClip(GrRenderTarget*, const SkIRect& rect, bool insideClip) = 0; 578 579 // overridden by backend-specific derived class to perform the draw call. 580 virtual void onDraw(const DrawArgs&, const GrNonInstancedVertices&) = 0; 581 582 virtual bool onMakeCopyForTextureParams(GrTexture* texture, const GrTextureParams&, 583 GrTextureProducer::CopyParams*) const { return false; } 584 585 virtual bool onGetReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeight, 586 size_t rowBytes, GrPixelConfig readConfig, DrawPreference*, 587 ReadPixelTempDrawInfo*) = 0; 588 virtual bool onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height, 589 GrPixelConfig srcConfig, DrawPreference*, 590 WritePixelTempDrawInfo*) = 0; 591 592 // overridden by backend-specific derived class to perform the surface read 593 virtual bool onReadPixels(GrSurface*, 594 int left, int top, 595 int width, int height, 596 GrPixelConfig, 597 void* buffer, 598 size_t rowBytes) = 0; 599 600 // overridden by backend-specific derived class to perform the surface write 601 virtual bool onWritePixels(GrSurface*, 602 int left, int top, int width, int height, 603 GrPixelConfig config, 604 const SkTArray<GrMipLevel>& texels) = 0; 605 606 // overridden by backend-specific derived class to perform the surface write 607 virtual bool onTransferPixels(GrSurface*, 608 int left, int top, int width, int height, 609 GrPixelConfig config, GrTransferBuffer* buffer, 610 size_t offset, size_t rowBytes) = 0; 611 612 // overridden by backend-specific derived class to perform the resolve 613 virtual void onResolveRenderTarget(GrRenderTarget* target) = 0; 614 615 // overridden by backend specific derived class to perform the copy surface 616 virtual bool onCopySurface(GrSurface* dst, 617 GrSurface* src, 618 const SkIRect& srcRect, 619 const SkIPoint& dstPoint) = 0; 620 621 // overridden by backend specific derived class to perform the multisample queries 622 virtual void onGetMultisampleSpecs(GrRenderTarget*, 623 const GrStencilSettings&, 624 int* effectiveSampleCnt, 625 SkAutoTDeleteArray<SkPoint>* sampleLocations) = 0; 626 627 void resetContext() { 628 this->onResetContext(fResetBits); 629 fResetBits = 0; 630 ++fResetTimestamp; 631 } 632 633 ResetTimestamp fResetTimestamp; 634 uint32_t fResetBits; 635 SkTArray<const MultisampleSpecs*, true> fMultisampleSpecsMap; 636 GrTAllocator<MultisampleSpecs> fMultisampleSpecsAllocator; 637 // The context owns us, not vice-versa, so this ptr is not ref'ed by Gpu. 638 GrContext* fContext; 639 640 friend class GrPathRendering; 641 typedef SkRefCnt INHERITED; 642}; 643 644#endif 645