1f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com/* 2f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com * Copyright 2012 Google Inc. 3f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com * 4f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com * Use of this source code is governed by a BSD-style license that can be 5f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com * found in the LICENSE file. 6f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com */ 7f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com 8f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com#ifndef GrAARectRenderer_DEFINED 9f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com#define GrAARectRenderer_DEFINED 10f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com 11114eb9e69942c11635380284deb9cc91eaab3632robertphillips@google.com#include "SkMatrix.h" 12fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org#include "SkRect.h" 13a4de8c257ea0be8ff7081f645249b6afe5c48e7ecommit-bot@chromium.org#include "SkRefCnt.h" 146006d0f8c4f19d19a12de20826f731f52ac822a7commit-bot@chromium.org#include "SkStrokeRec.h" 15f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com 16f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.comclass GrGpu; 17f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.comclass GrDrawTarget; 18f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.comclass GrIndexBuffer; 19f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com 20f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com/* 21f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com * This class wraps helper functions that draw AA rects (filled & stroked) 22f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com */ 23a4de8c257ea0be8ff7081f645249b6afe5c48e7ecommit-bot@chromium.orgclass GrAARectRenderer : public SkRefCnt { 24f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.compublic: 254d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com SK_DECLARE_INST_COUNT(GrAARectRenderer) 26f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com 27fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com GrAARectRenderer() 28f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com : fAAFillRectIndexBuffer(NULL) 296006d0f8c4f19d19a12de20826f731f52ac822a7commit-bot@chromium.org , fAAMiterStrokeRectIndexBuffer(NULL) 306006d0f8c4f19d19a12de20826f731f52ac822a7commit-bot@chromium.org , fAABevelStrokeRectIndexBuffer(NULL) { 31f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com } 32f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com 33f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com void reset(); 34f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com 35f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com ~GrAARectRenderer() { 36f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com this->reset(); 37f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com } 38f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com 39f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com // TODO: potentialy fuse the fill & stroke methods and differentiate 406006d0f8c4f19d19a12de20826f731f52ac822a7commit-bot@chromium.org // between them by passing in stroke (==NULL means fill). 41f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com 42f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com void fillAARect(GrGpu* gpu, 43f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com GrDrawTarget* target, 44fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org const SkRect& rect, 45b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com const SkMatrix& combinedMatrix, 46fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org const SkRect& devRect, 47b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com bool useVertexCoverage) { 48b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com#ifdef SHADER_AA_FILL_RECT 49b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com if (combinedMatrix.rectStaysRect()) { 50b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com this->shaderFillAlignedAARect(gpu, target, 51114eb9e69942c11635380284deb9cc91eaab3632robertphillips@google.com rect, combinedMatrix); 52b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com } else { 53b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com this->shaderFillAARect(gpu, target, 54114eb9e69942c11635380284deb9cc91eaab3632robertphillips@google.com rect, combinedMatrix); 55b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com } 56b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com#else 57b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com this->geometryFillAARect(gpu, target, 584b140b5fbedcb75d0b9587fa9d232ce54d9c7eb5robertphillips@google.com rect, combinedMatrix, 59afd1cba5237eba5394ee011106eede9f6c8074c8robertphillips@google.com devRect, useVertexCoverage); 60b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com#endif 61b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com } 62df3695e5c72b3b4401e71ff259827d87bfe8a06frobertphillips@google.com 63f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com void strokeAARect(GrGpu* gpu, 64f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com GrDrawTarget* target, 65fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org const SkRect& rect, 6618136d1cf284bea42ae574e491fa8032aef4e7ddrobertphillips@google.com const SkMatrix& combinedMatrix, 67fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org const SkRect& devRect, 68d58a0ba9cff9fcefe5047e88ccb4a6e76c591c40egdaniel const SkStrokeRec& stroke, 69f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com bool useVertexCoverage); 70f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com 7183d1a68141830cbfa0d5fca6f9c9bccf9c978ad2robertphillips@google.com // First rect is outer; second rect is inner 7283d1a68141830cbfa0d5fca6f9c9bccf9c978ad2robertphillips@google.com void fillAANestedRects(GrGpu* gpu, 7383d1a68141830cbfa0d5fca6f9c9bccf9c978ad2robertphillips@google.com GrDrawTarget* target, 7483d1a68141830cbfa0d5fca6f9c9bccf9c978ad2robertphillips@google.com const SkRect rects[2], 7583d1a68141830cbfa0d5fca6f9c9bccf9c978ad2robertphillips@google.com const SkMatrix& combinedMatrix, 7683d1a68141830cbfa0d5fca6f9c9bccf9c978ad2robertphillips@google.com bool useVertexCoverage); 7783d1a68141830cbfa0d5fca6f9c9bccf9c978ad2robertphillips@google.com 78f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.comprivate: 79f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com GrIndexBuffer* fAAFillRectIndexBuffer; 806006d0f8c4f19d19a12de20826f731f52ac822a7commit-bot@chromium.org GrIndexBuffer* fAAMiterStrokeRectIndexBuffer; 816006d0f8c4f19d19a12de20826f731f52ac822a7commit-bot@chromium.org GrIndexBuffer* fAABevelStrokeRectIndexBuffer; 82f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com 83f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com GrIndexBuffer* aaFillRectIndexBuffer(GrGpu* gpu); 84f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com 856006d0f8c4f19d19a12de20826f731f52ac822a7commit-bot@chromium.org static int aaStrokeRectIndexCount(bool miterStroke); 866006d0f8c4f19d19a12de20826f731f52ac822a7commit-bot@chromium.org GrIndexBuffer* aaStrokeRectIndexBuffer(GrGpu* gpu, bool miterStroke); 874d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com 88b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com // TODO: Remove the useVertexCoverage boolean. Just use it all the time 89b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com // since we now have a coverage vertex attribute 90b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com void geometryFillAARect(GrGpu* gpu, 91b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com GrDrawTarget* target, 92fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org const SkRect& rect, 934b140b5fbedcb75d0b9587fa9d232ce54d9c7eb5robertphillips@google.com const SkMatrix& combinedMatrix, 94fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org const SkRect& devRect, 95b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com bool useVertexCoverage); 96b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com 97b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com void shaderFillAARect(GrGpu* gpu, 98b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com GrDrawTarget* target, 99fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org const SkRect& rect, 100114eb9e69942c11635380284deb9cc91eaab3632robertphillips@google.com const SkMatrix& combinedMatrix); 101b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com 102b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com void shaderFillAlignedAARect(GrGpu* gpu, 103b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com GrDrawTarget* target, 104fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org const SkRect& rect, 105114eb9e69942c11635380284deb9cc91eaab3632robertphillips@google.com const SkMatrix& combinedMatrix); 106b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com 10783d1a68141830cbfa0d5fca6f9c9bccf9c978ad2robertphillips@google.com void geometryStrokeAARect(GrGpu* gpu, 10883d1a68141830cbfa0d5fca6f9c9bccf9c978ad2robertphillips@google.com GrDrawTarget* target, 10983d1a68141830cbfa0d5fca6f9c9bccf9c978ad2robertphillips@google.com const SkRect& devOutside, 1106006d0f8c4f19d19a12de20826f731f52ac822a7commit-bot@chromium.org const SkRect& devOutsideAssist, 11183d1a68141830cbfa0d5fca6f9c9bccf9c978ad2robertphillips@google.com const SkRect& devInside, 1126006d0f8c4f19d19a12de20826f731f52ac822a7commit-bot@chromium.org bool useVertexCoverage, 1136006d0f8c4f19d19a12de20826f731f52ac822a7commit-bot@chromium.org bool miterStroke); 11483d1a68141830cbfa0d5fca6f9c9bccf9c978ad2robertphillips@google.com 115a4de8c257ea0be8ff7081f645249b6afe5c48e7ecommit-bot@chromium.org typedef SkRefCnt INHERITED; 116f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com}; 117f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com 118f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com#endif // GrAARectRenderer_DEFINED 119