| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrGpu_DEFINED | 8 #ifndef GrGpu_DEFINED |
| 9 #define GrGpu_DEFINED | 9 #define GrGpu_DEFINED |
| 10 | 10 |
| 11 #include "GrPipelineBuilder.h" | 11 #include "GrPipelineBuilder.h" |
| 12 #include "GrProgramDesc.h" | 12 #include "GrProgramDesc.h" |
| 13 #include "GrStencil.h" | 13 #include "GrStencil.h" |
| 14 #include "GrTextureParamsAdjuster.h" | 14 #include "GrTextureParamsAdjuster.h" |
| 15 #include "GrXferProcessor.h" | 15 #include "GrXferProcessor.h" |
| 16 #include "SkMipMapLevel.h" |
| 16 #include "SkPath.h" | 17 #include "SkPath.h" |
| 18 #include "SkTArray.h" |
| 17 | 19 |
| 18 class GrBatchTracker; | 20 class GrBatchTracker; |
| 19 class GrContext; | 21 class GrContext; |
| 20 class GrGLContext; | 22 class GrGLContext; |
| 21 class GrIndexBuffer; | 23 class GrIndexBuffer; |
| 22 class GrNonInstancedVertices; | 24 class GrNonInstancedVertices; |
| 23 class GrPath; | 25 class GrPath; |
| 24 class GrPathRange; | 26 class GrPathRange; |
| 25 class GrPathRenderer; | 27 class GrPathRenderer; |
| 26 class GrPathRendererChain; | 28 class GrPathRendererChain; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 void markContextDirty(uint32_t state = kAll_GrBackendState) { fResetBits |=
state; } | 76 void markContextDirty(uint32_t state = kAll_GrBackendState) { fResetBits |=
state; } |
| 75 | 77 |
| 76 /** | 78 /** |
| 77 * Creates a texture object. If kRenderTarget_GrSurfaceFlag the texture can | 79 * Creates a texture object. If kRenderTarget_GrSurfaceFlag the texture can |
| 78 * be used as a render target by calling GrTexture::asRenderTarget(). Not al
l | 80 * be used as a render target by calling GrTexture::asRenderTarget(). Not al
l |
| 79 * pixel configs can be used as render targets. Support for configs as textu
res | 81 * pixel configs can be used as render targets. Support for configs as textu
res |
| 80 * or render targets can be checked using GrCaps. | 82 * or render targets can be checked using GrCaps. |
| 81 * | 83 * |
| 82 * @param desc describes the texture to be created. | 84 * @param desc describes the texture to be created. |
| 83 * @param budgeted does this texture count against the resource cache bud
get? | 85 * @param budgeted does this texture count against the resource cache bud
get? |
| 84 * @param srcData texel data to load texture. Begins with full-size | 86 * @param texels array of mipmap levels containing texel data to load. |
| 85 * palette data for paletted textures. For compressed | 87 * Begins with full-size palette data for paletted textur
es. |
| 86 * formats it contains the compressed pixel data. Otherwi
se, | 88 * For compressed formats it contains the compressed pixe
l data. |
| 87 * it contains width*height texels. If nullptr texture da
ta | 89 * Otherwise, it contains width*height texels. If there i
s only one |
| 88 * is uninitialized. | 90 * element and it contains nullptr fTexels, texture data
is |
| 89 * @param rowBytes the number of bytes between consecutive rows. Zero | 91 * uninitialized. |
| 90 * means rows are tightly packed. This field is ignored | 92 * @return The texture object if successful, otherwise nullptr. |
| 91 * for compressed formats. | 93 */ |
| 94 GrTexture* createTexture(const GrSurfaceDesc& desc, bool budgeted, |
| 95 const SkTArray<SkMipMapLevel>& texels); |
| 96 |
| 97 /** |
| 98 * This function is a shim which creates a SkTArray<SkMipMapLevel> of size 1
. |
| 99 * It then calls createTexture with that SkTArray. |
| 92 * | 100 * |
| 93 * @return The texture object if successful, otherwise nullptr. | 101 * @param srcData texel data to load texture. Begins with full-size |
| 102 * palette data for paletted texture. For compressed |
| 103 * formats it contains the compressed pixel data. Otherwise, |
| 104 * it contains width*height texels. If nullptr texture data |
| 105 * is uninitialized. |
| 106 * @param rowBytes the number of bytes between consecutive rows. Zero |
| 107 * means rows are tightly packed. This field is ignored |
| 108 * for compressed pixel formats. |
| 109 * @return The texture object if successful, otherwise, nullptr. |
| 94 */ | 110 */ |
| 95 GrTexture* createTexture(const GrSurfaceDesc& desc, bool budgeted, | 111 GrTexture* createTexture(const GrSurfaceDesc& desc, bool budgeted, |
| 96 const void* srcData, size_t rowBytes); | 112 const void* srcData, size_t rowBytes); |
| 97 | 113 |
| 98 /** | 114 /** |
| 99 * Implements GrContext::wrapBackendTexture | 115 * Implements GrContext::wrapBackendTexture |
| 100 */ | 116 */ |
| 101 GrTexture* wrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership); | 117 GrTexture* wrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership); |
| 102 | 118 |
| 103 /** | 119 /** |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 | 203 |
| 188 /** | 204 /** |
| 189 * Used to negotiate whether and how an intermediate draw should or must be
performed before | 205 * Used to negotiate whether and how an intermediate draw should or must be
performed before |
| 190 * a readPixels call. If this returns false then GrGpu could not deduce an i
ntermediate draw | 206 * a readPixels call. If this returns false then GrGpu could not deduce an i
ntermediate draw |
| 191 * that would allow a successful readPixels call. The passed width, height,
and rowBytes, | 207 * that would allow a successful readPixels call. The passed width, height,
and rowBytes, |
| 192 * must be non-zero and already reflect clipping to the src bounds. | 208 * must be non-zero and already reflect clipping to the src bounds. |
| 193 */ | 209 */ |
| 194 bool getReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeight,
size_t rowBytes, | 210 bool getReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeight,
size_t rowBytes, |
| 195 GrPixelConfig readConfig, DrawPreference*, ReadPixelT
empDrawInfo*); | 211 GrPixelConfig readConfig, DrawPreference*, ReadPixelT
empDrawInfo*); |
| 196 | 212 |
| 197 /** Info struct returned by getWritePixelsInfo about performing an intermedi
ate draw in order | 213 /** Info struct returned by getWritePixelsInfo about performing an intermedi
ate draw in order |
| 198 to write pixels to a GrSurface for either performance or correctness rea
sons. */ | 214 to write pixels to a GrSurface for either performance or correctness rea
sons. */ |
| 199 struct WritePixelTempDrawInfo { | 215 struct WritePixelTempDrawInfo { |
| 200 /** If the GrGpu is requesting that the caller upload to an intermediate
surface and draw | 216 /** If the GrGpu is requesting that the caller upload to an intermediate
surface and draw |
| 201 that to the dst then this is the descriptor for the intermediate sur
face. The caller | 217 that to the dst then this is the descriptor for the intermediate sur
face. The caller |
| 202 should upload the pixels such that the upper left pixel of the uploa
d rect is at 0,0 in | 218 should upload the pixels such that the upper left pixel of the uploa
d rect is at 0,0 in |
| 203 the intermediate surface.*/ | 219 the intermediate surface.*/ |
| 204 GrSurfaceDesc fTempSurfaceDesc; | 220 GrSurfaceDesc fTempSurfaceDesc; |
| 205 /** If set, fTempSurfaceDesc's config will be a R/B swap of the src pixe
l config. The caller | 221 /** If set, fTempSurfaceDesc's config will be a R/B swap of the src pixe
l config. The caller |
| 206 should upload the pixels as is such that R and B will be swapped in
the intermediate | 222 should upload the pixels as is such that R and B will be swapped in
the intermediate |
| 207 surface. When the intermediate is drawn to the dst the shader should
swap R/B again | 223 surface. When the intermediate is drawn to the dst the shader should
swap R/B again |
| 208 such that the correct swizzle results in the dst. This is done to wo
rk around either | 224 such that the correct swizzle results in the dst. This is done to wo
rk around either |
| 209 performance or API restrictions in the backend 3D API implementation
. */ | 225 performance or API restrictions in the backend 3D API implementation
. */ |
| 210 bool fSwapRAndB; | 226 bool fSwapRAndB; |
| 211 }; | 227 }; |
| 212 | 228 |
| 213 /** | 229 /** |
| 214 * Used to negotiate whether and how an intermediate surface should be used
to write pixels to | 230 * Used to negotiate whether and how an intermediate surface should be used
to write pixels to |
| 215 * a GrSurface. If this returns false then GrGpu could not deduce an interme
diate draw | 231 * a GrSurface. If this returns false then GrGpu could not deduce an interme
diate draw |
| 216 * that would allow a successful transfer of the src pixels to the dst. The
passed width, | 232 * that would allow a successful transfer of the src pixels to the dst. The
passed width, |
| 217 * height, and rowBytes, must be non-zero and already reflect clipping to th
e dst bounds. | 233 * height, and rowBytes, must be non-zero and already reflect clipping to th
e dst bounds. |
| 218 */ | 234 */ |
| 219 bool getWritePixelsInfo(GrSurface* dstSurface, int width, int height, size_t
rowBytes, | 235 bool getWritePixelsInfo(GrSurface* dstSurface, int width, int height, |
| 220 GrPixelConfig srcConfig, DrawPreference*, WritePixel
TempDrawInfo*); | 236 GrPixelConfig srcConfig, DrawPreference*, WritePixel
TempDrawInfo*); |
| 221 | 237 |
| 222 /** | 238 /** |
| 223 * Reads a rectangle of pixels from a render target. | 239 * Reads a rectangle of pixels from a render target. |
| 224 * | 240 * |
| 225 * @param surface The surface to read from | 241 * @param surface The surface to read from |
| 226 * @param left left edge of the rectangle to read (inclusive) | 242 * @param left left edge of the rectangle to read (inclusive) |
| 227 * @param top top edge of the rectangle to read (inclusive) | 243 * @param top top edge of the rectangle to read (inclusive) |
| 228 * @param width width of rectangle to read in pixels. | 244 * @param width width of rectangle to read in pixels. |
| 229 * @param height height of rectangle to read in pixels. | 245 * @param height height of rectangle to read in pixels. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 244 | 260 |
| 245 /** | 261 /** |
| 246 * Updates the pixels in a rectangle of a surface. | 262 * Updates the pixels in a rectangle of a surface. |
| 247 * | 263 * |
| 248 * @param surface The surface to write to. | 264 * @param surface The surface to write to. |
| 249 * @param left left edge of the rectangle to write (inclusive) | 265 * @param left left edge of the rectangle to write (inclusive) |
| 250 * @param top top edge of the rectangle to write (inclusive) | 266 * @param top top edge of the rectangle to write (inclusive) |
| 251 * @param width width of rectangle to write in pixels. | 267 * @param width width of rectangle to write in pixels. |
| 252 * @param height height of rectangle to write in pixels. | 268 * @param height height of rectangle to write in pixels. |
| 253 * @param config the pixel config of the source buffer | 269 * @param config the pixel config of the source buffer |
| 254 * @param buffer memory to read pixels from | 270 * @param texels array of mipmap levels containing texture data |
| 255 * @param rowBytes number of bytes between consecutive rows. Zero | |
| 256 * means rows are tightly packed. | |
| 257 */ | 271 */ |
| 258 bool writePixels(GrSurface* surface, | 272 bool writePixels(GrSurface* surface, |
| 259 int left, int top, int width, int height, | 273 int left, int top, int width, int height, |
| 274 GrPixelConfig config, |
| 275 const SkTArray<SkMipMapLevel>& texels); |
| 276 |
| 277 /** |
| 278 * This function is a shim which creates a SkTArray<SkMipMapLevel> of size 1
. |
| 279 * It then calls writePixels with that SkTArray. |
| 280 * |
| 281 * @param buffer memory to read pixels from. |
| 282 * @param rowBytes number of bytes between consecutive rows. Zero |
| 283 * means rows are tightly packed. |
| 284 */ |
| 285 bool writePixels(GrSurface* surface, |
| 286 int left, int top, int width, int height, |
| 260 GrPixelConfig config, const void* buffer, | 287 GrPixelConfig config, const void* buffer, |
| 261 size_t rowBytes); | 288 size_t rowBytes); |
| 262 | 289 |
| 263 /** | 290 /** |
| 264 * Updates the pixels in a rectangle of a surface using a GrTransferBuffer | 291 * Updates the pixels in a rectangle of a surface using a GrTransferBuffer |
| 265 * | 292 * |
| 266 * @param surface The surface to write to. | 293 * @param surface The surface to write to. |
| 267 * @param left left edge of the rectangle to write (inclusive) | 294 * @param left left edge of the rectangle to write (inclusive) |
| 268 * @param top top edge of the rectangle to write (inclusive) | 295 * @param top top edge of the rectangle to write (inclusive) |
| 269 * @param width width of rectangle to write in pixels. | 296 * @param width width of rectangle to write in pixels. |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 virtual void onResetContext(uint32_t resetBits) = 0; | 504 virtual void onResetContext(uint32_t resetBits) = 0; |
| 478 | 505 |
| 479 // Called before certain draws in order to guarantee coherent results from d
st reads. | 506 // Called before certain draws in order to guarantee coherent results from d
st reads. |
| 480 virtual void xferBarrier(GrRenderTarget*, GrXferBarrierType) = 0; | 507 virtual void xferBarrier(GrRenderTarget*, GrXferBarrierType) = 0; |
| 481 | 508 |
| 482 // overridden by backend-specific derived class to create objects. | 509 // overridden by backend-specific derived class to create objects. |
| 483 // Texture size and sample size will have already been validated in base cla
ss before | 510 // Texture size and sample size will have already been validated in base cla
ss before |
| 484 // onCreateTexture/CompressedTexture are called. | 511 // onCreateTexture/CompressedTexture are called. |
| 485 virtual GrTexture* onCreateTexture(const GrSurfaceDesc& desc, | 512 virtual GrTexture* onCreateTexture(const GrSurfaceDesc& desc, |
| 486 GrGpuResource::LifeCycle lifeCycle, | 513 GrGpuResource::LifeCycle lifeCycle, |
| 487 const void* srcData, size_t rowBytes) = 0
; | 514 const SkTArray<SkMipMapLevel>& texels) =
0; |
| 488 virtual GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, | 515 virtual GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, |
| 489 GrGpuResource::LifeCycle lifeCy
cle, | 516 GrGpuResource::LifeCycle lifeCy
cle, |
| 490 const void* srcData) = 0; | 517 const SkTArray<SkMipMapLevel>&
texels) = 0; |
| 518 |
| 491 virtual GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapO
wnership) = 0; | 519 virtual GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapO
wnership) = 0; |
| 492 virtual GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTarge
tDesc&, | 520 virtual GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTarge
tDesc&, |
| 493 GrWrapOwnership) = 0; | 521 GrWrapOwnership) = 0; |
| 494 virtual GrVertexBuffer* onCreateVertexBuffer(size_t size, bool dynamic) = 0; | 522 virtual GrVertexBuffer* onCreateVertexBuffer(size_t size, bool dynamic) = 0; |
| 495 virtual GrIndexBuffer* onCreateIndexBuffer(size_t size, bool dynamic) = 0; | 523 virtual GrIndexBuffer* onCreateIndexBuffer(size_t size, bool dynamic) = 0; |
| 496 virtual GrTransferBuffer* onCreateTransferBuffer(size_t size, TransferType t
ype) = 0; | 524 virtual GrTransferBuffer* onCreateTransferBuffer(size_t size, TransferType t
ype) = 0; |
| 497 | 525 |
| 498 // overridden by backend-specific derived class to perform the clear. | 526 // overridden by backend-specific derived class to perform the clear. |
| 499 virtual void onClear(GrRenderTarget*, const SkIRect& rect, GrColor color) =
0; | 527 virtual void onClear(GrRenderTarget*, const SkIRect& rect, GrColor color) =
0; |
| 500 | 528 |
| 501 | 529 |
| 502 // Overridden by backend specific classes to perform a clear of the stencil
clip bits. This is | 530 // Overridden by backend specific classes to perform a clear of the stencil
clip bits. This is |
| 503 // ONLY used by the the clip target | 531 // ONLY used by the the clip target |
| 504 virtual void onClearStencilClip(GrRenderTarget*, const SkIRect& rect, bool i
nsideClip) = 0; | 532 virtual void onClearStencilClip(GrRenderTarget*, const SkIRect& rect, bool i
nsideClip) = 0; |
| 505 | 533 |
| 506 // overridden by backend-specific derived class to perform the draw call. | 534 // overridden by backend-specific derived class to perform the draw call. |
| 507 virtual void onDraw(const DrawArgs&, const GrNonInstancedVertices&) = 0; | 535 virtual void onDraw(const DrawArgs&, const GrNonInstancedVertices&) = 0; |
| 508 | 536 |
| 509 virtual bool onGetReadPixelsInfo(GrSurface* srcSurface, int readWidth, int r
eadHeight, | 537 virtual bool onGetReadPixelsInfo(GrSurface* srcSurface, int readWidth, int r
eadHeight, |
| 510 size_t rowBytes, GrPixelConfig readConfig,
DrawPreference*, | 538 size_t rowBytes, GrPixelConfig readConfig,
DrawPreference*, |
| 511 ReadPixelTempDrawInfo*) = 0; | 539 ReadPixelTempDrawInfo*) = 0; |
| 512 virtual bool onGetWritePixelsInfo(GrSurface* dstSurface, int width, int heig
ht, size_t rowBytes, | 540 virtual bool onGetWritePixelsInfo(GrSurface* dstSurface, int width, int heig
ht, |
| 513 GrPixelConfig srcConfig, DrawPreference*, | 541 GrPixelConfig srcConfig, DrawPreference*, |
| 514 WritePixelTempDrawInfo*) = 0; | 542 WritePixelTempDrawInfo*) = 0; |
| 515 | 543 |
| 516 // overridden by backend-specific derived class to perform the surface read | 544 // overridden by backend-specific derived class to perform the surface read |
| 517 virtual bool onReadPixels(GrSurface*, | 545 virtual bool onReadPixels(GrSurface*, |
| 518 int left, int top, | 546 int left, int top, |
| 519 int width, int height, | 547 int width, int height, |
| 520 GrPixelConfig, | 548 GrPixelConfig, |
| 521 void* buffer, | 549 void* buffer, |
| 522 size_t rowBytes) = 0; | 550 size_t rowBytes) = 0; |
| 523 | 551 |
| 524 // overridden by backend-specific derived class to perform the surface write | 552 // overridden by backend-specific derived class to perform the surface write |
| 525 virtual bool onWritePixels(GrSurface*, | 553 virtual bool onWritePixels(GrSurface*, |
| 526 int left, int top, int width, int height, | 554 int left, int top, int width, int height, |
| 527 GrPixelConfig config, const void* buffer, | 555 GrPixelConfig config, |
| 528 size_t rowBytes) = 0; | 556 const SkTArray<SkMipMapLevel>& texels) = 0; |
| 529 | 557 |
| 530 // overridden by backend-specific derived class to perform the surface write | 558 // overridden by backend-specific derived class to perform the surface write |
| 531 virtual bool onTransferPixels(GrSurface*, | 559 virtual bool onTransferPixels(GrSurface*, |
| 532 int left, int top, int width, int height, | 560 int left, int top, int width, int height, |
| 533 GrPixelConfig config, GrTransferBuffer* buffer
, | 561 GrPixelConfig config, GrTransferBuffer* buffer
, |
| 534 size_t offset, size_t rowBytes) = 0; | 562 size_t offset, size_t rowBytes) = 0; |
| 535 | 563 |
| 536 // overridden by backend-specific derived class to perform the resolve | 564 // overridden by backend-specific derived class to perform the resolve |
| 537 virtual void onResolveRenderTarget(GrRenderTarget* target) = 0; | 565 virtual void onResolveRenderTarget(GrRenderTarget* target) = 0; |
| 538 | 566 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 551 ResetTimestamp fResetTi
mestamp; | 579 ResetTimestamp fResetTi
mestamp; |
| 552 uint32_t fResetBi
ts; | 580 uint32_t fResetBi
ts; |
| 553 // The context owns us, not vice-versa, so this ptr is not ref'ed by Gpu. | 581 // The context owns us, not vice-versa, so this ptr is not ref'ed by Gpu. |
| 554 GrContext* fContext
; | 582 GrContext* fContext
; |
| 555 | 583 |
| 556 friend class GrPathRendering; | 584 friend class GrPathRendering; |
| 557 typedef SkRefCnt INHERITED; | 585 typedef SkRefCnt INHERITED; |
| 558 }; | 586 }; |
| 559 | 587 |
| 560 #endif | 588 #endif |
| OLD | NEW |